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 model BaseAgentEvent[源代码]#

基类:BaseMessage, ABC

代理事件的基础类。

备注

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

代理事件用于将代理和团队产生的动作与思考信号发送给用户和应用程序。 它们不用于代理间通信,也不期望被其他代理处理。

如果你想提供自定义的内容渲染方式,应该重写 to_text() 方法。

Show JSON schema
{
   "title": "BaseAgentEvent",
   "description": "\u4ee3\u7406\u4e8b\u4ef6\u7684\u57fa\u7840\u7c7b\u3002\n\n.. note::\n\n    \u5982\u679c\u4f60\u60f3\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6d88\u606f\u7c7b\u578b\u7528\u4e8e\u5411\u7528\u6237\u548c\u5e94\u7528\u7a0b\u5e8f\u53d1\u9001\u53ef\u89c2\u5bdf\u4e8b\u4ef6\u4fe1\u53f7\uff0c\n    \u8bf7\u7ee7\u627f\u8fd9\u4e2a\u7c7b\u3002\n\n\u4ee3\u7406\u4e8b\u4ef6\u7528\u4e8e\u5c06\u4ee3\u7406\u548c\u56e2\u961f\u4ea7\u751f\u7684\u52a8\u4f5c\u4e0e\u601d\u8003\u4fe1\u53f7\u53d1\u9001\u7ed9\u7528\u6237\u548c\u5e94\u7528\u7a0b\u5e8f\u3002\n\u5b83\u4eec\u4e0d\u7528\u4e8e\u4ee3\u7406\u95f4\u901a\u4fe1\uff0c\u4e5f\u4e0d\u671f\u671b\u88ab\u5176\u4ed6\u4ee3\u7406\u5904\u7406\u3002\n\n\u5982\u679c\u4f60\u60f3\u63d0\u4f9b\u81ea\u5b9a\u4e49\u7684\u5185\u5bb9\u6e32\u67d3\u65b9\u5f0f\uff0c\u5e94\u8be5\u91cd\u5199 :meth:`to_text` \u65b9\u6cd5\u3002",
   "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"
      },
      "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"
   ]
}

Fields:
field created_at: datetime [Optional]#

消息创建的时间。

field metadata: Dict[str, str] = {}#

关于消息的额外元数据。

field models_usage: RequestUsage | None = None#

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

field source: str [Required]#

发送此消息的代理名称。

pydantic model BaseChatMessage[源代码]#

基类:BaseMessage, ABC

聊天消息的抽象基类。

备注

如需创建用于智能体间通信的新消息类型,请继承此类, 或者当内容类型是 Pydantic BaseModel 的子类时, 直接使用 StructuredMessage

此类用于聊天对话中智能体之间传递的消息。 智能体应通过模型处理消息内容, 并返回另一个 BaseChatMessage 作为响应。

Show JSON schema
{
   "title": "BaseChatMessage",
   "description": "\u804a\u5929\u6d88\u606f\u7684\u62bd\u8c61\u57fa\u7c7b\u3002\n\n.. note::\n\n    \u5982\u9700\u521b\u5efa\u7528\u4e8e\u667a\u80fd\u4f53\u95f4\u901a\u4fe1\u7684\u65b0\u6d88\u606f\u7c7b\u578b\uff0c\u8bf7\u7ee7\u627f\u6b64\u7c7b\uff0c\n    \u6216\u8005\u5f53\u5185\u5bb9\u7c7b\u578b\u662f Pydantic BaseModel \u7684\u5b50\u7c7b\u65f6\uff0c\n    \u76f4\u63a5\u4f7f\u7528 :class:`StructuredMessage`\u3002\n\n\u6b64\u7c7b\u7528\u4e8e\u804a\u5929\u5bf9\u8bdd\u4e2d\u667a\u80fd\u4f53\u4e4b\u95f4\u4f20\u9012\u7684\u6d88\u606f\u3002\n\u667a\u80fd\u4f53\u5e94\u901a\u8fc7\u6a21\u578b\u5904\u7406\u6d88\u606f\u5185\u5bb9\uff0c\n\u5e76\u8fd4\u56de\u53e6\u4e00\u4e2a :class:`BaseChatMessage` \u4f5c\u4e3a\u54cd\u5e94\u3002",
   "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"
      },
      "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"
   ]
}

Fields:
field created_at: datetime [Optional]#

消息创建的时间。

field metadata: Dict[str, str] = {}#

关于此消息的附加元数据。

field models_usage: RequestUsage | None = None#

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

field source: str [Required]#

发送此消息的代理名称。

abstract to_model_message() UserMessage[源代码]#

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

abstract to_model_text() str[源代码]#

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

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

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

pydantic model BaseMessage[源代码]#

基类:BaseModel, ABC

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

警告

如需创建新的消息类型,请不要直接继承此类。 应继承 BaseChatMessageBaseAgentEvent 以明确消息类型的用途。

Show JSON schema
{
   "title": "BaseMessage",
   "description": "AgentChat \u4e2d\u6240\u6709\u6d88\u606f\u7c7b\u578b\u7684\u62bd\u8c61\u57fa\u7c7b\u3002\n\n.. warning::\n\n    \u5982\u9700\u521b\u5efa\u65b0\u7684\u6d88\u606f\u7c7b\u578b\uff0c\u8bf7\u4e0d\u8981\u76f4\u63a5\u7ee7\u627f\u6b64\u7c7b\u3002\n    \u5e94\u7ee7\u627f :class:`BaseChatMessage` \u6216 :class:`BaseAgentEvent`\n    \u4ee5\u660e\u786e\u6d88\u606f\u7c7b\u578b\u7684\u7528\u9014\u3002",
   "type": "object",
   "properties": {}
}

dump() Mapping[str, Any][源代码]#

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

默认实现使用Pydantic模型的 :meth:`model_dump`方法将消息转换为字典。 如需自定义序列化过程或向输出添加额外字段,请重写此方法。

classmethod load(data: Mapping[str, Any]) Self[源代码]#

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

默认实现使用Pydantic模型的 :meth:`model_validate`方法从数据创建消息。 如需自定义反序列化过程或向输入数据添加额外字段,请重写此方法。

abstract to_text() str[源代码]#

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

pydantic model BaseTextChatMessage[源代码]#

基类:BaseChatMessage, ABC

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

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

Show JSON schema
{
   "title": "BaseTextChatMessage",
   "description": "\u6240\u6709\u7eaf\u6587\u672c :class:`BaseChatMessage` \u7c7b\u578b\u7684\u57fa\u7c7b\u3002\n\u5b83\u5b9e\u73b0\u4e86 :meth:`to_text`\u3001:meth:`to_model_text`\n\u548c :meth:`to_model_message` \u65b9\u6cd5\u3002\n\n\u5982\u679c\u60a8\u7684\u6d88\u606f\u5185\u5bb9\u7c7b\u578b\u662f\u5b57\u7b26\u4e32\uff0c\u8bf7\u7ee7\u627f\u6b64\u7c7b\u3002",
   "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"
      },
      "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"
   ]
}

Fields:
field content: str [Required]#

消息的内容。

to_model_message() UserMessage[源代码]#

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

to_model_text() str[源代码]#

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

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

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

to_text() str[源代码]#

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

ChatMessage#

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

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

pydantic model CodeExecutionEvent[源代码]#

基类:BaseAgentEvent

表示代码执行事件的事件。

Show JSON schema
{
   "title": "CodeExecutionEvent",
   "description": "\u8868\u793a\u4ee3\u7801\u6267\u884c\u4e8b\u4ef6\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "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"
   ]
}

Fields:
field result: CodeResult [Required]#

Code Execution Result

field retry_attempt: int [Required]#

Retry number, 0 means first execution

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

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

pydantic model CodeGenerationEvent[源代码]#

基类:BaseAgentEvent

表示代码生成事件的事件。

Show JSON schema
{
   "title": "CodeGenerationEvent",
   "description": "\u8868\u793a\u4ee3\u7801\u751f\u6210\u4e8b\u4ef6\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "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"
   ]
}

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

List of code blocks present in content

field content: str [Required]#

The complete content as string.

field retry_attempt: int [Required]#

Retry number, 0 means first generation

field type: Literal['CodeGenerationEvent'] = 'CodeGenerationEvent'#
to_text() str[源代码]#

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

pydantic model HandoffMessage[源代码]#

基类:BaseTextChatMessage

请求将对话转交给其他代理的消息。

Show JSON schema
{
   "title": "HandoffMessage",
   "description": "\u8bf7\u6c42\u5c06\u5bf9\u8bdd\u8f6c\u4ea4\u7ed9\u5176\u4ed6\u4ee3\u7406\u7684\u6d88\u606f\u3002",
   "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"
      },
      "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": "\u52a9\u624b\u6d88\u606f\u662f\u4ece\u8bed\u8a00\u6a21\u578b\u4e2d\u91c7\u6837\u5f97\u5230\u7684\u3002",
         "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": "\u51fd\u6570\u6267\u884c\u7ed3\u679c\u5305\u542b\u51fd\u6570\u8c03\u7528\u7684\u8f93\u51fa\u3002",
         "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": "\u51fd\u6570\u6267\u884c\u7ed3\u679c\u6d88\u606f\u5305\u542b\u591a\u4e2a\u51fd\u6570\u8c03\u7528\u7684\u8f93\u51fa\u3002",
         "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": "\u7cfb\u7edf\u6d88\u606f\u5305\u542b\u6765\u81ea\u5f00\u53d1\u8005\u7684\u6a21\u578b\u6307\u4ee4\u3002\n\n.. note::\n\n    OpenAI \u6b63\u9010\u6b65\u5f03\u7528 'system' \u89d2\u8272\uff0c\u8f6c\u800c\u4f7f\u7528 'developer' \u89d2\u8272\u3002\n    \u8be6\u60c5\u8bf7\u53c2\u9605 `Model Spec <https://cdn.openai.com/spec/model-spec-2024-05-08.html#definitions>`_\u3002\n    \u4e0d\u8fc7\uff0c\u5176 API \u4ecd\u5141\u8bb8\u4f7f\u7528 'system' \u89d2\u8272\uff0c\u670d\u52a1\u5668\u7aef\u4f1a\u81ea\u52a8\u5c06\u5176\u8f6c\u6362\u4e3a 'developer' \u89d2\u8272\n    \u56e0\u6b64\uff0c\u5f00\u53d1\u8005\u6d88\u606f\u53ef\u4ee5\u4f7f\u7528 `SystemMessage`\u3002",
         "properties": {
            "content": {
               "title": "Content",
               "type": "string"
            },
            "type": {
               "const": "SystemMessage",
               "default": "SystemMessage",
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "content"
         ],
         "title": "SystemMessage",
         "type": "object"
      },
      "UserMessage": {
         "description": "\u7528\u6237\u6d88\u606f\u5305\u542b\u7ec8\u7aef\u7528\u6237\u7684\u8f93\u5165\uff0c\u6216\u4f5c\u4e3a\u63d0\u4f9b\u7ed9\u6a21\u578b\u6570\u636e\u7684\u901a\u7528\u5bb9\u5668\u3002",
         "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')]] = []#

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

field target: str [Required]#

要交接的目标代理的名称。

field type: Literal['HandoffMessage'] = 'HandoffMessage'#
pydantic model MemoryQueryEvent[源代码]#

基类:BaseAgentEvent

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

Show JSON schema
{
   "title": "MemoryQueryEvent",
   "description": "\u8868\u793a\u5185\u5b58\u67e5\u8be2\u7ed3\u679c\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "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": "\u4e00\u4e2a\u5185\u5b58\u5185\u5bb9\u9879\u3002",
         "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": "\u652f\u6301\u7684\u5185\u5b58\u5185\u5bb9 MIME \u7c7b\u578b\u3002",
         "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]#

内存查询结果。

field type: Literal['MemoryQueryEvent'] = 'MemoryQueryEvent'#
to_text() str[源代码]#

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

pydantic model ModelClientStreamingChunkEvent[源代码]#

基类:BaseAgentEvent

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

Show JSON schema
{
   "title": "ModelClientStreamingChunkEvent",
   "description": "\u8868\u793a\u6a21\u578b\u5ba2\u6237\u7aef\u5728\u6d41\u6a21\u5f0f\u4e0b\u8f93\u51fa\u7684\u6587\u672c\u5757\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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]#

来自模型客户端的字符串片段。

field type: Literal['ModelClientStreamingChunkEvent'] = 'ModelClientStreamingChunkEvent'#
to_text() str[源代码]#

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

pydantic model MultiModalMessage[源代码]#

基类:BaseChatMessage

多模态消息。

Show JSON schema
{
   "title": "MultiModalMessage",
   "description": "\u591a\u6a21\u6001\u6d88\u606f\u3002",
   "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"
      },
      "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"
   ]
}

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

消息的内容。

field type: Literal['MultiModalMessage'] = 'MultiModalMessage'#
to_model_message() UserMessage[源代码]#

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

to_model_text(image_placeholder: str | None = '[image]') str[源代码]#

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

to_text(iterm: bool = False) str[源代码]#

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

pydantic model SelectSpeakerEvent[源代码]#

基类:BaseAgentEvent

表示已为对话选择发言者的事件。

Show JSON schema
{
   "title": "SelectSpeakerEvent",
   "description": "\u8868\u793a\u5df2\u4e3a\u5bf9\u8bdd\u9009\u62e9\u53d1\u8a00\u8005\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "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"
   ]
}

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

所选发言者的名称。

field type: Literal['SelectSpeakerEvent'] = 'SelectSpeakerEvent'#
to_text() str[源代码]#

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

pydantic model StopMessage[源代码]#

基类:BaseTextChatMessage

请求停止对话的消息。

Show JSON schema
{
   "title": "StopMessage",
   "description": "\u8bf7\u6c42\u505c\u6b62\u5bf9\u8bdd\u7684\u6d88\u606f\u3002",
   "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"
      },
      "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"
   ]
}

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

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

TypeVar('StructuredContentType', bound=BaseModel, covariant=True) 的别名

pydantic model StructuredMessage[源代码]#

基类: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!

Show JSON schema
{
   "title": "StructuredMessage",
   "description": "\u4e00\u4e2a\u5185\u5bb9\u7c7b\u578b\u672a\u6307\u5b9a\u7684 :class:`BaseChatMessage` \u7c7b\u578b\u3002\n\n\u8981\u521b\u5efa\u65b0\u7684\u7ed3\u6784\u5316\u6d88\u606f\u7c7b\u578b\uff0c\u9700\u5c06\u5185\u5bb9\u7c7b\u578b\u6307\u5b9a\u4e3a\n`Pydantic BaseModel <https://docs.pydantic.dev/latest/concepts/models/>`_ \u7684\u5b50\u7c7b\u3002\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"
      },
      "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"
   ]
}

Fields:
field content: StructuredContentType [Required]#

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

field format_string: str | None = None#

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

to_model_message() UserMessage[源代码]#

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

to_model_text() str[源代码]#

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

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

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

to_text() str[源代码]#

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

property type: str#
pydantic model TextMessage[源代码]#

基类:BaseTextChatMessage

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

Show JSON schema
{
   "title": "TextMessage",
   "description": "\u4ec5\u5305\u542b\u5b57\u7b26\u4e32\u5185\u5bb9\u7684\u6587\u672c\u6d88\u606f\u3002",
   "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"
      },
      "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"
   ]
}

Fields:
field type: Literal['TextMessage'] = 'TextMessage'#
pydantic model ThoughtEvent[源代码]#

基类:BaseAgentEvent

表示模型思考过程的事件。 用于传递推理模型生成的推理标记, 或函数调用生成的额外文本内容。

Show JSON schema
{
   "title": "ThoughtEvent",
   "description": "\u8868\u793a\u6a21\u578b\u601d\u8003\u8fc7\u7a0b\u7684\u4e8b\u4ef6\u3002\n\u7528\u4e8e\u4f20\u9012\u63a8\u7406\u6a21\u578b\u751f\u6210\u7684\u63a8\u7406\u6807\u8bb0\uff0c\n\u6216\u51fd\u6570\u8c03\u7528\u751f\u6210\u7684\u989d\u5916\u6587\u672c\u5185\u5bb9\u3002",
   "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"
      },
      "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"
   ]
}

Fields:
field content: str [Required]#

模型的思考过程。

field type: Literal['ThoughtEvent'] = 'ThoughtEvent'#
to_text() str[源代码]#

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

pydantic model ToolCallExecutionEvent[源代码]#

基类:BaseAgentEvent

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

Show JSON schema
{
   "title": "ToolCallExecutionEvent",
   "description": "\u8868\u793a\u5de5\u5177\u8c03\u7528\u6267\u884c\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "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": "\u51fd\u6570\u6267\u884c\u7ed3\u679c\u5305\u542b\u51fd\u6570\u8c03\u7528\u7684\u8f93\u51fa\u3002",
         "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]#

工具调用的结果。

field type: Literal['ToolCallExecutionEvent'] = 'ToolCallExecutionEvent'#
to_text() str[源代码]#

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

pydantic model ToolCallRequestEvent[源代码]#

基类:BaseAgentEvent

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

Show JSON schema
{
   "title": "ToolCallRequestEvent",
   "description": "\u8868\u793a\u8bf7\u6c42\u4f7f\u7528\u5de5\u5177\u7684\u4e8b\u4ef6\u3002",
   "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"
      },
      "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"
   ]
}

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

工具调用。

field type: Literal['ToolCallRequestEvent'] = 'ToolCallRequestEvent'#
to_text() str[源代码]#

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

pydantic model ToolCallSummaryMessage[源代码]#

基类:BaseTextChatMessage

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

Show JSON schema
{
   "title": "ToolCallSummaryMessage",
   "description": "\u8868\u793a\u5de5\u5177\u8c03\u7528\u7ed3\u679c\u6458\u8981\u7684\u6d88\u606f\u3002",
   "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"
      },
      "created_at": {
         "format": "date-time",
         "title": "Created At",
         "type": "string"
      },
      "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[源代码]#

基类:BaseAgentEvent

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

Show JSON schema
{
   "title": "UserInputRequestedEvent",
   "description": "\u8868\u793a\u7528\u6237\u4ee3\u7406\u5df2\u8bf7\u6c42\u7528\u6237\u8f93\u5165\u7684\u4e8b\u4ef6\u4fe1\u53f7\u3002\u5728\u8c03\u7528\u8f93\u5165\u56de\u8c03\u4e4b\u524d\u53d1\u5e03\u3002",
   "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"
      },
      "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"
   ]
}

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

为兼容期望内容字段的消费者而设的空内容。

field request_id: str [Required]#

用户输入请求的标识符。

field type: Literal['UserInputRequestedEvent'] = 'UserInputRequestedEvent'#
to_text() str[源代码]#

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