autogen_agentchat.messages#

此模块定义了用于代理间通信的各种消息类型。每种消息类型都继承自 BaseChatMessage 类或 BaseAgentEvent 类,并包含与所发送消息类型相关的特定字段。

AgentEvent#

BaseAgentEvent 所有内置具体子类的联合类型。

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

pydantic 模型 BaseMessage[source]#

基类:BaseModel, ABC

AgentChat 中所有消息类型的抽象基类。

警告

如果您想创建新的消息类型,请不要继承此类。相反,请继承 BaseChatMessageBaseAgentEvent 以阐明消息类型的目的。

显示 JSON 模式
{
   "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": {}
}

抽象 to_text() str[source]#

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

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

将消息转换为 JSON 可序列化字典。

默认实现使用 Pydantic 模型的 model_dump() 方法将消息转换为字典。Datetime 对象会自动转换为 ISO 格式字符串以确保 JSON 序列化兼容性。如果您想自定义序列化过程或向输出添加额外字段,请覆盖此方法。

类方法 load(data: Mapping[str, Any]) Self[source]#

从 JSON 可序列化数据的字典创建消息。

默认实现使用 Pydantic 模型的 model_validate() 方法从数据创建消息。如果您想自定义反序列化过程或向输入数据添加额外字段,请覆盖此方法。

ChatMessage#

BaseChatMessage 所有内置具体子类的联合类型。它不包括 StructuredMessage 类型。

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

pydantic 模型 BaseChatMessage[source]#

基类:BaseMessage, ABC

聊天消息的抽象基类。

注意

如果您想创建用于代理间通信的新消息类型,请继承此类;如果您的内容类型是 Pydantic BaseModel 的子类,则直接使用 StructuredMessage

此类用于在聊天对话中代理之间发送的消息。代理应使用模型处理消息内容,并返回另一个 BaseChatMessage 作为响应。

显示 JSON 模式
{
   "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": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "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"
   ]
}

字段:
字段 id: str [可选]#

此消息的唯一标识符。

字段 source: str [必填]#

发送此消息的代理名称。

字段 models_usage: RequestUsage | None = None#

生成此消息时产生的模型客户端使用情况。

字段 metadata: Dict[str, str] = {}#

有关消息的其他元数据。

字段 created_at: datetime [可选]#

消息创建的时间。

抽象 to_model_text() str[source]#

将消息内容转换为纯文本表示形式。这用于为模型创建纯文本内容。

这不用于在控制台中渲染消息。为此,请使用 to_text()

此方法与 to_model_message() 的区别在于,此方法用于为模型客户端构建消息的一部分,而 to_model_message() 用于为模型客户端创建完整消息。

抽象 to_model_message() UserMessage[source]#

将消息内容转换为 UserMessage,以便与模型客户端(例如 ChatCompletionClient)一起使用。

pydantic 模型 BaseAgentEvent[source]#

基类:BaseMessage, ABC

代理事件的基类。

注意

如果您想创建用于向用户和应用程序发出可观察事件信号的新消息类型,请继承此类。

代理事件用于向用户和应用程序发出代理和团队生成的动作和思想信号。它们不用于代理间通信,也不期望由其他代理处理。

如果您想提供内容的自定义渲染,应覆盖 to_text() 方法。

显示 JSON 模式
{
   "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": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "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"
   ]
}

字段:
字段 id: str [可选]#

此事件的唯一标识符。

字段 source: str [必填]#

发送此消息的代理名称。

字段 models_usage: RequestUsage | None = None#

生成此消息时产生的模型客户端使用情况。

字段 metadata: Dict[str, str] = {}#

有关消息的其他元数据。

字段 created_at: datetime [可选]#

消息创建的时间。

pydantic 模型 BaseTextChatMessage[source]#

基类:BaseChatMessage, ABC

所有纯文本 BaseChatMessage 类型的基类。它实现了 to_text()to_model_text()to_model_message() 方法。

如果您的消息内容类型是字符串,请继承此类。

显示 JSON 模式
{
   "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": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: str [必填]#

消息内容。

to_text() str[source]#

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

to_model_text() str[source]#

将消息内容转换为纯文本表示形式。这用于为模型创建纯文本内容。

这不用于在控制台中渲染消息。为此,请使用 to_text()

此方法与 to_model_message() 的区别在于,此方法用于为模型客户端构建消息的一部分,而 to_model_message() 用于为模型客户端创建完整消息。

to_model_message() UserMessage[source]#

将消息内容转换为 UserMessage,以便与模型客户端(例如 ChatCompletionClient)一起使用。

StructuredContentType#

结构化内容类型的类型变量。

别名 TypeVar(‘StructuredContentType’, bound=BaseModel, covariant=True)

pydantic 模型 StructuredMessage[source]#

基类:BaseChatMessage, Generic[StructuredContentType]

一种具有未指定内容类型的 BaseChatMessage 类型。

要创建新的结构化消息类型,请将内容类型指定为 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!

显示 JSON 模式
{
   "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.org.cn/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": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: StructuredContentType [必填]#

消息内容。必须是 Pydantic BaseModel 的子类。

字段 format_string: str | None = None#

(实验性)一个可选的格式字符串,用于将内容渲染为人类可读的格式。格式字符串可以使用内容模型的字段作为占位符。例如,如果内容模型有一个字段 name,您可以在格式字符串中使用 {name} 来包含该字段的值。格式字符串在 to_text() 方法中用于创建消息的人类可读表示。此设置是实验性的,将来可能会更改。

属性 type: str#
to_text() str[source]#

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

to_model_text() str[source]#

将消息内容转换为纯文本表示形式。这用于为模型创建纯文本内容。

这不用于在控制台中渲染消息。为此,请使用 to_text()

此方法与 to_model_message() 的区别在于,此方法用于为模型客户端构建消息的一部分,而 to_model_message() 用于为模型客户端创建完整消息。

to_model_message() UserMessage[source]#

将消息内容转换为 UserMessage,以便与模型客户端(例如 ChatCompletionClient)一起使用。

pydantic 模型 HandoffMessage[source]#

基类:BaseTextChatMessage

请求将对话移交给另一个代理的消息。

显示 JSON 模式
{
   "title": "HandoffMessage",
   "description": "A message requesting handoff of a conversation to another agent.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 target: str [必填]#

要移交到的目标代理的名称。

字段 context: List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] = []#

传递给目标代理的模型上下文。

字段 type: Literal['HandoffMessage'] = 'HandoffMessage'#
pydantic 模型 MultiModalMessage[source]#

基类:BaseChatMessage

多模态消息。

显示 JSON 模式
{
   "title": "MultiModalMessage",
   "description": "A multimodal message.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: List[str | Image] [必填]#

消息内容。

字段 type: Literal['MultiModalMessage'] = 'MultiModalMessage'#
to_model_text(image_placeholder: str | None = '[image]') str#

将消息内容转换为纯字符串表示形式。如果存在图像,默认情况下会将其替换为图像占位符,否则在设置为 None 时会是一个 base64 字符串。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

to_model_message() UserMessage[source]#

将消息内容转换为 UserMessage,以便与模型客户端(例如 ChatCompletionClient)一起使用。

pydantic 模型 StopMessage[source]#

基类:BaseTextChatMessage

请求停止对话的消息。

显示 JSON 模式
{
   "title": "StopMessage",
   "description": "A message requesting stop of a conversation.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 type: Literal['StopMessage'] = 'StopMessage'#
pydantic 模型 TextMessage[source]#

基类:BaseTextChatMessage

内容仅为字符串的文本消息。

显示 JSON 模式
{
   "title": "TextMessage",
   "description": "A text message with string-only content.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 type: Literal['TextMessage'] = 'TextMessage'#
pydantic 模型 ToolCallExecutionEvent[source]#

基类:BaseAgentEvent

表示工具调用执行的事件。

显示 JSON 模式
{
   "title": "ToolCallExecutionEvent",
   "description": "An event signaling the execution of tool calls.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: List[FunctionExecutionResult] [必填]#

工具调用结果。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 ToolCallRequestEvent[source]#

基类:BaseAgentEvent

表示请求使用工具的事件。

显示 JSON 模式
{
   "title": "ToolCallRequestEvent",
   "description": "An event signaling a request to use tools.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: List[FunctionCall] [必填]#

工具调用。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 ToolCallSummaryMessage[source]#

基类:BaseTextChatMessage

表示工具调用结果摘要的消息。

显示 JSON 模式
{
   "title": "ToolCallSummaryMessage",
   "description": "A message signaling the summary of tool call results.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "content": {
         "title": "Content",
         "type": "string"
      },
      "type": {
         "const": "ToolCallSummaryMessage",
         "default": "ToolCallSummaryMessage",
         "title": "Type",
         "type": "string"
      },
      "tool_calls": {
         "items": {
            "$ref": "#/$defs/FunctionCall"
         },
         "title": "Tool Calls",
         "type": "array"
      },
      "results": {
         "items": {
            "$ref": "#/$defs/FunctionExecutionResult"
         },
         "title": "Results",
         "type": "array"
      }
   },
   "$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"
      },
      "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",
      "tool_calls",
      "results"
   ]
}

字段:
字段 type: Literal['ToolCallSummaryMessage'] = 'ToolCallSummaryMessage'#
字段 tool_calls: List[FunctionCall] [必填]#

已进行的工具调用。

字段 results: List[FunctionExecutionResult] [必填]#

工具调用的结果。

pydantic 模型 MemoryQueryEvent[source]#

基类:BaseAgentEvent

表示内存查询结果的事件。

显示 JSON 模式
{
   "title": "MemoryQueryEvent",
   "description": "An event signaling the results of memory queries.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: List[MemoryContent] [必填]#

内存查询结果。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 UserInputRequestedEvent[source]#

基类:BaseAgentEvent

表示用户代理已请求用户输入的事件。在调用输入回调之前发布。

显示 JSON 模式
{
   "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": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 request_id: str [必填]#

用户输入请求的标识符。

字段 content: Literal[''] = ''#

与消费者期望的内容字段兼容的空内容。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 ModelClientStreamingChunkEvent[source]#

基类:BaseAgentEvent

表示模型客户端在流模式下输出文本块的事件。

显示 JSON 模式
{
   "title": "ModelClientStreamingChunkEvent",
   "description": "An event signaling a text output chunk from a model client in streaming mode.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "content": {
         "title": "Content",
         "type": "string"
      },
      "full_message_id": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Full Message Id"
      },
      "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"
   ]
}

字段:
字段 content: str [必填]#

模型客户端的字符串块。

字段 full_message_id: str | None = None#

对可能在块之后出现的完整消息的可选引用。这允许流的消费者将块与最终完成的消息相关联。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 ThoughtEvent[source]#

基类:BaseAgentEvent

表示模型思维过程的事件。它用于传达推理模型生成的推理令牌,或函数调用生成的额外文本内容。

显示 JSON 模式
{
   "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": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: str [必填]#

模型的思维过程。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 SelectSpeakerEvent[source]#

基类:BaseAgentEvent

表示对话发言人选择的事件。

显示 JSON 模式
{
   "title": "SelectSpeakerEvent",
   "description": "An event signaling the selection of speakers for a conversation.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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"
   ]
}

字段:
字段 content: List[str] [必填]#

所选发言人的姓名。

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 CodeGenerationEvent[source]#

基类:BaseAgentEvent

表示代码生成事件。

显示 JSON 模式
{
   "title": "CodeGenerationEvent",
   "description": "An event signaling code generation event.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "retry_attempt": {
         "title": "Retry Attempt",
         "type": "integer"
      },
      "content": {
         "title": "Content",
         "type": "string"
      },
      "code_blocks": {
         "items": {
            "$ref": "#/$defs/CodeBlock"
         },
         "title": "Code Blocks",
         "type": "array"
      },
      "type": {
         "const": "CodeGenerationEvent",
         "default": "CodeGenerationEvent",
         "title": "Type",
         "type": "string"
      }
   },
   "$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",
      "retry_attempt",
      "content",
      "code_blocks"
   ]
}

字段:
字段 retry_attempt: int [必填]#

重试次数,0 表示首次生成

字段 content: str [必填]#

完整的字符串内容。

字段 code_blocks: List[CodeBlock] [必填]#

内容中存在的代码块列表

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

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()

pydantic 模型 CodeExecutionEvent[source]#

基类:BaseAgentEvent

表示代码执行事件。

显示 JSON 模式
{
   "title": "CodeExecutionEvent",
   "description": "An event signaling code execution event.",
   "type": "object",
   "properties": {
      "id": {
         "title": "Id",
         "type": "string"
      },
      "source": {
         "title": "Source",
         "type": "string"
      },
      "models_usage": {
         "anyOf": [
            {
               "$ref": "#/$defs/RequestUsage"
            },
            {
               "type": "null"
            }
         ],
         "default": null
      },
      "metadata": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Metadata",
         "type": "object"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "retry_attempt": {
         "title": "Retry Attempt",
         "type": "integer"
      },
      "result": {
         "$ref": "#/$defs/CodeResult"
      },
      "type": {
         "const": "CodeExecutionEvent",
         "default": "CodeExecutionEvent",
         "title": "Type",
         "type": "string"
      }
   },
   "$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",
      "retry_attempt",
      "result"
   ]
}

字段:
字段 retry_attempt: int [必填]#

重试次数,0 表示首次执行

字段 result: CodeResult [必填]#

代码执行结果

字段 type: Literal['CodeExecutionEvent'] = 'CodeExecutionEvent'#
to_text() str[源代码]#

将消息内容转换为纯字符串表示形式,以便在控制台中渲染并由用户或条件检查。这不用于为模型创建纯文本内容。对于 BaseChatMessage 类型,请改用 to_model_text()