[docs]@dataclass(kw_only=True)classResponse:"""A response from calling :meth:`ChatAgent.on_messages`."""chat_message:ChatMessage"""A chat message produced by the agent as the response."""inner_messages:Sequence[AgentEvent|ChatMessage]|None=None"""Inner messages produced by the agent, they can be :class:`AgentEvent` or :class:`ChatMessage`."""
[docs]classChatAgent(ABC,TaskRunner,ComponentBase[BaseModel]):"""Protocol for a chat agent."""component_type="agent"@property@abstractmethoddefname(self)->str:"""The name of the agent. This is used by team to uniquely identify the agent. It should be unique within the team."""...@property@abstractmethoddefdescription(self)->str:"""The description of the agent. This is used by team to make decisions about which agents to use. The description should describe the agent's capabilities and how to interact with it."""...@property@abstractmethoddefproduced_message_types(self)->Sequence[type[ChatMessage]]:"""The types of messages that the agent produces in the :attr:`Response.chat_message` field. They must be :class:`ChatMessage` types."""...
[docs]@abstractmethodasyncdefon_messages(self,messages:Sequence[ChatMessage],cancellation_token:CancellationToken)->Response:"""Handles incoming messages and returns a response."""...
[docs]@abstractmethoddefon_messages_stream(self,messages:Sequence[ChatMessage],cancellation_token:CancellationToken)->AsyncGenerator[AgentEvent|ChatMessage|Response,None]:"""Handles incoming messages and returns a stream of inner messages and and the final item is the response."""...
[docs]@abstractmethodasyncdefon_reset(self,cancellation_token:CancellationToken)->None:"""Resets the agent to its initialization state."""...
[docs]@abstractmethodasyncdefon_pause(self,cancellation_token:CancellationToken)->None:"""Called when the agent is paused. The agent may be running in :meth:`on_messages` or :meth:`on_messages_stream` when this method is called."""...
[docs]@abstractmethodasyncdefon_resume(self,cancellation_token:CancellationToken)->None:"""Called when the agent is resumed. The agent may be running in :meth:`on_messages` or :meth:`on_messages_stream` when this method is called."""...
[docs]@abstractmethodasyncdefsave_state(self)->Mapping[str,Any]:"""Save agent state for later restoration"""...
[docs]@abstractmethodasyncdefload_state(self,state:Mapping[str,Any])->None:"""Restore agent from saved state"""...
[docs]@abstractmethodasyncdefclose(self)->None:"""Release any resources held by the agent."""...