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#

The union type of all built-in concrete subclasses of BaseAgentEvent.

alias of Annotated[ToolCallRequestEvent | ToolCallExecutionEvent | MemoryQueryEvent | UserInputRequestedEvent | ModelClientStreamingChunkEvent | ThoughtEvent | SelectSpeakerEvent | CodeGenerationEvent | CodeExecutionEvent, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]

pydantic model BaseAgentEvent[source]#

Bases: BaseMessage, ABC

Base class for agent events.

Note

If you want to create a new message type for signaling observable events to user and application, inherit from this class.

Agent events are used to signal actions and thoughts produced by agents and teams to user and applications. They are not used for agent-to-agent communication and are not expected to be processed by other agents.

You should override the to_text() method if you want to provide a custom rendering of the content.

Show JSON schema
{
   "title": "BaseAgentEvent",
   "description": "Base class for agent events.\n\n.. note::\n\n    If you want to create a new message type for signaling observable events\n    to user and application, inherit from this class.\n\nAgent events are used to signal actions and thoughts produced by agents\nand teams to user and applications. They are not used for agent-to-agent\ncommunication and are not expected to be processed by other agents.\n\nYou should override the :meth:`to_text` method if you want to provide\na custom rendering of the content.",
   "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 metadata: Dict[str, str] = {}#

Additional metadata about the message.

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.

pydantic model BaseChatMessage[source]#

Bases: BaseMessage, ABC

Abstract base class for chat messages.

Note

If you want to create a new message type that is used for agent-to-agent communication, inherit from this class, or simply use StructuredMessage if your content type is a subclass of Pydantic BaseModel.

This class is used for messages that are sent between agents in a chat conversation. Agents are expected to process the content of the message using models and return a response as another BaseChatMessage.

Show JSON schema
{
   "title": "BaseChatMessage",
   "description": "Abstract base class for chat messages.\n\n.. note::\n\n    If you want to create a new message type that is used for agent-to-agent\n    communication, inherit from this class, or simply use\n    :class:`StructuredMessage` if your content type is a subclass of\n    Pydantic BaseModel.\n\nThis class is used for messages that are sent between agents in a chat\nconversation. Agents are expected to process the content of the\nmessage using models and return a response as another :class:`BaseChatMessage`.",
   "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 metadata: Dict[str, str] = {}#

Additional metadata about the message.

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.

abstract to_model_message() UserMessage[source]#

Convert the message content to a UserMessage for use with model client, e.g., ChatCompletionClient.

abstract to_model_text() str[source]#

Convert the content of the message to text-only representation. This is used for creating text-only content for models.

This is not used for rendering the message in console. For that, use to_text().

The difference between this and to_model_message() is that this is used to construct parts of the a message for the model client, while to_model_message() is used to create a complete message for the model client.

pydantic model BaseMessage[source]#

Bases: BaseModel, ABC

Abstract base class for all message types in AgentChat.

Warning

If you want to create a new message type, do not inherit from this class. Instead, inherit from BaseChatMessage or BaseAgentEvent to clarify the purpose of the message type.

Show JSON schema
{
   "title": "BaseMessage",
   "description": "Abstract base class for all message types in AgentChat.\n\n.. warning::\n\n    If you want to create a new message type, do not inherit from this class.\n    Instead, inherit from :class:`BaseChatMessage` or :class:`BaseAgentEvent`\n    to clarify the purpose of the message type.",
   "type": "object",
   "properties": {}
}

dump() Mapping[str, Any][source]#

Convert the message to a JSON-serializable dictionary.

The default implementation uses the Pydantic model’s model_dump() method to convert the message to a dictionary. Override this method if you want to customize the serialization process or add additional fields to the output.

classmethod load(data: Mapping[str, Any]) Self[source]#

Create a message from a dictionary of JSON-serializable data.

The default implementation uses the Pydantic model’s model_validate() method to create the message from the data. Override this method if you want to customize the deserialization process or add additional fields to the input data.

abstract to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

pydantic model BaseTextChatMessage[source]#

Bases: BaseChatMessage, ABC

Base class for all text-only BaseChatMessage types. It has implementations for to_text(), to_model_text(), and to_model_message() methods.

Inherit from this class if your message content type is a string.

Show JSON schema
{
   "title": "BaseTextChatMessage",
   "description": "Base class for all text-only :class:`BaseChatMessage` types.\nIt has implementations for :meth:`to_text`, :meth:`to_model_text`,\nand :meth:`to_model_message` methods.\n\nInherit from this class if your message content type is a string.",
   "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"
      }
   },
   "$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.

to_model_message() UserMessage[source]#

Convert the message content to a UserMessage for use with model client, e.g., ChatCompletionClient.

to_model_text() str[source]#

Convert the content of the message to text-only representation. This is used for creating text-only content for models.

This is not used for rendering the message in console. For that, use to_text().

The difference between this and to_model_message() is that this is used to construct parts of the a message for the model client, while to_model_message() is used to create a complete message for the model client.

to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

ChatMessage#

The union type of all built-in concrete subclasses of BaseChatMessage. It does not include StructuredMessage types.

alias of Annotated[TextMessage | MultiModalMessage | StopMessage | ToolCallSummaryMessage | HandoffMessage, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]

pydantic model CodeExecutionEvent[source]#

Bases: BaseAgentEvent

Show JSON schema
{
   "title": "CodeExecutionEvent",
   "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"
      },
      "type": {
         "const": "CodeExecutionEvent",
         "default": "CodeExecutionEvent",
         "title": "Type",
         "type": "string"
      },
      "result": {
         "$ref": "#/$defs/CodeResult"
      }
   },
   "$defs": {
      "CodeResult": {
         "properties": {
            "exit_code": {
               "title": "Exit Code",
               "type": "integer"
            },
            "output": {
               "title": "Output",
               "type": "string"
            }
         },
         "required": [
            "exit_code",
            "output"
         ],
         "title": "CodeResult",
         "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",
      "result"
   ]
}

Fields:
field result: CodeResult [Required]#
field type: Literal['CodeExecutionEvent'] = 'CodeExecutionEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

pydantic model CodeGenerationEvent[source]#

Bases: BaseAgentEvent

An event signaling code generation for execution.

Show JSON schema
{
   "title": "CodeGenerationEvent",
   "description": "An event signaling code generation for execution.",
   "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": "CodeGenerationEvent",
         "default": "CodeGenerationEvent",
         "title": "Type",
         "type": "string"
      },
      "code_blocks": {
         "items": {
            "$ref": "#/$defs/CodeBlock"
         },
         "title": "Code Blocks",
         "type": "array"
      }
   },
   "$defs": {
      "CodeBlock": {
         "properties": {
            "code": {
               "title": "Code",
               "type": "string"
            },
            "language": {
               "title": "Language",
               "type": "string"
            }
         },
         "required": [
            "code",
            "language"
         ],
         "title": "CodeBlock",
         "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",
      "code_blocks"
   ]
}

Fields:
field code_blocks: List[CodeBlock] [Required]#
field content: str [Required]#

The complete content as string.

field type: Literal['CodeGenerationEvent'] = 'CodeGenerationEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

pydantic model HandoffMessage[source]#

Bases: BaseTextChatMessage

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"
      },
      "content": {
         "title": "Content",
         "type": "string"
      },
      "target": {
         "title": "Target",
         "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",
      "content",
      "target"
   ]
}

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.

field target: str [Required]#

The name of the target agent to handoff to.

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

field type: Literal['MemoryQueryEvent'] = 'MemoryQueryEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

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"
   ]
}

Fields:
field content: str [Required]#

A string chunk from the model client.

field type: Literal['ModelClientStreamingChunkEvent'] = 'ModelClientStreamingChunkEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

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"
   ]
}

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

The content of the message.

field type: Literal['MultiModalMessage'] = 'MultiModalMessage'#
to_model_message() UserMessage[source]#

Convert the message content to a UserMessage for use with model client, e.g., ChatCompletionClient.

to_model_text(image_placeholder: str | None = '[image]') str[source]#

Convert the content of the message to a string-only representation. If an image is present, it will be replaced with the image placeholder by default, otherwise it will be a base64 string when set to None.

to_text(iterm: bool = False) str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

pydantic model SelectSpeakerEvent[source]#

Bases: BaseAgentEvent

An event signaling the selection of speakers for a conversation.

Show JSON schema
{
   "title": "SelectSpeakerEvent",
   "description": "An event signaling the selection of speakers for 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": {
         "items": {
            "type": "string"
         },
         "title": "Content",
         "type": "array"
      },
      "type": {
         "const": "SelectSpeakerEvent",
         "default": "SelectSpeakerEvent",
         "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] [Required]#

The names of the selected speakers.

field type: Literal['SelectSpeakerEvent'] = 'SelectSpeakerEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

pydantic model StopMessage[source]#

Bases: BaseTextChatMessage

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"
   ]
}

Fields:
field type: Literal['StopMessage'] = 'StopMessage'#
class StructuredContentType#

Type variable for structured content types.

alias of TypeVar(‘StructuredContentType’, bound=BaseModel, covariant=True)

pydantic model StructuredMessage[source]#

Bases: BaseChatMessage, Generic[StructuredContentType]

A BaseChatMessage type with an unspecified content type.

To create a new structured message type, specify the content type as a subclass of Pydantic BaseModel.

from pydantic import BaseModel
from autogen_agentchat.messages import StructuredMessage


class MyMessageContent(BaseModel):
    text: str
    number: int


message = StructuredMessage[MyMessageContent](
    content=MyMessageContent(text="Hello", number=42),
    source="agent1",
)

print(message.to_text())  # {"text": "Hello", "number": 42}
from pydantic import BaseModel
from autogen_agentchat.messages import StructuredMessage


class MyMessageContent(BaseModel):
    text: str
    number: int


message = StructuredMessage[MyMessageContent](
    content=MyMessageContent(text="Hello", number=42),
    source="agent",
    format_string="Hello, {text} {number}!",
)

print(message.to_text())  # Hello, agent 42!

Show JSON schema
{
   "title": "StructuredMessage",
   "description": "A :class:`BaseChatMessage` type with an unspecified content type.\n\nTo create a new structured message type, specify the content type\nas a subclass of `Pydantic BaseModel <https://docs.pydantic.dev/latest/concepts/models/>`_.\n\n.. code-block:: python\n\n    from pydantic import BaseModel\n    from autogen_agentchat.messages import StructuredMessage\n\n\n    class MyMessageContent(BaseModel):\n        text: str\n        number: int\n\n\n    message = StructuredMessage[MyMessageContent](\n        content=MyMessageContent(text=\"Hello\", number=42),\n        source=\"agent1\",\n    )\n\n    print(message.to_text())  # {\"text\": \"Hello\", \"number\": 42}\n\n.. code-block:: python\n\n    from pydantic import BaseModel\n    from autogen_agentchat.messages import StructuredMessage\n\n\n    class MyMessageContent(BaseModel):\n        text: str\n        number: int\n\n\n    message = StructuredMessage[MyMessageContent](\n        content=MyMessageContent(text=\"Hello\", number=42),\n        source=\"agent\",\n        format_string=\"Hello, {text} {number}!\",\n    )\n\n    print(message.to_text())  # Hello, agent 42!",
   "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": {
         "$ref": "#/$defs/BaseModel"
      },
      "format_string": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Format String"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "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: StructuredContentType [Required]#

The content of the message. Must be a subclass of Pydantic BaseModel.

field format_string: str | None = None#

(Experimental) An optional format string to render the content into a human-readable format. The format string can use the fields of the content model as placeholders. For example, if the content model has a field name, you can use {name} in the format string to include the value of that field. The format string is used in the to_text() method to create a human-readable representation of the message. This setting is experimental and will change in the future.

to_model_message() UserMessage[source]#

Convert the message content to a UserMessage for use with model client, e.g., ChatCompletionClient.

to_model_text() str[source]#

Convert the content of the message to text-only representation. This is used for creating text-only content for models.

This is not used for rendering the message in console. For that, use to_text().

The difference between this and to_model_message() is that this is used to construct parts of the a message for the model client, while to_model_message() is used to create a complete message for the model client.

to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

property type: str#
pydantic model TextMessage[source]#

Bases: BaseTextChatMessage

A text message with string-only content.

Show JSON schema
{
   "title": "TextMessage",
   "description": "A text message with string-only content.",
   "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"
   ]
}

Fields:
field type: Literal['TextMessage'] = 'TextMessage'#
pydantic model ThoughtEvent[source]#

Bases: BaseAgentEvent

An event signaling the thought process of a model. 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 a model.\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"
   ]
}

Fields:
field content: str [Required]#

The thought process of the model.

field type: Literal['ThoughtEvent'] = 'ThoughtEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

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.

field type: Literal['ToolCallExecutionEvent'] = 'ToolCallExecutionEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

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"
   ]
}

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

The tool calls.

field type: Literal['ToolCallRequestEvent'] = 'ToolCallRequestEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.

pydantic model ToolCallSummaryMessage[source]#

Bases: BaseTextChatMessage

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"
   ]
}

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

Fields:
field content: Literal[''] = ''#

Empty content for compat with consumers expecting a content field.

field request_id: str [Required]#

Identifier for the user input request.

field type: Literal['UserInputRequestedEvent'] = 'UserInputRequestedEvent'#
to_text() str[source]#

Convert the message content to a string-only representation that can be rendered in the console and inspected by the user or conditions. This is not used for creating text-only content for models. For BaseChatMessage types, use to_model_text() instead.