Agent Framework & A2A Overview¶
litestar-mcp includes a provider-neutral multi-agent runtime, class-based prompt and skill controllers, bidirectional MCP/A2A protocol bridges, and an official Agent-to-Agent (a2a-sdk 1.0) transport plugin that run natively inside your Litestar application.
Architectural Layers¶
The agent and interoperability stack is organized into five composable layers:
flowchart LR
Controllers["Chat & Skill Controllers"]
Hierarchy["Agent & AgentGroup"]
Runtime["AgentRuntime & TurnBudget"]
Model["ModelClient (GoogleGenAIClient)"]
Bridges["Bridges & LitestarA2A"]
Controllers --> Runtime
Hierarchy --> Runtime
Runtime --> Model
Bridges <--> Runtime
- Controllers (
PromptController,SkillController,AgentChatController,QueuedAgentChatController): Class-based boundaries mirroring Litestar'sControllerarchitecture to package domain prompts (@prompt), tools (@tool), instructions, authorization guards, universal dependency injection (Provide,FromDishka[T],Inject(),Depends(fn)), and HTTP/SSE turn endpoints. - Agent Hierarchy (
Agent,AgentGroup,AgentMessage): Provider-neutral agent specifications and coordinator-specialist trees featuring automatic,Literal-typedtransfer_to_agenthandoff tool synthesis and non-mutating specialist isolation. - Runtime & Model Layer (
AgentRuntime,TurnBudget,ModelClient,GoogleGenAIClient,MockModelClient,SessionStore): Guarded multi-step execution loops enforcingTurnBudgetlimits (max_turns,max_tool_calls,timeout_seconds), streamingModelDeltachunks fromGoogleGenAIClient(defaulting togemini-3.8-flashwith thought-signature preservation, Vertex AI support, and sharedhttpx2.AsyncClientpooling), persisting transcripts in owner-scopedMemorySessionStoreorLitestarStoreSessionStorebackends, and emitting typedAgentStreamFrameServer-Sent Events. - Bidirectional Protocol Bridges (
agent_to_mcp,mcp_to_tools,discover_mcp_tools,agent_to_a2a): Zero-boilerplate adapters connecting marked Litestar MCP routes, remote Streamable HTTP MCP servers (MCPStreamableHTTPClient), localAgentorAgentGroupruntimes, and A2A 1.0 endpoints. - Official A2A 1.0 Adapter (
LitestarA2A,A2AConfig): First-party Litestar plugin wrappinga2a-sdk(>=1.1.4)DefaultRequestHandler,AgentExecutor, andTaskStorecontracts across/.well-known/agent-card.jsondiscovery, JSON-RPC 2.0 (POST /a2a), and native A2A 1.0HTTP+JSONREST routes with/{tenant:str}path parameters andX-A2A-Tenantheader multi-tenancy.
Installation¶
The core Agent, AgentGroup, AgentRuntime, TurnBudget, SessionStore, AgentChatController, MockModelClient, and MCP protocol bridges (agent_to_mcp, mcp_to_tools, discover_mcp_tools) ship in the base litestar-mcp package. Install the google-genai and a2a extras to unlock GoogleGenAIClient and LitestarA2A / agent_to_a2a:
Universal Dependency Injection Across Tools & Skills¶
Tools decorated with @tool, SkillController methods, and PromptController methods support four dependency injection mechanisms across HTTP routes, MCP tools/call / prompts/get, and AgentRuntime turns:
| Mechanism | Declaration Syntax | Schema Behavior & Resolution |
|---|---|---|
| Litestar Native DI | dependencies={"svc": Provide(...)} on controller, router, app, or @tool(dependencies=...) |
Excluded from tool JSON Schema; resolved via Litestar Provide callables or async generators |
| Dishka | svc: FromDishka[Service] parameter annotation on @tool or @prompt |
Excluded from tool JSON Schema; resolved from the active request or application Dishka container |
| Third-Party DI Markers | Annotated[Service, Inject()] or service: Service = Depends(fn) |
Excluded from tool JSON Schema; resolved from app.state containers (wireup_container, svcs_registry, di_container, container) or callable provider |
| Custom Resolver Hook | ToolContext(container=..., dependency_resolver=...) |
Invokes dependency_resolver(param_name, type_hint, ctx) per injected parameter during standalone execution |
Guides in This Section¶
| Guide | Topics Covered |
|---|---|
| Agent Runtime & Turn Budgets | Agent, @tool, ToolContext, AgentRuntime plugin and runtime dependency, TurnBudget & BudgetExceededError, ModelClient, MockModelClient, and GoogleGenAIClient (gemini-3.8-flash) |
| Agent Groups & Handoffs | AgentGroup(coordinator=..., specialists=[...]), automatic Literal-typed transfer_to_agent synthesis, non-mutating specialist isolation, and the runnable Coffee Shop example |
| Sessions & SSE Streaming | SessionStore, MemorySessionStore, LitestarStoreSessionStore, strict owner_id IDOR prevention, AgentChatController, QueuedAgentChatController, Last-Event-ID cursor replay, and AgentStreamFrame events |
| Protocol Bridges | Bidirectional interoperability with agent_to_mcp, mcp_to_tools, discover_mcp_tools (MCPStreamableHTTPClient), and agent_to_a2a |
| A2A 1.0 Protocol & HTTP+JSON | LitestarA2A, A2AConfig, /.well-known/agent-card.json (ETag, Cache-Control, agent_card_route_opt), JSON-RPC 2.0 (POST /a2a), HTTP+JSON REST routes, stream_cleanup_timeout, and a2a_activated_extensions |
| Multi-Tenant A2A Routing | /{tenant:str} path parameters, X-A2A-Tenant header fallback, authoritative context_builder(request, context), principal user_name resolution, and owner-scoped TaskStore isolation |