Class AbstractToolCall<T extends AbstractTool<?,?>, R extends AbstractToolResponse<?>>
java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.message.AbstractPart
uno.anahata.asi.agi.tool.spi.AbstractToolCall<T,R>
- Type Parameters:
T- The specific type of the Tool.R- The specific type of the Response.
- All Implemented Interfaces:
PropertyChangeSource, ThoughtSignature, Rebindable
- Direct Known Subclasses:
BadToolCall, JavaMethodToolCall
public abstract class AbstractToolCall<T extends AbstractTool<?,?>, R extends AbstractToolResponse<?>>
extends AbstractPart
implements ThoughtSignature
Represents a request to execute a specific tool. It holds a direct reference
to the tool's definition and its corresponding response.
In the V2 architecture, the tool call is the primary message part. It owns the response lifecycle entirely. Pruning the call effectively prunes the response for context purposes.
- Author:
- anahata-gemini-pro-2.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe enriched arguments for the tool, which may contain rich POJOs (like JavaType).private final StringA unique, immutable identifier for this specific invocation request.Map of arguments that were modified by the user in the UI.The original, raw arguments received from the AI provider (e.g., Gemini).private final RThe single, final response object associated with this call.private byte[]The signature of the thought process as a byte array.private final TThe tool definition that this call corresponds to.Fields inherited from class BasicPropertyChangeSource
propertyChangeSupportModifier and TypeFieldDescriptionprotected PropertyChangeSupportSupport for firing property change events. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractToolCall(AbstractModelMessage message, String id, T tool, @NonNull Map<String, Object> rawArgs, @NonNull Map<String, Object> args) Constructs a new AbstractToolCall. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHook for subclasses to inject specialized metadata into the part header.asText()Returns the content of the part as a simple string.protected voidPerforms the lazy, model-specific token calculation for this part.private intCalculates the total tokens consumed by this tool call, including its nested execution response, by delegating to the selected model's offline tokenizer.protected abstract RCreates the corresponding response object for this tool call.getArgumentsString(boolean effective) Formats the tool call's arguments into a concise, Java-like comma-separated string.protected intTemplate method hook for subclasses to provide their specific default max depth policy.Gets the effective arguments for the UI (original + draft modifications).Gets the model message that initiated this tool call.Returns a summarized string representation of the part's content to be used as a "Hint" when the part is effectively pruned.Gets the name of the tool to be invoked.booleanCalculates the EFFECTIVE pruned state of this part.voidResets the cached token count, forcing a lazy, background recalculation on the next call to getTokenCount().voidsetModifiedArgument(String name, Object value) Updates a modified argument in the draft state and fires a property change event.Methods inherited from class AbstractPart
createMetadataHeader, getAgi, getAgiConfig, getEffectiveMaxDepth, getEffectiveTokenCount, getIdentityLabel, getMetadataTokenCount, getRemainingDepth, getTokenCount, isAuto, isPinned, isPruned, remove, setExpanded, setPruningState, setPruningState, setTokenCountModifier and TypeMethodDescriptionCreates a standardized text header containing metadata for this part.getAgi()Gets the parent agi session.Gets the agi configuration.final intThe definitive method for resolving the max depth policy for this part.intCalculates the total "effective" tokens contributed by this part.protected StringReturns the identity label for the metadata header (e.g., "Part ID: 45").intCalculates the token count of the metadata header for this part.intCalculates the remaining depth before this part is auto-pruned.intRetrieves the cached token count for this part.booleanisAuto()Checks if this part is managed automatically.booleanisPinned()Checks if this part is explicitly pinned.booleanisPruned()Checks if this part is explicitly pruned.voidremove()Removes this part from its parent message and severs the bidirectional link.voidsetExpanded(boolean expanded) Sets the expanded state and fires a property change event.voidsetPruningState(PruningState pruningState) Sets the pruning state of this part and fires a property change event.voidsetPruningState(PruningState pruningState, String reason) Sets the pruning state of this part with an optional reason.voidsetTokenCount(int tokenCount) Sets the token count and fires a property change event.Methods inherited from class BasicPropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, rebind, removePropertyChangeListener, removePropertyChangeListenerModifier and TypeMethodDescriptionvoidAdds a property change listener.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Adds a property change listener for a specific property.voidrebind()Re-initializes the transientPropertyChangeSupportafter deserialization.voidRemoves a property change listener.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) Removes a property change listener for a specific property.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertyChangeSource
getPropertyChangeSupportModifier and TypeMethodDescriptionGets the PropertyChangeSupport instance for this object.Methods inherited from interface ThoughtSignature
getThoughtSignature, setThoughtSignatureModifier and TypeMethodDescriptionbyte[]Gets the signature of the thought process as a byte array.voidsetThoughtSignature(byte[] thoughtSignature) Sets the signature of the thought process as a byte array.
-
Field Details
-
id
A unique, immutable identifier for this specific invocation request. -
tool
The tool definition that this call corresponds to. Ignored during serialization to avoid issues with non-serializable members (e.g. Method). -
rawArgs
-
args
-
modifiedArgs
-
response
The single, final response object associated with this call. This is ignored during schema generation to prevent a circular reference. -
thoughtSignature
private byte[] thoughtSignatureThe signature of the thought process as a byte array.
-
-
Constructor Details
-
AbstractToolCall
public AbstractToolCall(AbstractModelMessage message, String id, @NonNull T tool, @NonNull @NonNull Map<String, Object> rawArgs, @NonNull @NonNull Map<String, Object> args) Constructs a new AbstractToolCall.- Parameters:
message- The model message that initiated the call.id- The unique call ID.tool- The tool definition.rawArgs- The original JSON arguments from the provider.args- The enriched arguments (POJOs).
-
-
Method Details
-
getToolName
-
getMessage
Gets the model message that initiated this tool call.- Returns:
- The parent model message.
-
createResponse
Creates the corresponding response object for this tool call. This acts as a factory method and is called once by the constructor.- Returns:
- A new, un-executed tool response.
-
setModifiedArgument
-
getEffectiveArgs
-
calculateTokenCount
protected void calculateTokenCount()Performs the lazy, model-specific token calculation for this part. This is implemented by subclasses to perform the actual calculation.Performs the lazy calculation of the total tool call and response tokens.
- Specified by:
calculateTokenCountin classAbstractPart
-
resetTokenCount
public void resetTokenCount()Resets the cached token count, forcing a lazy, background recalculation on the next call to getTokenCount().Resets the cached token counts of both the tool call and its nested response, forcing a lazy recalculation under the new selected model.
- Overrides:
resetTokenCountin classAbstractPart
-
calculateTotalTokens
private int calculateTotalTokens()Calculates the total tokens consumed by this tool call, including its nested execution response, by delegating to the selected model's offline tokenizer.- Returns:
- The total token count.
-
isEffectivelyPruned
public boolean isEffectivelyPruned()Calculates the EFFECTIVE pruned state of this part. A part is effectively pruned if it was explicitly pruned or if its time-to-live has expired (while in AUTO state).An actively executing tool call is immune to pruning, guaranteeing that it remains visible in the prompt and is never garbage collected while its background execution is still underway.
- Overrides:
isEffectivelyPrunedin classAbstractPart- Returns:
trueif the part is effectively pruned,falseotherwise.
-
getDefaultMaxDepth
protected int getDefaultMaxDepth()Template method hook for subclasses to provide their specific default max depth policy. This is the fallback value used when no explicitmaxDepthis set on the instance.- Specified by:
getDefaultMaxDepthin classAbstractPart- Returns:
- The default maximum depth for this part type.
-
asText
Returns the content of the part as a simple string. This is implemented by subclasses.Returns the complete text representation of the tool call, including its Java-like arguments signature and the full execution response details.
- Specified by:
asTextin classAbstractPart- Returns:
- The text representation of the part.
-
getArgumentsString
Formats the tool call's arguments into a concise, Java-like comma-separated string. HonorsDisplayable.getDisplayValue()and bracketed collections viaTextUtils.formatValue(Object).- Parameters:
effective- If true, uses effective args (including user modifications); otherwise original args.- Returns:
- The formatted comma-separated arguments string (e.g. "true, [FlightContact, Airport]").
-
getPrunedHint
Returns a summarized string representation of the part's content to be used as a "Hint" when the part is effectively pruned. Defaults to a formatted version ofAbstractPart.asText(). Overridden to provide a rich, detailed execution summary in the pruned metadata header.- Overrides:
getPrunedHintin classAbstractPart- Returns:
- The pruned hint string.
-
appendMetadata
Hook for subclasses to inject specialized metadata into the part header.- Overrides:
appendMetadatain classAbstractPart- Parameters:
sb- The StringBuilder building the header.
-

