Class Session
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
This toolkit provides high-level control over the session environment, allowing the model to optimize its own context window, toggle available toolkits, and manage the lifecycle of stateful resources.
- Author:
- anahata-ai
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DateThe last time the session got deserialized.private DateThe time when the session started.Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSwitches the session to server-side tool mode.Gets a list of system instruction strings provided by this context provider.killRunningTools(List<Long> toolCallIds) Signals one or more currently executing background tools to stop.voidpopulateMessage(RagMessage ragMessage) Populates the RAG message with comprehensive session metadata.voidCaptures the sessionRestored time during deserialization;voidsetContextProviderProviding(boolean providing, List<String> providerIds) Enables or disables specific context providers within the session hierarchy.voidsetToolkitEnabled(boolean enabled, List<String> toolkitNames) Enables or disables multiple toolkits by their names.updateSessionNickname(String nickName) Updates the AGIs nickname.updateSessionSummary(String summary) Updates the human-readable summary of the current session.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, rebindMethods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, isProviding, setParentProvider, setProviding
-
Field Details
-
sessionStart
The time when the session started. -
sessionRestored
The last time the session got deserialized.
-
-
Constructor Details
-
Session
public Session()
-
-
Method Details
-
postActivate
public void postActivate()Captures the sessionRestored time during deserialization;- Overrides:
postActivatein classAnahataToolkit
-
getSystemInstructions
Description copied from interface:ContextProviderGets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.- Returns:
- A list of system instruction strings.
- Throws:
Exception- if an error occurs during instruction generation.
-
updateSessionNickname
-
updateSessionSummary
Updates the human-readable summary of the current session.STRICT USAGE RULE: This tool MUST ONLY be called if there are other "task-related" tool calls (e.g., file manipulation, shell commands, pruning) being made in the same turn. It should NEVER be called as the sole tool in a turn.
The summary is visible to the user in the container dashboard and the parent agi if spawned by another agi.
- Parameters:
summary- A concise summary of the conversation's current state or topic.- Returns:
- A confirmation message.
-
setContextProviderProviding
Enables or disables specific context providers within the session hierarchy.This tool allows the model to surgically control which providers contribute to the RAG message, helping to reduce noise and optimize token usage.
- Parameters:
providing- Whether to enable or disable the providers.providerIds- The fully qualified IDs of the context providers to update.
-
setToolkitEnabled
Enables or disables multiple toolkits by their names.Disabling a toolkit makes its tools invisible to the model and can reduce complexity when certain capabilities are no longer needed.
- Parameters:
enabled- Whether to enable or disable the toolkits.toolkitNames- The names (IDs) of the toolkits to update (e.g., 'Audio', 'Chrome').
-
killRunningTools
Signals one or more currently executing background tools to stop.This is useful for cancelling long-running tasks like large file reads, complex shell commands, or audio recording.
- Parameters:
toolCallIds- The unique IDs of the tool calls to stop.- Returns:
- A detailed report of the stopping operations.
-
enableHostedTools
Switches the session to server-side tool mode.CRITICAL: After calling this, local Java tools are disabled until manually re-enabled by the user. Use this only when a capability provided by the model host (e.g., Google Search) is explicitly required.
- Returns:
- Confirmation message describing the impact.
-
populateMessage
Populates the RAG message with comprehensive session metadata.Provides a Markdown summary of session identity, model configuration, context window usage, and the status of executing tools.
- Parameters:
ragMessage- The target RAG message.- Throws:
Exception- if metadata extraction fails.
-

