Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions docs/user-guide/concepts/multi-agent/agent-to-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The `A2AServer` constructor accepts several configuration options:
The `A2AServer` provides access to the underlying FastAPI or Starlette application objects allowing you to further customize server behavior.

```python
from contextlib import asynccontextmanager
from strands import Agent
from strands.multiagent.a2a import A2AServer
import uvicorn
Expand All @@ -94,13 +95,22 @@ import uvicorn
agent = Agent(name="My Agent", description="A customizable agent", callback_handler=None)
a2a_server = A2AServer(agent=agent)

@asynccontextmanager
async def lifespan(app: FastAPI):
"""Manage application lifespan with proper error handling."""
# Startup tasks
yield # Application runs here
# Shutdown tasks

# Access the underlying FastAPI app
fastapi_app = a2a_server.to_fastapi_app()
# Allows passing keyword arguments to FastAPI constructor for further customization
fastapi_app = a2a_server.to_fastapi_app(lifespan=lifespan)
# Add custom middleware, routes, or configuration
fastapi_app.add_middleware(...)

# Or access the Starlette app
starlette_app = a2a_server.to_starlette_app()
# Allows passing keyword arguments to FastAPI constructor for further customization
starlette_app = a2a_server.to_starlette_app(lifespan=lifespan)
# Customize as needed

# You can then serve the customized app directly
Expand Down