"""This module defines various message types used for agent-to-agent communication.Each message type inherits either from the BaseChatMessage class or BaseAgentEventclass and includes specific fields relevant to the type of message being sent."""fromabcimportABCfromtypingimportList,Literalfromautogen_coreimportFunctionCall,Imagefromautogen_core.modelsimportFunctionExecutionResult,RequestUsagefrompydanticimportBaseModel,ConfigDict,Fieldfromtyping_extensionsimportAnnotated
[docs]classBaseMessage(BaseModel,ABC):"""Base class for all message types."""source:str"""The name of the agent that sent this message."""models_usage:RequestUsage|None=None"""The model client usage incurred when producing this message."""model_config=ConfigDict(arbitrary_types_allowed=True)
classBaseChatMessage(BaseMessage,ABC):"""Base class for chat messages."""passclassBaseAgentEvent(BaseMessage,ABC):"""Base class for agent events."""pass
[docs]classTextMessage(BaseChatMessage):"""A text message."""content:str"""The content of the message."""type:Literal["TextMessage"]="TextMessage"
[docs]classMultiModalMessage(BaseChatMessage):"""A multimodal message."""content:List[str|Image]"""The content of the message."""type:Literal["MultiModalMessage"]="MultiModalMessage"
[docs]classStopMessage(BaseChatMessage):"""A message requesting stop of a conversation."""content:str"""The content for the stop message."""type:Literal["StopMessage"]="StopMessage"
[docs]classHandoffMessage(BaseChatMessage):"""A message requesting handoff of a conversation to another agent."""target:str"""The name of the target agent to handoff to."""content:str"""The handoff message to the target agent."""type:Literal["HandoffMessage"]="HandoffMessage"
[docs]classToolCallRequestEvent(BaseAgentEvent):"""An event signaling a request to use tools."""content:List[FunctionCall]"""The tool calls."""type:Literal["ToolCallRequestEvent"]="ToolCallRequestEvent"
[docs]classToolCallExecutionEvent(BaseAgentEvent):"""An event signaling the execution of tool calls."""content:List[FunctionExecutionResult]"""The tool call results."""type:Literal["ToolCallExecutionEvent"]="ToolCallExecutionEvent"
[docs]classToolCallSummaryMessage(BaseChatMessage):"""A message signaling the summary of tool call results."""content:str"""Summary of the the tool call results."""type:Literal["ToolCallSummaryMessage"]="ToolCallSummaryMessage"
ChatMessage=Annotated[TextMessage|MultiModalMessage|StopMessage|ToolCallSummaryMessage|HandoffMessage,Field(discriminator="type")]"""Messages for agent-to-agent communication only."""AgentEvent=Annotated[ToolCallRequestEvent|ToolCallExecutionEvent,Field(discriminator="type")]"""Events emitted by agents and teams when they work, not used for agent-to-agent communication."""__all__=["BaseMessage","TextMessage","MultiModalMessage","StopMessage","HandoffMessage","ToolCallRequestEvent","ToolCallExecutionEvent","ToolCallSummaryMessage","ChatMessage","AgentEvent",]