Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions src/strands/multiagent/a2a/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,21 @@ def agent_skills(self, skills: list[AgentSkill]) -> None:
"""
self._agent_skills = skills

def to_starlette_app(self) -> Starlette:
def to_starlette_app(self, *, app_kwargs: dict[str, Any] | None = None) -> Starlette:
"""Create a Starlette application for serving this agent via HTTP.

Automatically handles path-based mounting if a mount path was derived
from the http_url parameter.

Args:
app_kwargs: Additional keyword arguments to pass to the Starlette constructor.

Returns:
Starlette: A Starlette application configured to serve this agent.
"""
a2a_app = A2AStarletteApplication(agent_card=self.public_agent_card, http_handler=self.request_handler).build()
a2a_app = A2AStarletteApplication(agent_card=self.public_agent_card, http_handler=self.request_handler).build(
**app_kwargs or {}
)

if self.mount_path:
# Create parent app and mount the A2A app at the specified path
Expand All @@ -196,16 +201,21 @@ def to_starlette_app(self) -> Starlette:

return a2a_app

def to_fastapi_app(self) -> FastAPI:
def to_fastapi_app(self, *, app_kwargs: dict[str, Any] | None = None) -> FastAPI:
"""Create a FastAPI application for serving this agent via HTTP.

Automatically handles path-based mounting if a mount path was derived
from the http_url parameter.

Args:
app_kwargs: Additional keyword arguments to pass to the FastAPI constructor.

Returns:
FastAPI: A FastAPI application configured to serve this agent.
"""
a2a_app = A2AFastAPIApplication(agent_card=self.public_agent_card, http_handler=self.request_handler).build()
a2a_app = A2AFastAPIApplication(agent_card=self.public_agent_card, http_handler=self.request_handler).build(
**app_kwargs or {}
)

if self.mount_path:
# Create parent app and mount the A2A app at the specified path
Expand Down
24 changes: 24 additions & 0 deletions tests/strands/multiagent/a2a/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,27 @@ def test_serve_at_root_edge_cases(mock_strands_agent):
)
assert server3.mount_path == ""
assert server3.http_url == "http://api.example.com/v1/agents/team1/agent1/"


def test_to_starlette_app_with_app_kwargs(mock_strands_agent):
"""Test that to_starlette_app passes app_kwargs to the Starlette constructor."""
mock_strands_agent.tool_registry.get_all_tools_config.return_value = {}

a2a_agent = A2AServer(mock_strands_agent, skills=[])

app = a2a_agent.to_starlette_app(app_kwargs={"debug": True})

assert isinstance(app, Starlette)
assert app.debug is True


def test_to_fastapi_app_with_app_kwargs(mock_strands_agent):
"""Test that to_fastapi_app passes app_kwargs to the FastAPI constructor."""
mock_strands_agent.tool_registry.get_all_tools_config.return_value = {}

a2a_agent = A2AServer(mock_strands_agent, skills=[])

app = a2a_agent.to_fastapi_app(app_kwargs={"title": "Custom Agent Title"})

assert isinstance(app, FastAPI)
assert app.title == "Custom Agent Title"
Loading