autogen_agentchat.messages#
该模块定义了用于代理间通信的各种消息类型。 每种消息类型都继承自BaseChatMessage类或BaseAgentEvent类,并包括与发送的消息类型相关的特定字段。
- AgentEvent#
当代理和团队工作时发出的事件,不用于代理之间的通信。
Annotated
的别名,[ToolCallRequestEvent
|ToolCallExecutionEvent
|MemoryQueryEvent
|UserInputRequestedEvent
|ModelClientStreamingChunkEvent
|ThoughtEvent
, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]
- pydantic model BaseMessage[源代码]#
基础类:
BaseModel
,ABC
所有消息类型的基类。
Show JSON schema
{ "title": "BaseMessage", "description": "Base class for all message types.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source" ] }
- Fields:
- field models_usage: RequestUsage | 无 = None#
生成此消息时产生的模型客户端使用情况。
- ChatMessage#
仅用于代理间通信的消息。
alias of
Annotated
[TextMessage
|MultiModalMessage
|StopMessage
|ToolCallSummaryMessage
|HandoffMessage
, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]
- pydantic model HandoffMessage[源代码]#
基础:
BaseChatMessage
一条请求将对话转交给另一代理的消息。
Show JSON schema
{ "title": "HandoffMessage", "description": "A message requesting handoff of a conversation to another agent.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "target": { "title": "Target", "type": "string" }, "content": { "title": "Content", "type": "string" }, "context": { "default": [], "items": { "discriminator": { "mapping": { "AssistantMessage": "#/$defs/AssistantMessage", "FunctionExecutionResultMessage": "#/$defs/FunctionExecutionResultMessage", "SystemMessage": "#/$defs/SystemMessage", "UserMessage": "#/$defs/UserMessage" }, "propertyName": "type" }, "oneOf": [ { "$ref": "#/$defs/SystemMessage" }, { "$ref": "#/$defs/UserMessage" }, { "$ref": "#/$defs/AssistantMessage" }, { "$ref": "#/$defs/FunctionExecutionResultMessage" } ] }, "title": "Context", "type": "array" }, "type": { "const": "HandoffMessage", "default": "HandoffMessage", "title": "Type", "type": "string" } }, "$defs": { "AssistantMessage": { "description": "Assistant message are sampled from the language model.", "properties": { "content": { "anyOf": [ { "type": "string" }, { "items": { "$ref": "#/$defs/FunctionCall" }, "type": "array" } ], "title": "Content" }, "thought": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Thought" }, "source": { "title": "Source", "type": "string" }, "type": { "const": "AssistantMessage", "default": "AssistantMessage", "title": "Type", "type": "string" } }, "required": [ "content", "source" ], "title": "AssistantMessage", "type": "object" }, "FunctionCall": { "properties": { "id": { "title": "Id", "type": "string" }, "arguments": { "title": "Arguments", "type": "string" }, "name": { "title": "Name", "type": "string" } }, "required": [ "id", "arguments", "name" ], "title": "FunctionCall", "type": "object" }, "FunctionExecutionResult": { "description": "Function execution result contains the output of a function call.", "properties": { "content": { "title": "Content", "type": "string" }, "name": { "title": "Name", "type": "string" }, "call_id": { "title": "Call Id", "type": "string" }, "is_error": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "title": "Is Error" } }, "required": [ "content", "name", "call_id" ], "title": "FunctionExecutionResult", "type": "object" }, "FunctionExecutionResultMessage": { "description": "Function execution result message contains the output of multiple function calls.", "properties": { "content": { "items": { "$ref": "#/$defs/FunctionExecutionResult" }, "title": "Content", "type": "array" }, "type": { "const": "FunctionExecutionResultMessage", "default": "FunctionExecutionResultMessage", "title": "Type", "type": "string" } }, "required": [ "content" ], "title": "FunctionExecutionResultMessage", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" }, "SystemMessage": { "description": "System message contains instructions for the model coming from the developer.\n\n.. note::\n\n Open AI is moving away from using 'system' role in favor of 'developer' role.\n See `Model Spec <https://cdn.openai.com/spec/model-spec-2024-05-08.html#definitions>`_ for more details.\n However, the 'system' role is still allowed in their API and will be automatically converted to 'developer' role\n on the server side.\n So, you can use `SystemMessage` for developer messages.", "properties": { "content": { "title": "Content", "type": "string" }, "type": { "const": "SystemMessage", "default": "SystemMessage", "title": "Type", "type": "string" } }, "required": [ "content" ], "title": "SystemMessage", "type": "object" }, "UserMessage": { "description": "User message contains input from end users, or a catch-all for data provided to the model.", "properties": { "content": { "anyOf": [ { "type": "string" }, { "items": { "anyOf": [ { "type": "string" }, {} ] }, "type": "array" } ], "title": "Content" }, "source": { "title": "Source", "type": "string" }, "type": { "const": "UserMessage", "default": "UserMessage", "title": "Type", "type": "string" } }, "required": [ "content", "source" ], "title": "UserMessage", "type": "object" } }, "required": [ "source", "target", "content" ] }
- Fields:
- field context: 列表[已注解[系统消息 | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] = []#
传递给目标代理的模型上下文。
- pydantic model MemoryQueryEvent[源代码]#
基类:
BaseAgentEvent
一个表示内存查询结果的事件信号。
Show JSON schema
{ "title": "MemoryQueryEvent", "description": "An event signaling the results of memory queries.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "$ref": "#/$defs/MemoryContent" }, "title": "Content", "type": "array" }, "type": { "const": "MemoryQueryEvent", "default": "MemoryQueryEvent", "title": "Type", "type": "string" } }, "$defs": { "MemoryContent": { "description": "A memory content item.", "properties": { "content": { "anyOf": [ { "type": "string" }, { "format": "binary", "type": "string" }, { "type": "object" }, {} ], "title": "Content" }, "mime_type": { "anyOf": [ { "$ref": "#/$defs/MemoryMimeType" }, { "type": "string" } ], "title": "Mime Type" }, "metadata": { "anyOf": [ { "type": "object" }, { "type": "null" } ], "default": null, "title": "Metadata" } }, "required": [ "content", "mime_type" ], "title": "MemoryContent", "type": "object" }, "MemoryMimeType": { "description": "Supported MIME types for memory content.", "enum": [ "text/plain", "application/json", "text/markdown", "image/*", "application/octet-stream" ], "title": "MemoryMimeType", "type": "string" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- Fields:
- field content: 列表[MemoryContent] [Required]#
记忆查询结果。
- pydantic model ModelClientStreamingChunkEvent[源代码]#
基类:
BaseAgentEvent
一个事件,表示在流模式下从模型客户端输出的文本块。
Show JSON schema
{ "title": "ModelClientStreamingChunkEvent", "description": "An event signaling a text output chunk from a model client in streaming mode.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "ModelClientStreamingChunkEvent", "default": "ModelClientStreamingChunkEvent", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model MultiModalMessage[源代码]#
基础:
BaseChatMessage
一条多模态消息。
Show JSON schema
{ "title": "MultiModalMessage", "description": "A multimodal message.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "anyOf": [ { "type": "string" }, {} ] }, "title": "Content", "type": "array" }, "type": { "const": "MultiModalMessage", "default": "MultiModalMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model StopMessage[源代码]#
基础:
BaseChatMessage
请求停止对话的消息。
Show JSON schema
{ "title": "StopMessage", "description": "A message requesting stop of a conversation.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "StopMessage", "default": "StopMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model TextMessage[源代码]#
基础:
BaseChatMessage
一条文本消息。
Show JSON schema
{ "title": "TextMessage", "description": "A text message.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "TextMessage", "default": "TextMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model ThoughtEvent[源代码]#
基类:
BaseAgentEvent
一个信号表示代理思考过程的事件。 它用于传达由推理模型生成的推理令牌, 或由函数调用生成的额外文本内容。
Show JSON schema
{ "title": "ThoughtEvent", "description": "An event signaling the thought process of an agent.\nIt is used to communicate the reasoning tokens generated by a reasoning model,\nor the extra text content generated by a function call.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "ThoughtEvent", "default": "ThoughtEvent", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model ToolCallExecutionEvent[源代码]#
基类:
BaseAgentEvent
一个信号工具调用执行的事件。
Show JSON schema
{ "title": "ToolCallExecutionEvent", "description": "An event signaling the execution of tool calls.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "$ref": "#/$defs/FunctionExecutionResult" }, "title": "Content", "type": "array" }, "type": { "const": "ToolCallExecutionEvent", "default": "ToolCallExecutionEvent", "title": "Type", "type": "string" } }, "$defs": { "FunctionExecutionResult": { "description": "Function execution result contains the output of a function call.", "properties": { "content": { "title": "Content", "type": "string" }, "name": { "title": "Name", "type": "string" }, "call_id": { "title": "Call Id", "type": "string" }, "is_error": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "title": "Is Error" } }, "required": [ "content", "name", "call_id" ], "title": "FunctionExecutionResult", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- Fields:
- field content: 列表[FunctionExecutionResult] [Required]#
工具调用结果。
- pydantic model ToolCallRequestEvent[源代码]#
基类:
BaseAgentEvent
一个表示请求使用工具的事件。
Show JSON schema
{ "title": "ToolCallRequestEvent", "description": "An event signaling a request to use tools.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "items": { "$ref": "#/$defs/FunctionCall" }, "title": "Content", "type": "array" }, "type": { "const": "ToolCallRequestEvent", "default": "ToolCallRequestEvent", "title": "Type", "type": "string" } }, "$defs": { "FunctionCall": { "properties": { "id": { "title": "Id", "type": "string" }, "arguments": { "title": "Arguments", "type": "string" }, "name": { "title": "Name", "type": "string" } }, "required": [ "id", "arguments", "name" ], "title": "FunctionCall", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- field content: 列表[FunctionCall] [Required]#
- 工具调用。
- pydantic model ToolCallSummaryMessage[源代码]#
基础:
BaseChatMessage
一条消息,用于表示工具调用结果的摘要。
Show JSON schema
{ "title": "ToolCallSummaryMessage", "description": "A message signaling the summary of tool call results.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "content": { "title": "Content", "type": "string" }, "type": { "const": "ToolCallSummaryMessage", "default": "ToolCallSummaryMessage", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "content" ] }
- pydantic model UserInputRequestedEvent[源代码]#
基类:
BaseAgentEvent
一个信号事件,表示用户代理已请求用户输入。在调用输入回调之前发布。
Show JSON schema
{ "title": "UserInputRequestedEvent", "description": "An event signaling a that the user proxy has requested user input. Published prior to invoking the input callback.", "type": "object", "properties": { "source": { "title": "Source", "type": "string" }, "models_usage": { "anyOf": [ { "$ref": "#/$defs/RequestUsage" }, { "type": "null" } ], "default": null }, "metadata": { "additionalProperties": { "type": "string" }, "default": {}, "title": "Metadata", "type": "object" }, "request_id": { "title": "Request Id", "type": "string" }, "content": { "const": "", "default": "", "title": "Content", "type": "string" }, "type": { "const": "UserInputRequestedEvent", "default": "UserInputRequestedEvent", "title": "Type", "type": "string" } }, "$defs": { "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" } }, "required": [ "source", "request_id" ] }