ADK (Agent Development Kit)
Agent execution engine built on FastAPI and Google ADK: what it does, how it is built, and where to find the full API reference
Updated 2026-11-03
Verified 2026-11-03
The ADK service (cosmos-adk-v3) is the agent execution engine of the Cosmos platform. Built on FastAPI and Google ADK 2.13, it runs agents, manages conversation sessions, generates skills, and streams responses. It integrates with MCP for tools and supports multi-agent hierarchies, guardrails, client-side tool execution, test sessions, and real-time streaming.
Why It Matters
Every agent turn in Cosmos, whether it starts in the Frontend, Chat, Voice, Cosmos Code, or a consumer app such as JumpStart, is executed by ADK. ADK is the one place that assembles an agent's tools, skills, guardrails, and prompt into a runnable Google ADK agent, and the one place that enforces per-turn identity, project scope, PII masking, content filtering, cost limits, and rate limits before an LLM call happens.
Architecture
| Component | Role |
|---|---|
| REST API server | Synchronous turns (POST /api/v1/adk/converse/), sessions, skills, evaluations, and direct LLM calls |
| WebSocket server | Streaming through V1 (/converse_stream/, used by Chat) and V2 (/converse/v2, recommended) |
| Event consumer | Consumes Configurator events for agent, tool, and app updates |
| Celery worker | Async agent requests and webhook callbacks with retry logic |
| Background jobs | Periodic maintenance and cleanup tasks |
V1 and V2 share core modules: agent_builder (recursive multi-agent tree construction), app_factory (App and Runner factory with plugins), client_proxy_toolset (client-side tool execution), skill_manager (Configurator skills to ADK SkillToolset), image_utils (DMS image resolution), and pii_utils (streaming PII demasking).
Agent turn flow: ADK authenticates the caller, checks that the requested user_id matches the token subject, authorizes adk.agent.execute against the organization (or against the project when a project ID is supplied), loads the agent, app, or prompt-only configuration, resolves MCP tools, attaches client-defined tools and skills, builds the Google ADK runner, and streams protocol events back to the caller. Fatal setup or runtime errors are sent as error events with fatal: true before the WebSocket closes.
Plugin pipeline
app_factory.build_app() registers plugins in this order (some only when their feature is configured):
| Plugin | Purpose |
|---|---|
DatetimePlugin | Injects the current UTC time |
HeadroomSessionPlugin | Tags requests for the optional Headroom compression proxy |
PIIMaskingPlugin | Masks PII in user messages before persistence through the remote cosmos-pii-redactor service; the mapping is kept in session state and Redis |
ToolAwareContextFilterPlugin | Trims history by whole tool-call and tool-response invocations |
RateLimitPlugin | Enforces per-organization, per-provider TPM limits with a Redis sliding window; waits up to 120 seconds before returning RATE_LIMITED |
SessionCostGuardPlugin | Enforces session cost limits |
ArtifactReplayProjectionPlugin | Replays current DMS artifact evidence without leaking stale tool output |
ContextBudgetGuardPlugin | Blocks requests that would exceed the context budget |
DanglingToolCallPlugin, ToolHistorySanitizerPlugin, ProviderHistoryValidatorPlugin | Keep tool-call history valid for each provider |
LlmRequestResponseCapturePlugin, ModelLatencyPlugin | Capture LLM input, output, and timing for observability |
Key Capabilities
- V2 streaming protocol: per-request model overrides, client-defined tools with callback execution, tool approvals, mid-conversation tool updates, multi-agent hierarchies, test sessions, negotiated voice turns (
cosmos.voice.v2, required forchannel: voice), and PII streaming demasking. See the Converse API. - Guardrails: app-level PII configuration and content filtering, with agent-level content filter overrides. Prompt-only V2 sessions can opt in to the organization default guardrails with
use_org_default_guardrails. - Client-side tool execution:
ClientProxyToolsetturns client JSON Schema tool definitions into ADK function tools, sendstool_callevents, and waits fortool_result(120 seconds by default; V2 clients can setclient_tool_timeout_secondsup to 3600). Pending calls are cancelled on disconnect. - Tool approvals: tools configured with
requires_approvalin Configurator pause the turn with anapproval_requiredevent. The client answers withapproval_decision; no answer within 300 seconds denies the call. - Skills: Google ADK
SkillToolsetwith progressive disclosure (list_skills,load_skill,load_skill_resource,run_skill_script). Skills can be attached per request in the V2startevent, andmetadata.cosmos_knowledge_base_idsloads the referenced knowledge base collections. - Skill generation:
POST /api/v1/adk/skills/generateproposes reusable skills from a conversation, an agent prompt (including sub-agents), or a free-text description. - Context window and compaction: ADK alone owns these settings; clients do not send them. The window is the root agent's
context_window_tokens(minimum 8192) or the model's standard window fromprovider_capabilities.yaml, capped at the model maximum, with 128K for unknown models. The input window reserves the smaller of the maximum output tokens and half the window. Compaction starts at 80 percent of the input window unless the agent setstoken_threshold, and the budget guard blocks at 85 percent. Compaction interval, overlap, invocations to keep, and event retention (default 30) come from the agent configuration. Clients can also request compaction withPOST /sessions/{session_id}/compact. - Prompt caching (Anthropic-family models): per-agent
prompt_caching(system prompt breakpoint) andprompt_caching_history(history-tail breakpoint, 1 hour TTL). Anullvalue means on. ThePROMPT_CACHING_ENABLEDmaster switch, plusPROMPT_CACHING_SYSTEM_ENABLEDandPROMPT_CACHING_HISTORY_ENABLED, control the feature per environment. - Dynamic thinking: when an agent sets
dynamic_thinking_enabledandCLASSIFIER_ROUTING_ENABLEDis on, ADK classifies each query throughcosmos-classifier-v3(/v1/classify, 1.5 second timeout) and picks a thinking mode and reasoning effort within the model's limits. Classifier failures keep the saved configuration. - Headroom compression: an optional compression proxy for Anthropic and Azure Claude providers. It applies only when the agent sets
headroom_compression_enabled: trueandHEADROOM_ROUTING_ENABLEDis on. It is independent of prompt caching. - Project scope: callers can send
X-Project-Id(orproject_idin a V1 or V2startbody). ADK authorizes the project, stores it as the server-owned session scope, and forwards it to MCP asX-Project-Idso tools such asknowledge_baseauthorize each target against the project. - Test sessions: AI Testing Workspace sessions start with a
test_sessionselection, store an immutable snapshot, expose redacted traces, and support evaluation (POST /sessions/{session_id}/evaluate, enabled byADK_TEST_EVALUATE_ENABLED=true). See the Sessions API. - Evaluation and analyzer runs:
eval-agent/*,reviews/*,evals/experiments/*, andevals/agents/{id}/auto-setup/routes run analyzers, experiments, and review workflows.
API Overview
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/adk/converse/ | Synchronous agent or app turn |
| POST | /api/v1/adk/add-event/ | Inject an event into the caller's session |
| POST | /api/v1/adk/call_llm/ | Direct LLM call through the organization's BYOT credentials |
| WS | /api/v1/adk/converse_stream/ | V1 streaming (Chat) |
| WS | /api/v1/adk/converse/v2 | V2 streaming with client tools, approvals, and voice |
| POST | /api/v1/adk/skills/generate | Generate skill proposals |
| POST, GET | /api/v1/adk/async/requests/ | Submit and list async requests |
| GET | /api/v1/adk/async/requests/{request_id}/status/ | Async request status and result |
| GET | /api/v1/adk/sessions/ | List the caller's sessions |
| GET | /api/v1/adk/sessions/{session_id}/events/ | Session events |
| POST | /api/v1/adk/sessions/{session_id}/compact | Compact a session on demand |
| PATCH | /api/v1/adk/sessions/{session_id}/metadata | Merge session metadata |
| GET, POST, PUT | /api/v1/adk/sessions/{session_id}/... | Test-session snapshot, trace access, visible messages, evaluations, suggestions, and feedback |
| GET | /health/ | Health check |
→ Full API reference: ADK API
Configuration
The server.py entrypoint dispatches on the mode environment variable: webserver (default, FastAPI and Uvicorn), celery, background_job, or consumer. In Kubernetes every mode runs under opentelemetry-instrument, which exports traces to Azure Monitor (Application Insights) through APPLICATIONINSIGHTS_CONNECTION_STRING. The image installs dependencies into /app/.venv.
| Variable | Purpose |
|---|---|
COSMOS_SERVICE_CLIENT_ID, COSMOS_SERVICE_CLIENT_SECRET | Service OAuth client credentials for the User Service token endpoint |
MCP_SERVICE_URL, CONFIGURATOR_SERVICE_URL, OBSERVER_SERVICE_URL | Downstream service URLs |
PII_REDACTOR_SERVICE_URL | Remote PII masking service |
SESSION_COST_ENFORCEMENT_ENABLED, PERIOD_COST_ENFORCEMENT_ENABLED | Session and weekly or monthly cost limit enforcement |
PROMPT_CACHING_ENABLED, PROMPT_CACHING_SYSTEM_ENABLED, PROMPT_CACHING_HISTORY_ENABLED | Prompt caching switches |
CLASSIFIER_ROUTING_ENABLED, CLASSIFIER_BASE_URL | Dynamic thinking classifier |
HEADROOM_ROUTING_ENABLED, HEADROOM_BASE_URL, HEADROOM_PROXY_TOKEN, HEADROOM_DIAGNOSTICS_ENABLED | Headroom compression proxy |
ADK_TEST_EVALUATE_ENABLED | Enables test-session evaluation routes |
TRANSCRIPT_BACKEND | Media transcription backend |
ADK_SESSION_SCHEMA | Database schema for session tables |
COSMOS_LOG_SHOW_PAYLOADS | Shows truncated payloads in logs (off in UAT and production) |
Key dependencies: google-adk 2.13.0 (installed from a compatibility wheel with widened OpenTelemetry bounds), fastapi 0.141.1, litellm 1.103.8, mcp 2.x, SQLAlchemy 2.0.43, celery 5.6.0, PyJWT 2.15.0, faster-whisper 1.2.1, and azure-monitor-opentelemetry 1.8.11.
Supported LLM providers: google_ai, vertex_ai, azure_openai, azure_claude, aws_claude, azure_ai (Azure AI Foundry serverless models), smallest_ai, and inhouse. Model credentials come from the organization's BYOT configuration in Configurator.
Data Model
Sessions and events are stored in PostgreSQL through the Google ADK database session service. Sessions are keyed by (app_name, user_id, id), where app_name is the app code (agent_<uuid> or app_<uuid>, with hyphens replaced by underscores). Events belong to a session and carry content, usage metadata, and turn markers. Async requests and analyzer runs have their own tables. See the Sessions API for the exposed shapes.
Integration Points
| Service | Integration |
|---|---|
| MCP | Tool access via MCPToolset over streamable HTTP; forwards X-Org-Id, the delegated user, and X-Project-Id |
| Configurator | Agent, tool, app, skill, and BYOT configuration; cost limits |
| Observer | Cost data and analyzer results |
| PII Redactor | Remote PII masking |
| Kafka | Consumes Configurator events for agent, tool, and app updates |
| Redis | DB 0 (ADK cache, rate limit windows, PII counters), DB 15 (Kafka event cache) |
| PostgreSQL | Session, event, async request, and analyzer storage |
Troubleshooting
- "No agent with agent id" error: verify the agent version exists in Configurator (
GET /api/v1/agents/<id>/versions/) and that ADK can reachCONFIGURATOR_SERVICE_URL. - MCP tools not loading: check the service OAuth variables (
COSMOS_SERVICE_CLIENT_ID,COSMOS_SERVICE_CLIENT_SECRET) and MCP health (curl http://localhost:8102/health/). Re-provision with./manage.sh dev setup-tokensif needed. - V1 WebSocket closes with 4401 or 4403: the handshake needs a valid bearer token (4401), and the token must be authorized for the organization in the
startevent (4403). - Voice start rejected with
INVALID_REQUEST: V2 voice sessions must sendvoice_protocol: "cosmos.voice.v2". - Kafka consumer not processing events: check
docker logs cosmos-dev-adk-consumer, confirm Kafka is running, and restart with./manage.sh dev restart adk-consumer. - PII masking not working: confirm PII is enabled in the app's guardrails and that
PII_REDACTOR_SERVICE_URLis reachable. - Rate limiting errors: check
provider_rate_limitsin organization settings and the Redis sliding window (redis-cli KEYS "cosmos:rate_limit:tpm:*").
Changelog
See ADK Changelog for verified documentation and service-surface changes.