Class ChatMessage
java.lang.Object
uno.anahata.ai.ChatMessage
A rich, stateful representation of a single message in the chat history.
This class encapsulates the content of a message (text, blobs, function calls/responses), along with metadata such as token usage, grounding information, and internal dependencies between parts (e.g., which function response belongs to which function call).
It uses a dependency graph to track relationships between Part objects,
which is essential for precise context pruning and stateful resource management.
- Author:
- Anahata
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDependencies(com.google.genai.types.Part sourcePart, List<com.google.genai.types.Part> dependentParts) Adds a list of dependent parts to a source part's dependency list, merging with any existing dependencies for that source part.Set<com.google.genai.types.Part> Gets a set of all parts that are involved in any dependency relationship within this message.Set<com.google.genai.types.Part> getAllDependencies(com.google.genai.types.Part startPart) Performs a full graph traversal to find all parts connected to the startPart, including the startPart itself.
-
Constructor Details
-
ChatMessage
public ChatMessage()
-
-
Method Details
-
getAllDependencies
Performs a full graph traversal to find all parts connected to the startPart, including the startPart itself. This is used to find the complete set of interdependent parts for operations like pruning.- Parameters:
startPart- The part from which to start the dependency search.- Returns:
- A Set containing all parts in the same dependency group as the startPart.
- Throws:
IllegalArgumentException- if the startPart is not found within this message's dependency graph.
-
getAllDependencies
Gets a set of all parts that are involved in any dependency relationship within this message.- Returns:
- A Set containing every part that is either a source or a target of a dependency.
-
addDependencies
public void addDependencies(com.google.genai.types.Part sourcePart, List<com.google.genai.types.Part> dependentParts) Adds a list of dependent parts to a source part's dependency list, merging with any existing dependencies for that source part.- Parameters:
sourcePart- The part that is the source of the dependency (the key).dependentParts- The parts that depend on the source part (the values).
-
