Class ToolInvocation
When the assistant invokes a tool, this object contains the context including the session ID, tool call ID, tool name, and arguments parsed from the assistant's request.
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the arguments passed to the tool as a Map.<T> TgetArgumentsAs(Class<T> type) Deserializes the tool arguments into the specified type.Gets the session ID where the tool was invoked.Gets the unique identifier for this tool call.Gets the name of the tool being invoked.setArguments(com.fasterxml.jackson.databind.JsonNode arguments) Sets the tool arguments.setSessionId(String sessionId) Sets the session ID.setToolCallId(String toolCallId) Sets the tool call ID.setToolName(String toolName) Sets the tool name.
-
Constructor Details
-
ToolInvocation
public ToolInvocation()
-
-
Method Details
-
getSessionId
Gets the session ID where the tool was invoked.- Returns:
- the session ID
-
setSessionId
Sets the session ID.- Parameters:
sessionId- the session ID- Returns:
- this invocation for method chaining
-
getToolCallId
Gets the unique identifier for this tool call.This ID correlates the tool invocation with its response.
- Returns:
- the tool call ID
-
setToolCallId
Sets the tool call ID.- Parameters:
toolCallId- the tool call ID- Returns:
- this invocation for method chaining
-
getToolName
Gets the name of the tool being invoked.- Returns:
- the tool name
-
setToolName
Sets the tool name.- Parameters:
toolName- the tool name- Returns:
- this invocation for method chaining
-
getArguments
Gets the arguments passed to the tool as a Map.The arguments are provided as a
Map<String, Object>matching the parameter schema defined in the tool'sToolDefinition. Values can be accessed using standard Map operations.For type-safe access, use
getArgumentsAs(Class)to deserialize arguments into a record or POJO.- Returns:
- the arguments as a Map, or null if no arguments
- See Also:
-
getArgumentsAs
Deserializes the tool arguments into the specified type.This method provides type-safe access to tool arguments by converting the JSON arguments into a record, POJO, or other compatible type.
// Define a record for your tool's arguments record WeatherArgs(String city) { } // In your tool handler WeatherArgs args = invocation.getArgumentsAs(WeatherArgs.class); String city = args.city();- Type Parameters:
T- the type to deserialize to- Parameters:
type- the class of the target type- Returns:
- the arguments deserialized as the specified type
- Throws:
IllegalArgumentException- if deserialization fails- Since:
- 1.0.0
-
setArguments
Sets the tool arguments.Note: This method is intended for internal SDK use and JSON deserialization. Users typically do not need to call this method directly.
- Parameters:
arguments- the arguments as a JsonNode- Returns:
- this invocation for method chaining
-