Skip to content

Commit 6b358fe

Browse files
jer96jer
andauthored
refactor(a2a): configurable host and port and remove excessive logging (#423)
Co-authored-by: jer <jerebill@amazon.com>
1 parent 48bcd5b commit 6b358fe

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/strands/multiagent/a2a/executor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ async def _handle_streaming_event(self, event: dict[str, Any], updater: TaskUpda
111111
)
112112
elif "result" in event:
113113
await self._handle_agent_result(event["result"], updater)
114-
else:
115-
logger.warning("Unexpected streaming event: %s", event)
116114

117115
async def _handle_agent_result(self, result: SAAgentResult | None, updater: TaskUpdater) -> None:
118116
"""Handle the final result from the Strands Agent.

src/strands/multiagent/a2a/server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ def to_fastapi_app(self) -> FastAPI:
138138
"""
139139
return A2AFastAPIApplication(agent_card=self.public_agent_card, http_handler=self.request_handler).build()
140140

141-
def serve(self, app_type: Literal["fastapi", "starlette"] = "starlette", **kwargs: Any) -> None:
141+
def serve(
142+
self,
143+
app_type: Literal["fastapi", "starlette"] = "starlette",
144+
*,
145+
host: str | None = None,
146+
port: int | None = None,
147+
**kwargs: Any,
148+
) -> None:
142149
"""Start the A2A server with the specified application type.
143150
144151
This method starts an HTTP server that exposes the agent via the A2A protocol.
@@ -148,14 +155,16 @@ def serve(self, app_type: Literal["fastapi", "starlette"] = "starlette", **kwarg
148155
Args:
149156
app_type: The type of application to serve, either "fastapi" or "starlette".
150157
Defaults to "starlette".
158+
host: The host address to bind the server to. Defaults to "0.0.0.0".
159+
port: The port number to bind the server to. Defaults to 9000.
151160
**kwargs: Additional keyword arguments to pass to uvicorn.run.
152161
"""
153162
try:
154163
logger.info("Starting Strands A2A server...")
155164
if app_type == "fastapi":
156-
uvicorn.run(self.to_fastapi_app(), host=self.host, port=self.port, **kwargs)
165+
uvicorn.run(self.to_fastapi_app(), host=host or self.host, port=port or self.port, **kwargs)
157166
else:
158-
uvicorn.run(self.to_starlette_app(), host=self.host, port=self.port, **kwargs)
167+
uvicorn.run(self.to_starlette_app(), host=host or self.host, port=port or self.port, **kwargs)
159168
except KeyboardInterrupt:
160169
logger.warning("Strands A2A server shutdown requested (KeyboardInterrupt).")
161170
except Exception:

0 commit comments

Comments
 (0)