@@ -28,9 +28,8 @@ def __init__(
2828 self ,
2929 agent : SAAgent ,
3030 * ,
31- name : str ,
32- description : str ,
33- host : str = "localhost" ,
31+ # AgentCard
32+ host : str = "0.0.0" ,
3433 port : int = 9000 ,
3534 version : str = "0.0.1" ,
3635 ):
@@ -44,13 +43,14 @@ def __init__(
4443 port: The port to bind the A2A server to. Defaults to 9000.
4544 version: The version of the agent. Defaults to "0.0.1".
4645 """
47- self .name = name
48- self .description = description
4946 self .host = host
5047 self .port = port
5148 self .http_url = f"http://{ self .host } :{ self .port } /"
5249 self .version = version
5350 self .strands_agent = agent
51+ self .name = self .strands_agent .name
52+ self .description = self .strands_agent .description
53+ # TODO: enable configurable capabilities and request handler
5454 self .capabilities = AgentCapabilities ()
5555 self .request_handler = DefaultRequestHandler (
5656 agent_executor = StrandsA2AExecutor (self .strands_agent ),
@@ -67,7 +67,15 @@ def public_agent_card(self) -> AgentCard:
6767
6868 Returns:
6969 AgentCard: The public agent card containing metadata about this agent.
70+
71+ Raises:
72+ ValueError: If name or description is None or empty.
7073 """
74+ if not self .name :
75+ raise ValueError ("A2A agent name cannot be None or empty" )
76+ if not self .description :
77+ raise ValueError ("A2A agent description cannot be None or empty" )
78+
7179 return AgentCard (
7280 name = self .name ,
7381 description = self .description ,
@@ -89,6 +97,7 @@ def agent_skills(self) -> list[AgentSkill]:
8997 Returns:
9098 list[AgentSkill]: A list of skills this agent provides.
9199 """
100+ # TODO: translate Strands tools (native & MCP) to skills
92101 return []
93102
94103 def to_starlette_app (self ) -> Starlette :
@@ -100,8 +109,7 @@ def to_starlette_app(self) -> Starlette:
100109 Returns:
101110 Starlette: A Starlette application configured to serve this agent.
102111 """
103- starlette_app = A2AStarletteApplication (agent_card = self .public_agent_card , http_handler = self .request_handler )
104- return starlette_app .build ()
112+ return A2AStarletteApplication (agent_card = self .public_agent_card , http_handler = self .request_handler ).build ()
105113
106114 def to_fastapi_app (self ) -> FastAPI :
107115 """Create a FastAPI application for serving this agent via HTTP.
@@ -112,8 +120,7 @@ def to_fastapi_app(self) -> FastAPI:
112120 Returns:
113121 FastAPI: A FastAPI application configured to serve this agent.
114122 """
115- fastapi_app = A2AFastAPIApplication (agent_card = self .public_agent_card , http_handler = self .request_handler )
116- return fastapi_app .build ()
123+ return A2AFastAPIApplication (agent_card = self .public_agent_card , http_handler = self .request_handler ).build ()
117124
118125 def serve (self , app_type : Literal ["fastapi" , "starlette" ] = "starlette" , ** kwargs : Any ) -> None :
119126 """Start the A2A server with the specified application type.
@@ -128,12 +135,14 @@ def serve(self, app_type: Literal["fastapi", "starlette"] = "starlette", **kwarg
128135 **kwargs: Additional keyword arguments to pass to uvicorn.run.
129136 """
130137 try :
131- log .info ("Starting Strands agent A2A server..." )
138+ log .info ("Starting Strands A2A server..." )
132139 if app_type == "fastapi" :
133140 uvicorn .run (self .to_fastapi_app (), host = self .host , port = self .port , ** kwargs )
134141 else :
135142 uvicorn .run (self .to_starlette_app (), host = self .host , port = self .port , ** kwargs )
136143 except KeyboardInterrupt :
137- log .warning ("Server shutdown requested (KeyboardInterrupt)." )
144+ log .warning ("Strands A2A server shutdown requested (KeyboardInterrupt)." )
145+ except Exception :
146+ log .exception ("Strands A2A server encountered exception." )
138147 finally :
139- log .info ("Strands agent A2A server has shutdown." )
148+ log .info ("Strands A2A server has shutdown." )
0 commit comments