Appearance
A2A API
Agent-to-Agent protocol server and client types (A2A Protocol v1.0 via a2a-sdk>=1.0.0). For concepts, production examples, and migration from v0.3, see Agent-to-Agent (A2A).
Installation
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents[a2a]==0.3.0"A2AServer
python
from elsai.multiagent.a2a import A2AServerWraps a template agent or agent factory as an A2A-compatible HTTP server.
python
A2AServer(
agent, # Agent instance or factory callable
*,
name=None,
description=None,
version="0.0.1",
skills=None,
**options,
)| Parameter | Type | Default | Description |
|---|---|---|---|
agent | Agent | Callable[[A2AContextContext], Agent] | (required) | Template agent (cloned per context) or factory that builds a fully configured agent per context |
name | str | None | agent.name (template mode) | Display name in the agent card |
description | str | None | agent.description (template mode) | Description in the agent card |
version | str | "0.0.1" | Agent version string |
skills | list[AgentSkill] | None | None | Capabilities advertised in the agent card |
Network options
| Parameter | Default | Description |
|---|---|---|
host | 127.0.0.1 | Bind address |
port | 9000 | Port |
http_url | auto-detected | Public URL advertised in the agent card; path sets mount prefix |
serve_at_root | False | Mount routes at / when http_url has a path prefix |
public_url_scheme | auto | http or https for auto-generated URLs |
Session options
| Parameter | Default | Description |
|---|---|---|
session_store | auto-created | Pre-built A2ASessionStore; pass to share or customize the pool |
session_manager_factory | file-backed under ELSAI_A2A_SESSION_DIR | (context_id) -> SessionManager for template-clone mode |
max_active_contexts | 100 | LRU limit for in-memory context agents (None = unlimited) |
strict_tool_policy | False | When True, reject startup if warnlisted tools are not PER_CONTEXT-safe |
Handler options
| Parameter | Default | Description |
|---|---|---|
task_store | in-memory | Persistence backend for A2A task state |
queue_manager | None | Optional task queue manager |
push_config_store | None | Optional push notification config store |
push_sender | None | Optional push notification sender |
enable_a2a_compliant_streaming | True | Stream content via artifact updates (A2A v1 compliant) |
enable_v0_3_compat | False | Accept legacy v0.3 JSON-RPC wire format |
Methods and properties
| Member | Description |
|---|---|
serve() | Start the HTTP server (blocking) |
to_fastapi_app() | Return a FastAPI app for embedding |
to_starlette_app() | Return a Starlette app for embedding |
public_agent_card | a2a.types.AgentCard advertised at /.well-known/agent-card.json |
session_store | The A2ASessionStore backing per-context agents |
A2AAgent
python
from elsai.agent import A2AAgentClient wrapper for calling a remote A2A server.
python
A2AAgent(
endpoint,
*,
name=None,
description=None,
timeout=300,
client_config=None,
)| Parameter | Type | Default | Description |
|---|---|---|---|
endpoint | str | (required) | Remote A2A server base URL |
name | str | None | from agent card | Name when wrapping as a tool |
description | str | None | from agent card | Description when wrapping as a tool |
timeout | int | 300 | Request timeout in seconds (when no custom httpx_client) |
client_config | ClientConfig | None | None | a2a.client.ClientConfig for auth, transport, and streaming |
Deprecated
a2a_client_factory is deprecated — use client_config instead.
| Method | Description |
|---|---|
__call__(prompt) | Synchronous invocation |
invoke_async(prompt) | Async invocation |
stream_async(prompt) | Async streaming — yields a2a_stream events, then AgentResult |
get_agent_card() | Fetch and cache the remote agent card |
as_tool() | Wrap as an AgentTool for orchestrators |
A2ASessionStore
python
from elsai.multiagent.a2a import A2ASessionStoreMaps A2A context_id values to dedicated agents with durable session backing.
python
A2ASessionStore(
agent, # Agent template or factory
*,
session_manager_factory=None,
max_active_contexts=100,
strict_tool_policy=False,
)| Parameter | Type | Default | Description |
|---|---|---|---|
agent | Agent | Callable[[A2AContextContext], Agent] | (required) | Template to clone or factory callable |
session_manager_factory | Callable[[str], SessionManager] | None | file-backed default | Returns a SessionManager per context_id (template-clone mode only) |
max_active_contexts | int | None | 100 | LRU in-memory pool limit |
strict_tool_policy | bool | False | Fail when warnlisted tools are not PER_CONTEXT-safe |
Properties
| Property | Description |
|---|---|
uses_factory | True when agents are created via a factory callable |
in_flight_contexts | frozenset of context_id values currently holding the execution lock |
metrics | A2ASessionStoreMetrics instance |
Methods
| Method | Description |
|---|---|
get_agent(ctx) | Return the agent for ctx.context_id, creating or restoring from storage |
get_lock(context_id) | Per-context asyncio.Lock |
hold_context(context_id) | Async context manager — acquires lock, marks context in-flight (excluded from LRU eviction) |
close(context_id) | Remove agent from memory; skips in-flight contexts; does not delete persisted data |
close_all() | Remove all non-in-flight agents from memory |
probe_strict_tool_policy() | Validate factory-built agents at startup when strict_tool_policy=True |
A2AContextContext
python
from elsai.multiagent.a2a import A2AContextContextPer-conversation context passed to agent factories.
| Field | Type | Description |
|---|---|---|
context_id | str | A2A conversation identifier (maps to session_id) |
task_id | str | None | Optional A2A task ID |
metadata | dict | None | Optional request metadata |
A2ASessionStoreMetrics
python
from elsai.multiagent.a2a import A2ASessionStoreMetrics| Field | Type | Description |
|---|---|---|
cache_hits | int | Times a cached context agent was reused |
cache_misses | int | Times a new context agent was created |
evictions | int | Times an agent was removed from the in-memory pool by LRU |
Tool session policy
python
from elsai.types.tools import A2AToolSessionScope
from elsai.multiagent.a2a import A2A_STATEFUL_TOOL_WARNLISTA2AToolSessionScope
| Value | Description |
|---|---|
SHARED | Safe to share across contexts (default for stateless @tool functions) |
CONTEXT_KEYED | Mutable state keyed by invocation_state["a2a_context_id"] |
PER_CONTEXT | Requires clone_for_a2a_context(context_id) |
A2A_STATEFUL_TOOL_WARNLIST
Built-in tool names inspected at A2A server startup:
python_repl, shell, use_computer, code_interpreter, browser, mcp_client, graph, workflow, mem0_memory
When strict_tool_policy=True, each warnlisted tool on the template agent must declare PER_CONTEXT scope and implement clone_for_a2a_context().
ElsaiA2AExecutor
Internal request handler that routes A2A tasks through A2ASessionStore. Configured automatically by A2AServer; injects a2a_context_id into tool invocation_state.
Stream normalizer exports
For custom clients built on a2a-sdk 1.x, Elsai converts v1 StreamResponse chunks into the legacy A2AResponse shape used by A2AAgent.stream_async:
python
from a2a.types import SendMessageRequest
from elsai.multiagent.a2a import A2AStreamNormalizer, iter_normalized_responses
request = SendMessageRequest(message=message)
async for event in iter_normalized_responses(client, request):
... # Message or (Task, update_event) tuple
normalizer = A2AStreamNormalizer()
legacy_event = normalizer.normalize(stream_response_chunk)| Export | Description |
|---|---|
iter_normalized_responses | Async generator: v1 StreamResponse → legacy A2AResponse events |
A2AStreamNormalizer | Stateful single-chunk converter for custom clients |
Environment variables
Session and tool state
| Variable | Default | Description |
|---|---|---|
ELSAI_A2A_SESSION_DIR | {tempdir}/elsai-a2a-sessions | Root for A2A session files and on-disk per-context tool state |
PYTHON_REPL_PERSISTENCE_DIR | ./repl_state/ (cwd) | Standalone (non-A2A) persistence root for python_repl |
Production deployment (convention)
Used in A2A concept — S3 production example:
| Variable | Description |
|---|---|
A2A_SESSIONS_BUCKET | S3 bucket for A2A conversation history |
A2A_SESSIONS_PREFIX | S3 key prefix (e.g. a2a/contexts/) |
AWS_REGION | AWS region for S3 and Bedrock tools |
A2A_PUBLIC_URL | Public URL for A2AServer(http_url=…) in the agent card |
Requires standard AWS credentials (env vars or IAM role) when using S3 session backing.
Related
- Agent-to-Agent (A2A) — concepts, S3 production, migration from v0.3
- Sessions — A2A sessions — file and S3 session backing
- Multi-Agent API — Graph, Swarm, and
as_tool - Agents release notes — v0.3.0 A2A upgrade summary