autogen_agentchat.messages#
This module defines various message types used for agent-to-agent communication. Each message type inherits either from the BaseChatMessage class or BaseAgentEvent class and includes specific fields relevant to the type of message being sent.
- AgentEvent#
Events emitted by agents and teams when they work, not used for agent-to-agent communication.
alias of
Annotated
[ToolCallRequestEvent
|ToolCallExecutionEvent
|MemoryQueryEvent
|UserInputRequestedEvent
|ModelClientStreamingChunkEvent
|ThoughtEvent
, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]
- pydantic model BaseMessage[source]#
Bases:
BaseModel
,ABC
Base class for all message types.
Show JSON schema
{ "title": "BaseMessage", "description": "Base class for all message types.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source" ] }
- Fields:
- field models_usage: RequestUsage | None = None#
The model client usage incurred when producing this message.
- ChatMessage#
Messages for agent-to-agent communication only.
alias of
Annotated
[TextMessage
|MultiModalMessage
|StopMessage
|ToolCallSummaryMessage
|HandoffMessage
, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]
- pydantic model HandoffMessage[source]#
Bases:
BaseChatMessage
A message requesting handoff of a conversation to another agent.
Show JSON schema
{ "title": "HandoffMessage", "description": "A message requesting handoff of a conversation to another agent.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "target": { "title": "Target", "type": "string" }, "content": { "title": "Content", "type": "string" }, "context": { "default": [], "items": { "discriminator": { "mapping": { "AssistantMessage": "#/$defs/AssistantMessage", "FunctionExecutionResultMessage": "#/$defs/FunctionExecutionResultMessage", "SystemMessage": "#/$defs/SystemMessage", "UserMessage": "#/$defs/UserMessage" }, "propertyName": "type" }, "oneOf": [ { "$ref": "#/$defs/SystemMessage" }, { "$ref": "#/$defs/UserMessage" }, { "$ref": "#/$defs/AssistantMessage" }, { "$ref": "#/$defs/FunctionExecutionResultMessage" } ] }, "title": "Context", "type": "array" }, "type": { "const": "HandoffMessage", "default": "HandoffMessage", "title": "Type", "type": "string" } }, "$defs": { "AssistantMessage": { "description": "Assistant message are sampled from the language model.", "properties": { "content": { "anyOf": [ { "type": "string" }, { "items": { "$ref": "#/$defs/FunctionCall" }, "type": "array" } ], "title": "Content" }, "thought": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Thought" }, "source": { "title": "Source", "type": "string" }, "type": { "const": "AssistantMessage", "default": "AssistantMessage", "title": "Type", "type": "string" } }, "required": [ "content", "source" ], "title": "AssistantMessage", "type": "object" }, "FunctionCall": { "properties": { "id": { "title": "Id", "type": "string" }, "arguments": { "title": "Arguments", "type": "string" }, "name": { "title": "Name", "type": "string" } }, "required": [ "id", "arguments", "name" ], "title": "FunctionCall", "type": "object" }, "FunctionExecutionResult": { "description": "Function execution result contains the output of a function call.", "properties": { "content": { "title": "Content", "type": "string" }, "name": { "title": "Name", "type": "string" }, "call_id": { "title": "Call Id", "type": "string" }, "is_error": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "title": "Is Error" } }, "required": [ "content", "name", "call_id" ], "title": "FunctionExecutionResult", "type": "object" }, "FunctionExecutionResultMessage": { "description": "Function execution result message contains the output of multiple function calls.", "properties": { "content": { "items": { "$ref": "#/$defs/FunctionExecutionResult" }, "title": "Content", "type": "array" }, "type": { "const": "FunctionExecutionResultMessage", "default": "FunctionExecutionResultMessage", "title": "Type", "type": "string" } }, "required": [ "content" ], "title": "FunctionExecutionResultMessage", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" }, "SystemMessage": { "description": "System message contains instructions for the model coming from the developer.\n\n.. note::\n\n Open AI is moving away from using 'system' role in favor of 'developer' role.\n See `Model Spec <https://cdn.openai.com/spec/model-spec-2024-05-08.html#definitions>`_ for more details.\n However, the 'system' role is still allowed in their API and will be automatically converted to 'developer' role\n on the server side.\n So, you can use `SystemMessage` for developer messages.", "properties": { "content": { "title": "Content", "type": "string" }, "type": { "const": "SystemMessage", "default": "SystemMessage", "title": "Type", "type": "string" } }, "required": [ "content" ], "title": "SystemMessage", "type": "object" }, "UserMessage": { "description": "User message contains input from end users, or a catch-all for data provided to the model.", "properties": { "content": { "anyOf": [ { "type": "string" }, { "items": { "anyOf": [ { "type": "string" }, {} ] }, "type": "array" } ], "title": "Content" }, "source": { "title": "Source", "type": "string" }, "type": { "const": "UserMessage", "default": "UserMessage", "title": "Type", "type": "string" } }, "required": [ "content", "source" ], "title": "UserMessage", "type": "object" } }, "required": [ "source", "target", "content" ] }
- Fields:
- field context: List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] = []#
The model context to be passed to the target agent.
- pydantic model MemoryQueryEvent[source]#
Bases:
BaseAgentEvent
An event signaling the results of memory queries.
Show JSON schema
{ "title": "MemoryQueryEvent", "description": "An event signaling the results of memory queries.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "$ref": "#/$defs/MemoryContent" }, "title": "Content", "type": "array" }, "type": { "const": "MemoryQueryEvent", "default": "MemoryQueryEvent", "title": "Type", "type": "string" } }, "$defs": { "MemoryContent": { "description": "A memory content item.", "properties": { "content": { "anyOf": [ { "type": "string" }, { "format": "binary", "type": "string" }, { "type": "object" }, {} ], "title": "Content" }, "mime_type": { "anyOf": [ { "$ref": "#/$defs/MemoryMimeType" }, { "type": "string" } ], "title": "Mime Type" }, "metadata": { "anyOf": [ { "type": "object" }, { "type": "null" } ], "default": null, "title": "Metadata" } }, "required": [ "content", "mime_type" ], "title": "MemoryContent", "type": "object" }, "MemoryMimeType": { "description": "Supported MIME types for memory content.", "enum": [ "text/plain", "application/json", "text/markdown", "image/*", "application/octet-stream" ], "title": "MemoryMimeType", "type": "string" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- Fields:
- field content: List[MemoryContent] [Required]#
The memory query results.
- pydantic model ModelClientStreamingChunkEvent[source]#
Bases:
BaseAgentEvent
An event signaling a text output chunk from a model client in streaming mode.
Show JSON schema
{ "title": "ModelClientStreamingChunkEvent", "description": "An event signaling a text output chunk from a model client in streaming mode.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "ModelClientStreamingChunkEvent", "default": "ModelClientStreamingChunkEvent", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model MultiModalMessage[source]#
Bases:
BaseChatMessage
A multimodal message.
Show JSON schema
{ "title": "MultiModalMessage", "description": "A multimodal message.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "anyOf": [ { "type": "string" }, {} ] }, "title": "Content", "type": "array" }, "type": { "const": "MultiModalMessage", "default": "MultiModalMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model StopMessage[source]#
Bases:
BaseChatMessage
A message requesting stop of a conversation.
Show JSON schema
{ "title": "StopMessage", "description": "A message requesting stop of a conversation.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "StopMessage", "default": "StopMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model TextMessage[source]#
Bases:
BaseChatMessage
A text message.
Show JSON schema
{ "title": "TextMessage", "description": "A text message.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "TextMessage", "default": "TextMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model ThoughtEvent[source]#
Bases:
BaseAgentEvent
An event signaling the thought process of an agent. It is used to communicate the reasoning tokens generated by a reasoning model, or the extra text content generated by a function call.
Show JSON schema
{ "title": "ThoughtEvent", "description": "An event signaling the thought process of an agent.\nIt is used to communicate the reasoning tokens generated by a reasoning model,\nor the extra text content generated by a function call.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "ThoughtEvent", "default": "ThoughtEvent", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model ToolCallExecutionEvent[source]#
Bases:
BaseAgentEvent
An event signaling the execution of tool calls.
Show JSON schema
{ "title": "ToolCallExecutionEvent", "description": "An event signaling the execution of tool calls.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "$ref": "#/$defs/FunctionExecutionResult" }, "title": "Content", "type": "array" }, "type": { "const": "ToolCallExecutionEvent", "default": "ToolCallExecutionEvent", "title": "Type", "type": "string" } }, "$defs": { "FunctionExecutionResult": { "description": "Function execution result contains the output of a function call.", "properties": { "content": { "title": "Content", "type": "string" }, "name": { "title": "Name", "type": "string" }, "call_id": { "title": "Call Id", "type": "string" }, "is_error": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "title": "Is Error" } }, "required": [ "content", "name", "call_id" ], "title": "FunctionExecutionResult", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- Fields:
- field content: List[FunctionExecutionResult] [Required]#
The tool call results.
- pydantic model ToolCallRequestEvent[source]#
Bases:
BaseAgentEvent
An event signaling a request to use tools.
Show JSON schema
{ "title": "ToolCallRequestEvent", "description": "An event signaling a request to use tools.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "$ref": "#/$defs/FunctionCall" }, "title": "Content", "type": "array" }, "type": { "const": "ToolCallRequestEvent", "default": "ToolCallRequestEvent", "title": "Type", "type": "string" } }, "$defs": { "FunctionCall": { "properties": { "id": { "title": "Id", "type": "string" }, "arguments": { "title": "Arguments", "type": "string" }, "name": { "title": "Name", "type": "string" } }, "required": [ "id", "arguments", "name" ], "title": "FunctionCall", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- field content: List[FunctionCall] [Required]#
The tool calls.
- pydantic model ToolCallSummaryMessage[source]#
Bases:
BaseChatMessage
A message signaling the summary of tool call results.
Show JSON schema
{ "title": "ToolCallSummaryMessage", "description": "A message signaling the summary of tool call results.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "ToolCallSummaryMessage", "default": "ToolCallSummaryMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model UserInputRequestedEvent[source]#
Bases:
BaseAgentEvent
An event signaling a that the user proxy has requested user input. Published prior to invoking the input callback.
Show JSON schema
{ "title": "UserInputRequestedEvent", "description": "An event signaling a that the user proxy has requested user input. Published prior to invoking the input callback.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "request_id": { "title": "Request Id", "type": "string" }, "content": { "const": "", "default": "", "title": "Content", "type": "string" }, "type": { "const": "UserInputRequestedEvent", "default": "UserInputRequestedEvent", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "request_id" ] }