public final class ToolCall
- Object
- ToolCall
A tool/function invocation produced by the model. The id round-
trips the call back to a ToolResultPart so the provider can
match the result to the original request. argumentsJson is the
raw JSON string the model produced – parse it with
JSONParser if you need the structured fields.
Use execute(List) to dispatch to the matching Tool handler
from the request’s tool list. See the Tool class javadoc for
the full pattern.
Constructors
public ToolCall(String id, String name, String argumentsJson) | Creates a normalized model tool call. |
Methods
public String getId() | |
public String getName() | |
public String getArgumentsJson() | |
public String execute(List<Tool> tools)
throws Exception | Finds the Tool whose name matches this call and invokes its ToolHandler with this call’s argumentsJson. |
public Tool findTool(List<Tool> tools) | Looks up the matching Tool without invoking it. |
Inherited methods
Constructor details
ToolCall
public ToolCall(String id, String name, String argumentsJson)Parameters
idString- provider id used to associate the result
nameString- requested tool name
argumentsJsonString- model-generated JSON arguments;
nullbecomes{}
Method details
getId
public String getId()Returns
getName
public String getName()Returns
getArgumentsJson
public String getArgumentsJson()Returns
execute
public String execute(List<Tool> tools)
throws ExceptionFinds the Tool whose name matches this call and invokes its
ToolHandler with this call’s argumentsJson. Returns the
JSON result the handler produced. Apps typically wrap that in
a ChatMessage.toolResult and append it to the conversation
before the next chat turn.
Throws IllegalArgumentException when no tool in tools
has a matching name, or IllegalStateException when the
matching tool has no handler registered.
Parameters
toolsList<Tool>- definitions offered with the request
Returns
Throws
Exception- when lookup or application execution fails
findTool
public Tool findTool(List<Tool> tools)Tool without invoking it. Useful when
the caller wants to dispatch by hand but still benefit from
the name-matching plumbing.Parameters
toolsList<Tool>- candidate definitions, or
null
Returns
null