Class AnthropicMessage
java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.message.AbstractMessage
uno.anahata.asi.agi.message.AbstractModelMessage<AnthropicResponse>
uno.anahata.asi.anthropic.AnthropicMessage
- All Implemented Interfaces:
PropertyChangeSource, Rebindable
Message implementation for Anthropic's Claude.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<Integer, StringBuilder> Buffers for accumulating streaming tool call arguments, keyed by their index in the content block array.Maps content block indices to their stable API-provided unique tool use IDs.Maps content block indices to the requested tool name.Fields inherited from class BasicPropertyChangeSource
propertyChangeSupport -
Constructor Summary
ConstructorsConstructorDescriptionAnthropicMessage(Agi agi, String modelId) Constructs a new Anthropic message. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendContent(String text) Appends text to the last message part if it is a text part, otherwise creates a new one.voidappendThoughts(String text) Appends text to the reasoning/thought part or creates a new one.private voidflushToolCall(int index) Finalizes a tool call by parsing its buffered JSON arguments and registering it with the tool manager.voidhandleEvent(String eventType, com.fasterxml.jackson.databind.JsonNode data) Processes a single streaming event from the Anthropic API.voidparseFinalContent(com.fasterxml.jackson.databind.JsonNode contentArray) Parses the final (non-streaming) content array from an Anthropic response.voidsetFinishReasonFromAnthropic(String reason) Maps an Anthropic stop reason to the unified Anahata finish reason.voidsetThoughtSignatureOnLastPart(byte[] sig) Sets the thought signature on the last thought part.Methods inherited from class AbstractModelMessage
addBlobPart, addBlobPart, addBlobPart, addTextPart, addTextPart, appendMetadata, appendRawJson, declineAllPending, executeAllPending, getDevice, getFrom, getRole, getToolCalls, getToolResponses, hasPendingTools, isAutoRunnable, isEffectivelyPruned, isToolPromptMessage, processPendingTools, remove, removePart, setBilledCompletionTokens, setBilledPromptTokens, setFinishReason, setGroundingMetadata, setRawJsonMethods inherited from class AbstractMessage
addPart, asText, createMetadataHeader, getDepth, getEffectiveTokenCount, getIdentityLabel, getParts, getParts, getRemainingDepth, getTokenCount, isAllPinned, isAllPruned, isAnyPinned, isEmpty, isGarbageCollectable, isPrunnableOrRemovable, pinAllParts, pruneAllParts, resetTokenCounts, setAutoAllParts, shouldCreateMetadataMethods inherited from class BasicPropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, rebind, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertyChangeSource
getPropertyChangeSupport
-
Field Details
-
toolArgBuffers
Buffers for accumulating streaming tool call arguments, keyed by their index in the content block array. -
toolIds
-
toolNames
-
-
Constructor Details
-
AnthropicMessage
-
-
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
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
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
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
Maps an Anthropic stop reason to the unified Anahata finish reason.- Parameters:
reason- The raw string from the API.
-

