FastAPI companion service to the GSAP broker for AI agent
identity delegation in governed shell sessions.
Implements GCAP-SPEC-LLM-PRINCIPAL-BROKER-0001:
POST /delegate — request delegation (human → AI agent)
POST /delegate/{id}/revoke — revoke delegation
GET /delegate/{id} — delegation status
GET /agents — list active delegations
GET /health — health check
Delegation lifecycle:
REQUESTED → ACTIVE → EXPIRED | REVOKED
Cascading revocation on delegator AC revocation
Background cleanup of expired delegations (30s interval)
Keycloak integration:
Registers ephemeral agent clients per delegation
Deletes clients on revocation/expiry
Dev mode: stubs when no client_secret configured
GSAP broker integration:
Requests delegated ACs via on_behalf_of pattern
Scope narrowing: agent ceiling ≤ delegator ceiling
Dev mode: stubs when no bearer_token configured
Chronicle integration:
DELEGATION_CREATED (0x3001)
DELEGATION_REVOKED (0x3003)
DELEGATION_EXPIRED (0x3004)
All 7 smoke tests pass (health, create, list, query, revoke, verify, empty).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""Configuration — matches fastapi-gsap settings pattern."""
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
from typing import Optional
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", case_sensitive=False, extra="ignore")
|
|
|
|
# Service
|
|
llm_broker_port: int = 8092
|
|
broker_did: str = "did:web:guildhouse.dev/service/llm-broker"
|
|
|
|
# GSAP broker
|
|
gsap_broker_url: str = "http://localhost:8000"
|
|
gsap_bearer_token: str = ""
|
|
|
|
# Keycloak Admin
|
|
keycloak_url: str = "http://localhost:8080"
|
|
keycloak_realm: str = "substrate"
|
|
keycloak_admin_client_id: str = "llm-broker-admin"
|
|
keycloak_admin_client_secret: str = ""
|
|
|
|
# Chronicle
|
|
chronicle_webhook_url: Optional[str] = None
|
|
|
|
# Delegation defaults
|
|
default_delegation_ttl_minutes: int = 60
|
|
default_max_commands: int = 500
|
|
max_delegation_depth: int = 1
|
|
|
|
# CORS
|
|
cors_origins: list[str] = ["http://localhost:3000", "http://localhost:8000"]
|
|
|
|
# Database
|
|
database_url: str = "sqlite+aiosqlite:///./llm_broker.db"
|
|
|
|
|
|
settings = Settings()
|