Class AbstractToolCall<T extends AbstractTool<?,?>, R extends AbstractToolResponse<?>>

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 Details

    • id

      private final String id
      A unique, immutable identifier for this specific invocation request.
    • tool

      @NonNull private final T extends AbstractTool<?,?> tool
      The tool definition that this call corresponds to. Ignored during serialization to avoid issues with non-serializable members (e.g. Method).
    • rawArgs

      @NonNull private final @NonNull Map<String,Object> rawArgs
      The original, raw arguments received from the AI provider (e.g., Gemini). These are stored as a plain JSON-style Map for debugging and "Final Gate" safety.
    • args

      @NonNull private final @NonNull Map<String,Object> args
      The enriched arguments for the tool, which may contain rich POJOs (like JavaType). This map is used for tool execution and application logic.
    • modifiedArgs

      private final Map<String,Object> modifiedArgs
      Map of arguments that were modified by the user in the UI. This represents the "draft" state of the arguments.
    • response

      @NonNull private final R extends AbstractToolResponse<?> response
      The single, final response object associated with this call. This is ignored during schema generation to prevent a circular reference.
    • thoughtSignature

      private byte[] thoughtSignature
      The 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

      public String getToolName()
      Gets the name of the tool to be invoked.
      Returns:
      The tool's name.
    • getMessage

      public AbstractModelMessage getMessage()
      Gets the model message that initiated this tool call.
      Returns:
      The parent model message.
    • createResponse

      protected abstract R 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

      public void setModifiedArgument(String name, Object value)
      Updates a modified argument in the draft state and fires a property change event.
      Parameters:
      name - The name of the argument.
      value - The new value.
    • getEffectiveArgs

      public Map<String,Object> getEffectiveArgs()
      Gets the effective arguments for the UI (original + draft modifications).
      Returns:
      a map of effective arguments.
    • 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:
      calculateTokenCount in class AbstractPart
    • 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:
      resetTokenCount in class AbstractPart
    • 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:
      isEffectivelyPruned in class AbstractPart
      Returns:
      true if the part is effectively pruned, false otherwise.
    • 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 explicit maxDepth is set on the instance.
      Specified by:
      getDefaultMaxDepth in class AbstractPart
      Returns:
      The default maximum depth for this part type.
    • asText

      public String 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:
      asText in class AbstractPart
      Returns:
      The text representation of the part.
    • getArgumentsString

      public String getArgumentsString(boolean effective)
      Formats the tool call's arguments into a concise, Java-like comma-separated string. Honors Displayable.getDisplayValue() and bracketed collections via TextUtils.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

      public String 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 of AbstractPart.asText(). Overridden to provide a rich, detailed execution summary in the pruned metadata header.
      Overrides:
      getPrunedHint in class AbstractPart
      Returns:
      The pruned hint string.
    • appendMetadata

      protected void appendMetadata(StringBuilder sb)
      Hook for subclasses to inject specialized metadata into the part header.
      Overrides:
      appendMetadata in class AbstractPart
      Parameters:
      sb - The StringBuilder building the header.