generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 501
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Statement
The Strands SDK should allow users to pass additional keyword arguments to fastapi and starlette constructors supports further advanced customization of A2A servers.
Proposed Solution
The A2A Python SDK A2AFastAPI and A2AStarletteApplication classes both provide build methods which expose **kwarg parameters. The respective to_fastapi_app and to_starlette_app methonds on the Strands SDK A2AServer class simply need to be updated to enable passing this through to the A2A Python SDK build methods.
Example code:
from contextlib import asynccontextmanager
from fastapi import FastAPI
from strands import Agent
from strands.multiagent.a2a import A2AServer
def initialize_app() -> FastAPI:
"""Initialize and configure FastAPI application."""
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Manage application lifespan with proper error handling."""
# Startup tasks
yield # Application runs here
# Shutdown tasks
# Create your agent and A2A server
agent = Agent(name="My Agent", description="A customizable agent", callback_handler=None)
a2a_server = A2AServer(agent=agent)
serve_docs_enabled = False
app = a2a_server.to_fastapi_app(
title=config.app_name,
docs_url="/docs" if serve_docs_enabled else None,
redoc_url="/redoc" if serve_docs_enabled else None,
openapi_url="/openapi.json" if serve_docs_enabled else None,
debug=config.debug,
lifespan=lifespan,
)
return appUse Case
Enables users to further customize A2AServers as needed:
- Startup / Shutdown events by passing a lifespan function to the FastAPI constructor. This is preferable to using the now deprecated startup/shutdown event handlers.
- enabling/disabling documentation endpoints
- enabling/disabling
debugtracebacks
Alternatives Solutions
No response
Additional Context
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request