From c0155ad6acb16a1dc959d0a6aeac1e2c9eccaf5a Mon Sep 17 00:00:00 2001 From: snooyen Date: Sun, 23 Nov 2025 11:33:30 -0800 Subject: [PATCH 1/3] feat(a2a): allow passing additional keyword arguments to fastapi constructor --- src/strands/multiagent/a2a/server.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/strands/multiagent/a2a/server.py b/src/strands/multiagent/a2a/server.py index bbfbc824d..5a9de5489 100644 --- a/src/strands/multiagent/a2a/server.py +++ b/src/strands/multiagent/a2a/server.py @@ -196,16 +196,21 @@ def to_starlette_app(self) -> Starlette: return a2a_app - def to_fastapi_app(self) -> FastAPI: + def to_fastapi_app(self, **kwargs: Any) -> 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: + **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( + **kwargs + ) if self.mount_path: # Create parent app and mount the A2A app at the specified path From aeb79e813060790d53b036b75f5f3b948e1d3ee1 Mon Sep 17 00:00:00 2001 From: snooyen Date: Mon, 24 Nov 2025 09:50:09 -0800 Subject: [PATCH 2/3] feat(a2a): allow passing additional keyword arguments to starlette constructor --- src/strands/multiagent/a2a/server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/strands/multiagent/a2a/server.py b/src/strands/multiagent/a2a/server.py index 5a9de5489..3e2951f14 100644 --- a/src/strands/multiagent/a2a/server.py +++ b/src/strands/multiagent/a2a/server.py @@ -176,16 +176,20 @@ def agent_skills(self, skills: list[AgentSkill]) -> None: """ self._agent_skills = skills - def to_starlette_app(self) -> Starlette: + def to_starlette_app(self, **kwargs: Any) -> 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. + **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( + **kwargs + ) if self.mount_path: # Create parent app and mount the A2A app at the specified path From 9c566531de2175f84b333b630fddfc62463e6a82 Mon Sep 17 00:00:00 2001 From: Aaron Farntrog Date: Wed, 17 Dec 2025 11:51:31 -0500 Subject: [PATCH 3/3] update to use accept dictionary instead of kwargs and add tests. --- src/strands/multiagent/a2a/server.py | 13 +++++------ tests/strands/multiagent/a2a/test_server.py | 24 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/strands/multiagent/a2a/server.py b/src/strands/multiagent/a2a/server.py index 3e2951f14..a9093742f 100644 --- a/src/strands/multiagent/a2a/server.py +++ b/src/strands/multiagent/a2a/server.py @@ -176,19 +176,20 @@ def agent_skills(self, skills: list[AgentSkill]) -> None: """ self._agent_skills = skills - def to_starlette_app(self, **kwargs: Any) -> 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. - **kwargs: Additional keyword arguments to pass to the Starlette constructor. + 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( - **kwargs + **app_kwargs or {} ) if self.mount_path: @@ -200,20 +201,20 @@ def to_starlette_app(self, **kwargs: Any) -> Starlette: return a2a_app - def to_fastapi_app(self, **kwargs: Any) -> 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: - **kwargs: Additional keyword arguments to pass to the FastAPI constructor. + 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( - **kwargs + **app_kwargs or {} ) if self.mount_path: diff --git a/tests/strands/multiagent/a2a/test_server.py b/tests/strands/multiagent/a2a/test_server.py index 00dd164b5..647fce230 100644 --- a/tests/strands/multiagent/a2a/test_server.py +++ b/tests/strands/multiagent/a2a/test_server.py @@ -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"