@@ -123,19 +123,6 @@ def __init__(self, host_agent: ChatAgent, agent_type: str):
123123 self .host_agent : ChatAgent = host_agent
124124 self .agent_type : str = agent_type
125125
126- async def handle (self , msg : ChatHistory ) -> ChatMessage :
127- addr = Address (name = self .agent_type , id = self .host_agent .address .id )
128- result = await self .host_agent .channel .publish (addr , msg .encode (), request = True )
129- return ChatMessage .decode (result )
130-
131-
132- class StreamDelegate :
133- """A streaming delegate agent that helps to handle a specific task."""
134-
135- def __init__ (self , host_agent : StreamChatAgent , agent_type : str ):
136- self .host_agent : StreamChatAgent = host_agent
137- self .agent_type : str = agent_type
138-
139126 async def handle (self , msg : ChatHistory ) -> AsyncIterator [ChatMessage ]:
140127 addr = Address (name = self .agent_type , id = self .host_agent .address .id )
141128 result = self .host_agent .channel .publish_multi (addr , msg .encode ())
@@ -186,7 +173,7 @@ async def run(*args: Any, **kwargs: Any) -> ChatMessage | str:
186173 return run
187174
188175
189- class StreamChatAgent (BaseAgent ):
176+ class ChatAgent (BaseAgent ):
190177 def __init__ (
191178 self ,
192179 name : str = "" ,
@@ -239,7 +226,7 @@ async def get_swarm_agent(self) -> SwarmAgent:
239226
240227 async def agent (self , agent_type : str ) -> AsyncIterator [ChatMessage ]:
241228 """The candidate agent to delegate the conversation to."""
242- async for chunk in StreamDelegate (self , agent_type ).handle (self ._history ):
229+ async for chunk in Delegate (self , agent_type ).handle (self ._history ):
243230 yield chunk
244231
245232 @handler
@@ -311,27 +298,3 @@ async def _is_submit_message(self, history: ChatHistory) -> bool:
311298 return False
312299 last_msg = history .messages [- 1 ]
313300 return last_msg .role == "user" and last_msg .type == "submit"
314-
315-
316- class ChatAgent (StreamChatAgent ):
317- """Non-streaming ChatAgent."""
318-
319- async def agent (self , agent_type : str ) -> ChatMessage :
320- """The candidate agent to delegate the conversation to."""
321- return await Delegate (self , agent_type ).handle (self ._history )
322-
323- @handler
324- async def handle_history (self , msg : ChatHistory , ctx : Context ) -> ChatMessage :
325- accumulated_response = ChatMessage (role = "assistant" , content = "" )
326- response = super ().handle_history (msg , ctx )
327- async for chunk in response :
328- accumulated_response .content += chunk .content
329- return accumulated_response
330-
331- @handler
332- async def handle_message (self , msg : ChatMessage , ctx : Context ) -> ChatMessage :
333- accumulated_response = ChatMessage (role = "assistant" , content = "" )
334- response = super ().handle_message (msg , ctx )
335- async for chunk in response :
336- accumulated_response .content += chunk .content
337- return accumulated_response
0 commit comments