Class ContextWindow
java.lang.Object
uno.anahata.ai.tools.spi.ContextWindow
A set of tools for inspecting and managing the AI's conversation context window.
These tools allow the model to monitor its own token usage, prune redundant information, and toggle dynamic context providers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringGenerates a detailed Markdown summary of all messages and parts in the context.static intGets the current total token count in the context window.static intGets the current token threshold.static StringpruneEphemeralToolCalls(List<String> toolCallIds, String reason) Prunes ephemeral tool calls and their responses by ID.static StringpruneOther(List<String> partIds, String reason) Prunes specific non-tool parts from the context.static StringpruneStatefulResources(List<String> resourceIds, String reason) Prunes all parts associated with specific stateful resources.static StringsetTokenThreshold(int newThreshold) Sets a new token threshold.static StringtoggleContextProviders(List<String> contextProviderIds, boolean enabled) Enables or disables specific context providers.
-
Constructor Details
-
ContextWindow
public ContextWindow()
-
-
Method Details
-
getContextSummary
Generates a detailed Markdown summary of all messages and parts in the context.- Returns:
- The context summary string.
-
pruneOther
Prunes specific non-tool parts from the context.- Parameters:
partIds- A list of part identifiers in 'messageId/partIndex' format.reason- The rationale for removal.- Returns:
- A status message indicating the result of the pruning.
- Throws:
Exception- if pruning fails.
-
pruneEphemeralToolCalls
public static String pruneEphemeralToolCalls(List<String> toolCallIds, String reason) throws Exception Prunes ephemeral tool calls and their responses by ID.- Parameters:
toolCallIds- A list of tool call IDs.reason- The rationale for removal.- Returns:
- A success message.
- Throws:
Exception- if pruning fails.
-
pruneStatefulResources
public static String pruneStatefulResources(List<String> resourceIds, String reason) throws Exception Prunes all parts associated with specific stateful resources.- Parameters:
resourceIds- A list of resource IDs (full paths).reason- The rationale for removal.- Returns:
- A success message.
- Throws:
Exception- if pruning fails.
-
getTokenCount
-
getTokenThreshold
public static int getTokenThreshold()Gets the current token threshold.- Returns:
- The token threshold.
-
setTokenThreshold
Sets a new token threshold.- Parameters:
newThreshold- The new threshold value.- Returns:
- A success message.
-
toggleContextProviders
-
