autogen_core.tool_agent#

exception InvalidToolArgumentsException(call_id: str, content: str, name: str)[来源]#

基类:ToolException

class ToolAgent(description: str, tools: List[Tool])[来源]#

基类:RoutedAgent

工具代理接受 FunctionCall 类型的直接消息,使用提供的参数执行请求的工具,并将结果作为 FunctionExecutionResult 消息返回。

参数:
  • description (str) – 代理的描述。

  • tools (List[Tool]) – 代理可以执行的工具列表。

async handle_function_call(message: FunctionCall, ctx: MessageContext) FunctionExecutionResult[来源]#

通过使用提供的参数执行请求的工具来处理 FunctionCall 消息。

参数:
返回:

FunctionExecutionResult – 函数执行的结果。

引发:
property tools: List[Tool]#
exception ToolException(call_id: str, content: str, name: str)[来源]#

基类:BaseException

call_id: str#
content: str#
name: str#
异常 ToolExecutionException(call_id: str, content: str, name: str)[源代码]#

基类:ToolException

异常 ToolNotFoundException(call_id: str, content: str, name: str)[源代码]#

基类:ToolException

async tool_agent_caller_loop(caller: BaseAgent | AgentRuntime, tool_agent_id: AgentId, model_client: ChatCompletionClient, input_messages: List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], tool_schema: List[ToolSchema] | List[Tool], cancellation_token: CancellationToken | None = None, caller_source: str = 'assistant') List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]][源代码]#

为工具代理启动一个调用循环。此函数以交替方式将消息发送到工具代理和模型客户端,直到模型客户端停止生成工具调用。

参数:
  • tool_agent_id (AgentId) – 工具代理的代理 ID。

  • input_messages (List[LLMMessage]) – 输入消息的列表。

  • model_client (ChatCompletionClient) – 用于模型 API 的模型客户端。

  • tool_schema (List[Tool | ToolSchema]) – 模型可以使用的工具列表。

返回:

List[LLMMessage] – 在调用循环中创建的输出消息的列表。