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 消息,使用提供的参数执行请求的工具。

参数:
Returns:

FunctionExecutionResult -- 函数执行结果。

抛出:
property tools: List[Tool]#
exception ToolException(call_id: str, content: str, name: str)[源代码]#

基类:BaseException

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

基类:ToolException

exception 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]) -- 模型可以使用的工具列表。

Returns:

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