autogen_core.tool_agent#

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

基类:RoutedAgent

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

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

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

property tools: List[Tool]#
async handle_function_call(message: FunctionCall, ctx: MessageContext) FunctionExecutionResult[源代码]#

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

参数:
返回:

FunctionExecutionResult – 函数执行的结果。

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

基类:BaseException

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

基类:ToolException

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

基类:ToolException

exception ToolExecutionException(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] – 在调用者循环中创建的输出消息列表。