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:
- async handle_function_call(message: FunctionCall, ctx: MessageContext) FunctionExecutionResult [source]#
Handles a FunctionCall message by executing the requested tool with the provided arguments.
- Parameters:
message (FunctionCall) – The function call message.
cancellation_token (CancellationToken) – The cancellation token.
- Returns:
FunctionExecutionResult – The result of the function execution.
- Raises:
ToolNotFoundException – If the tool is not found.
InvalidToolArgumentsException – If the tool arguments are invalid.
ToolExecutionException – If the tool execution fails.
- internal_extra_handles_types: ClassVar[List[Tuple[Type[Any], List[MessageSerializer[Any]]]]] = []#
- internal_unbound_subscriptions_list: ClassVar[List[UnboundSubscription]] = []#
- exception autogen_core.components.tool_agent.ToolException(call_id: str, content: str)[source]#
Bases:
BaseException
- 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.