Record Class ToolCallDecisions
- Record Components:
decisions- one decision per tool call of the reply, with distinct keys
AssistantMessage, for a
ToolCallingManager to carry them out.
A manager pauses a batch when one of its calls needs confirmation (see
ToolCallConfirmationPolicy), by throwing
ToolCallConfirmationRequiredException before any call runs. A tool-calling loop
then returns the reply to the caller, listing the keys of the calls that wait for a
decision under AWAITING_DECISION_METADATA_KEY in the response metadata
(awaitingDecision(ChatResponse)). The caller shows them to a person and runs
the reply's calls with the decisions through
ToolCallingManager.executeToolCalls(org.springframework.ai.chat.prompt.Prompt, ChatResponse, ToolCallDecisions):
the allowed calls run, a denied call answers the model with its message. The tool
results then go to the model as part of the next request.
Every tool call of the reply needs a decision, and an allowed call runs only with a tool the prompt carries. The reply the calls come from must be the one the model gave, read from storage the end user cannot change: whoever can edit it can run any tool with any arguments.
Decisions name the calls by their keys (toolCallKeys(AssistantMessage)): a
call's id, or its position in the reply when the model gave it no id, or the same id as
another call. The reply itself is never changed.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe response metadata key under which a paused loop lists the keys of the tool calls that wait for a decision, as aList<String>.static final StringThe prefix of the key of a tool call that has no id of its own, followed by the call's position in the reply, starting at0. -
Constructor Summary
ConstructorsConstructorDescriptionToolCallDecisions(List<ToolCallDecision> decisions) Creates an instance of aToolCallDecisionsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionawaitingDecision(@Nullable ChatResponse chatResponse) The keys of the tool calls a paused loop waits on (seetoolCallKeys(AssistantMessage)), or an empty list when the response is not a paused one.@Nullable ToolCallDecisiondecisionOn(String toolCallId) The decision on the tool call with the key, ornullwhen there is none.Returns the value of thedecisionsrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static booleanisAwaitingDecision(@Nullable ChatResponse chatResponse) Whether the response is a paused one, with tool calls waiting for a decision.static ToolCallDecisionsof(ToolCallDecision... decisions) The decisions, one per tool call.toolCallKeys(AssistantMessage message) The keys of the tool calls of the message, in the order the model asked for them: a call's id when it has one that no other call of the message shares, otherwisePOSITION_KEY_PREFIXfollowed by the call's position, such as#1.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
POSITION_KEY_PREFIX
The prefix of the key of a tool call that has no id of its own, followed by the call's position in the reply, starting at0.- See Also:
-
AWAITING_DECISION_METADATA_KEY
The response metadata key under which a paused loop lists the keys of the tool calls that wait for a decision, as aList<String>. When streaming, the key is on the last chunk only; the aggregated response does not carry it.- See Also:
-
-
Constructor Details
-
ToolCallDecisions
Creates an instance of aToolCallDecisionsrecord class.- Parameters:
decisions- the value for thedecisionsrecord component
-
-
Method Details
-
of
The decisions, one per tool call. -
decisionOn
The decision on the tool call with the key, ornullwhen there is none. -
toolCallKeys
The keys of the tool calls of the message, in the order the model asked for them: a call's id when it has one that no other call of the message shares, otherwisePOSITION_KEY_PREFIXfollowed by the call's position, such as#1. Decisions name the calls by these keys. Some model providers return tool calls without ids; their calls are named by position, and the message keeps its calls as the model gave them.- Parameters:
message- the reply with the tool calls- Returns:
- one key per tool call, all distinct
-
awaitingDecision
The keys of the tool calls a paused loop waits on (seetoolCallKeys(AssistantMessage)), or an empty list when the response is not a paused one. When streaming, ask the last chunk; the aggregated response does not carry the keys.Only a response tells a paused reply apart: read it with
chatResponse()orchatClientResponse(). The text thatcontent()returns is the paused reply's text, often empty, and a streamedcontent()simply ends. -
isAwaitingDecision
Whether the response is a paused one, with tool calls waiting for a decision. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
decisions
Returns the value of thedecisionsrecord component.- Returns:
- the value of the
decisionsrecord component
-