autogen_core.components.tool_agent#

exception autogen_core.components.tool_agent.InvalidToolArgumentsException(call_id: str, content: str)[source]#

Bases: ToolException

class autogen_core.components.tool_agent.ToolAgent(description: str, tools: List[Tool])[source]#

Bases: RoutedAgent

A tool agent accepts direct messages of the type FunctionCall, executes the requested tool with the provided arguments, and returns the result as FunctionExecutionResult messages.

Parameters:
  • description (str) – The description of the agent.

  • tools (List[Tool]) – The list of tools that the agent can execute.

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

Handles a FunctionCall message by executing the requested tool with the provided arguments.

Parameters:
Returns:

FunctionExecutionResult – The result of the function execution.

Raises:
internal_extra_handles_types: ClassVar[List[Tuple[Type[Any], List[MessageSerializer[Any]]]]] = []#
internal_unbound_subscriptions_list: ClassVar[List[UnboundSubscription]] = []#
property tools: List[Tool]#
exception autogen_core.components.tool_agent.ToolException(call_id: str, content: str)[source]#

Bases: BaseException

call_id: str#
content: str#
exception autogen_core.components.tool_agent.ToolExecutionException(call_id: str, content: str)[source]#

Bases: ToolException

exception autogen_core.components.tool_agent.ToolNotFoundException(call_id: str, content: str)[source]#

Bases: ToolException

async autogen_core.components.tool_agent.tool_agent_caller_loop(caller: BaseAgent | AgentRuntime, tool_agent_id: AgentId, model_client: ChatCompletionClient, input_messages: List[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage], tool_schema: List[ToolSchema] | List[Tool], cancellation_token: CancellationToken | None = None, caller_source: str = 'assistant') List[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage][source]#

Start a caller loop for a tool agent. This function sends messages to the tool agent and the model client in an alternating fashion until the model client stops generating tool calls.

Parameters:
  • tool_agent_id (AgentId) – The Agent ID of the tool agent.

  • input_messages (List[LLMMessage]) – The list of input messages.

  • model_client (ChatCompletionClient) – The model client to use for the model API.

  • tool_schema (List[Tool | ToolSchema]) – The list of tools that the model can use.

Returns:

List[LLMMessage] – The list of output messages created in the caller loop.