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, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]

AgentMessage#

(Deprecated, will be removed in 0.4.0) All message and event types.

alias of Annotated[TextMessage | MultiModalMessage | StopMessage | HandoffMessage | ToolCallRequestEvent | ToolCallExecutionEvent | ToolCallSummaryMessage, 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
      }
   },
   "$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.

field source: str [Required]#

The name of the agent that sent 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
      },
      "target": {
         "title": "Target",
         "type": "string"
      },
      "content": {
         "title": "Content",
         "type": "string"
      },
      "type": {
         "const": "HandoffMessage",
         "default": "HandoffMessage",
         "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",
      "target",
      "content"
   ]
}

Fields:
field content: str [Required]#

The handoff message to the target agent.

field target: str [Required]#

The name of the target agent to handoff to.

field type: Literal['HandoffMessage'] = 'HandoffMessage'#
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
      },
      "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"
   ]
}

Fields:
field content: List[str | Image] [Required]#

The content of the message.

field type: Literal['MultiModalMessage'] = 'MultiModalMessage'#
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
      },
      "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"
   ]
}

Fields:
field content: str [Required]#

The content for the stop message.

field type: Literal['StopMessage'] = 'StopMessage'#
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
      },
      "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"
   ]
}

Fields:
field content: str [Required]#

The content of the message.

field type: Literal['TextMessage'] = 'TextMessage'#
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
      },
      "content": {
         "items": {
            "$ref": "#/$defs/FunctionExecutionResult"
         },
         "title": "Content",
         "type": "array"
      },
      "type": {
         "const": "ToolCallExecutionEvent",
         "default": "ToolCallExecutionEvent",
         "title": "Type",
         "type": "string"
      }
   },
   "$defs": {
      "FunctionExecutionResult": {
         "properties": {
            "content": {
               "title": "Content",
               "type": "string"
            },
            "call_id": {
               "title": "Call Id",
               "type": "string"
            }
         },
         "required": [
            "content",
            "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.

field type: Literal['ToolCallExecutionEvent'] = 'ToolCallExecutionEvent'#
pydantic model ToolCallMessage[source]#

Bases: BaseMessage

A message signaling the use of tools.

Show JSON schema
{
   "title": "ToolCallMessage",
   "description": "A message signaling the use of tools.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "content": {
         "items": {
            "$ref": "#/$defs/FunctionCall"
         },
         "title": "Content",
         "type": "array"
      },
      "type": {
         "const": "ToolCallMessage",
         "default": "ToolCallMessage",
         "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"
      }
   },
   "deprecated": true,
   "required": [
      "source",
      "content"
   ]
}

Fields:
field content: List[FunctionCall] [Required]#

The tool calls.

field type: Literal['ToolCallMessage'] = 'ToolCallMessage'#
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
      },
      "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"
   ]
}

Fields:
field content: List[FunctionCall] [Required]#

The tool calls.

field type: Literal['ToolCallRequestEvent'] = 'ToolCallRequestEvent'#
pydantic model ToolCallResultMessage[source]#

Bases: BaseMessage

A message signaling the results of tool calls.

Show JSON schema
{
   "title": "ToolCallResultMessage",
   "description": "A message signaling the results of tool calls.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "content": {
         "items": {
            "$ref": "#/$defs/FunctionExecutionResult"
         },
         "title": "Content",
         "type": "array"
      },
      "type": {
         "const": "ToolCallResultMessage",
         "default": "ToolCallResultMessage",
         "title": "Type",
         "type": "string"
      }
   },
   "$defs": {
      "FunctionExecutionResult": {
         "properties": {
            "content": {
               "title": "Content",
               "type": "string"
            },
            "call_id": {
               "title": "Call Id",
               "type": "string"
            }
         },
         "required": [
            "content",
            "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"
      }
   },
   "deprecated": true,
   "required": [
      "source",
      "content"
   ]
}

Fields:
field content: List[FunctionExecutionResult] [Required]#

The tool call results.

field type: Literal['ToolCallResultMessage'] = 'ToolCallResultMessage'#
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
      },
      "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"
   ]
}

Fields:
field content: str [Required]#

Summary of the the tool call results.

field type: Literal['ToolCallSummaryMessage'] = 'ToolCallSummaryMessage'#