@@ -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