Class AnthropicMessage

All Implemented Interfaces:
PropertyChangeSource, Rebindable

public class AnthropicMessage extends AbstractModelMessage<AnthropicResponse>
Message implementation for Anthropic's Claude.
Author:
anahata
  • Field Details

    • toolArgBuffers

      private transient Map<Integer, StringBuilder> toolArgBuffers
      Buffers for accumulating streaming tool call arguments, keyed by their index in the content block array.
    • toolIds

      private transient Map<Integer,String> toolIds
      Maps content block indices to their stable API-provided unique tool use IDs.
    • toolNames

      private transient Map<Integer,String> toolNames
      Maps content block indices to the requested tool name.
  • Constructor Details

    • AnthropicMessage

      public AnthropicMessage(Agi agi, String modelId)
      Constructs a new Anthropic message.
      Parameters:
      agi - The parent session.
      modelId - The model ID.
  • Method Details

    • parseFinalContent

      public void parseFinalContent(com.fasterxml.jackson.databind.JsonNode contentArray)
      Parses the final (non-streaming) content array from an Anthropic response. Handles text, thinking, and tool_use blocks.
      Parameters:
      contentArray - The JSON array of content blocks.
    • handleEvent

      public void handleEvent(String eventType, com.fasterxml.jackson.databind.JsonNode data)
      Processes a single streaming event from the Anthropic API.
      Parameters:
      eventType - The type of event (e.g., 'message_start', 'content_block_delta').
      data - The JSON payload associated with the event.
    • flushToolCall

      private void flushToolCall(int index)
      Finalizes a tool call by parsing its buffered JSON arguments and registering it with the tool manager.
      Parameters:
      index - The content block index for the tool.
    • appendContent

      public void appendContent(String text)
      Appends text to the last message part if it is a text part, otherwise creates a new one.
      Parameters:
      text - The text to append.
    • appendThoughts

      public void appendThoughts(String text)
      Appends text to the reasoning/thought part or creates a new one.
      Parameters:
      text - The thought text to append.
    • setThoughtSignatureOnLastPart

      public void setThoughtSignatureOnLastPart(byte[] sig)
      Sets the thought signature on the last thought part.
      Parameters:
      sig - The signature byte array.
    • setFinishReasonFromAnthropic

      public void setFinishReasonFromAnthropic(String reason)
      Maps an Anthropic stop reason to the unified Anahata finish reason.
      Parameters:
      reason - The raw string from the API.