Anahata Core

An Enterprise ready, Domain-Driven abstraction of the Context Window. Engineered for stability, modularity, portability, observability, security and traceability.

Mission Statement

Core provides the atomic units of context (Messages, Parts, Tools) and the context augmentation and metabolic management systems (CwGC) required to sustain live, long-running, multi-modal, cross platform, super intelligent agentic sessions without provider lock-in.

The AGI Container

The Agi class is the central orchestrator. It manages the session lifecycle, state persistence, and model communication.

  • Transactional States: Automatically triggers autoSave() on turn completion or terminal tool states (EXECUTED/FAILED) to ensure persistence.
  • Non-Blocking Inputs: Implements a stagedUserMessage queue, allowing users to submit input while the ASI is currently processing a turn.
  • Metabolic Policy: The AgiConfig defines default Turns to Keep (Max Depth) for different data types: Text (108), Thoughts (12), Tools (12), and Blobs (4).

Messages & Parts

Anahata treats context as a rich graph. A conversation is a sequence of AbstractMessage turns, each containing a collection of AbstractPart objects tracking their own metadata and metabolic state.

classDiagram AbstractMessage *-- AbstractPart AbstractPart <|-- TextPart AbstractPart <|-- BlobPart AbstractPart <|-- AbstractToolCall AbstractToolCall *-- AbstractToolResponse

In-Band Metadata Injection

Self-awareness is achieved by interleaving invisible metadata headers before every component. Even when a part is effectively pruned to save tokens, the Pruned Hint ensures the ASI maintains a "Semantic Ghost" of the action.

Metabolic Part Lifecycle

Depth 0
Thought (12)
Text (108)
User Blob (4)
Tool Call (12)
Depth 4
Thought (8)
Text (104)
Blob Ghost
Tool Call (8)
Depth 12
Thought Ghost
Text (96)
Blob Ghost
Tool Ghost
Depth 108
Recycling...
Recycling...
Recycling...
Recycling...
Example: Ghost Metadata Header
[x-anahata-part-id: 19 | Type: JavaMethodToolCall | Status: EXECUTED | Remaining Depth: 0 | Hint: Tool: NbFiles.updateTextFile | Result: Success]

Garbage Collection (CwGC)

Metabolic Logic Dashboard

Formula Engine
getDepth() = distance from head
turnsToKeep = MaxDepth policy
getRemainingDepth() = turnsToKeep - getDepth()
Ghost State Trigger
isEffectivelyPruned() == true

1. Omit body content
2. Inject Metadata Hint
pruningStateSymbolBehavior
AUTOSoft-pruned when depth expires.
PINNEDThe Messi State. Immune to GC. Permanent awareness.
PRUNEDImmediately recycled into a Ghost.

Context Providers

Context Providers are the sensors of the ASI. They contribute high-salience information to the RAG Message via a hierarchical tree structure.

classDiagram class ContextProvider { <<interface>> +getId() String +getName() String +isProviding() boolean +getContextPosition() ContextPosition +getSystemInstructions() List +populateMessage(RagMessage) } class BasicContextProvider { -String id -String name -boolean providing } class ContextManager { -List providers +addMessage(AbstractMessage) } class ResourceManager { -Map resources } class Resource { -ResourceHandle handle -ResourceView view -RefreshPolicy policy -ContextPosition position } class ContextPosition { <<enumeration>> SYSTEM_INSTRUCTIONS PROMPT_AUGMENTATION } class RefreshPolicy { <<enumeration>> LIVE SNAPSHOT } ContextProvider <|.. BasicContextProvider BasicContextProvider <|-- ContextManager BasicContextProvider <|-- ResourceManager BasicContextProvider <|-- Resource Resource o-- ContextPosition Resource o-- RefreshPolicy ContextManager "1" *-- "*" ContextProvider : manages

Reactive Events

The JASI platform follows a Data-First Reactive UI pattern. Core components implement the PropertyChangeSource interface, allowing the Swing UI to remain perfectly synchronized with the domain state.

Example: PropertyChangeSource Implementation
public class ResourceManager extends BasicPropertyChangeSource {
    public void register(Resource resource) {
        resources.put(resource.getId(), resource);
        // Fires event to trigger UI tree refresh
        propertyChangeSupport.firePropertyChange("resources", null, getResourcesList());
    }
}
Example: Swing UI Binding
agi.addPropertyChangeListener("status", evt -> {
    statusIndicator.update((AgiStatus) evt.getNewValue());
});

Universal Resource Pipeline (V2)

The V2 architecture introduces a URI-centric, capability-based resource model that decouples the source of data from its interpretation. Resources are "Self-Aware" and automatically bind the appropriate view based on detected MIME types.

Dual-Role Positioning

A single Resource can be loaded into either the SYSTEM_INSTRUCTIONS position (providing high-level behavioral guidance) or the PROMPT_AUGMENTATION (RAG) position for just-in-time facts. The system automatically routes the processed content to the correct section of the prompt.

Reactive Awareness

The ResourceManager identifies resources that are registered but disabled, injecting their metadata headers into the RAG message. This ensures the ASI remains aware of available but silent assets.

The Source Nexus: Universal Connectivity

graph LR subgraph Sources L[local file] Z[zip/jar entry] F[ftp/http server] NB[netbeans fileObject] end L --> PathHandle Z --> UrlHandle F --> UrlHandle NB --> NbHandle PathHandle --> Resource UrlHandle --> Resource NbHandle --> Resource subgraph Policies Resource -- "Refresh: LIVE" --> P1[Auto-Reload on Turn] Resource -- "Refresh: SNAPSHOT" --> P2[Static Memory] end subgraph Delivery P1 -- "Position: RAG" --> RAG[Prompt Augmentation] P1 -- "Position: SYSTEM" --> SYS[System Instructions] P2 --> RAG P2 --> SYS end

Resource Component Hierarchy

classDiagram class Resource { -ResourceHandle handle -ResourceView view -RefreshPolicy policy -ContextPosition position +reload() } class ResourceHandle { <<interface>> +openStream() InputStream +getLastModified() long } class ResourceView { <<interface>> +reload(ResourceHandle) +populateRag(RagMessage, ResourceHandle) } class RefreshPolicy { <<enumeration>> LIVE SNAPSHOT } class ContextPosition { <<enumeration>> SYSTEM_INSTRUCTIONS PROMPT_AUGMENTATION } class TextView class MediaView class PathHandle class UrlHandle class NbHandle Resource o-- ResourceHandle Resource o-- ResourceView Resource o-- RefreshPolicy Resource o-- ContextPosition ResourceView <|.. TextView ResourceView <|.. MediaView ResourceHandle <|.. PathHandle ResourceHandle <|.. UrlHandle ResourceHandle <|.. NbHandle

Toolkits & Tools

Session

Metadata & depth governor.

Files

Atomic cross-platform I/O.

Java

Singularity hot-reload engine.

Shell

Direct host interaction.

Advanced State Management

Toolkits manage three scopes of memory: Session (AGI turn), Container (all sessions), and Application (JVM-wide). Deserialization is handled via rebind().

Java: Scoped Persistence & Rebinding
@AiToolkit(value = "Task Orchestration", maxDepth = 12)
public class TaskToolkit extends AnahataToolkit {
    private List<String> persistentTasks = new ArrayList<>(); // Serialized by Kryo
    private transient Map<String, Long> runtimeMetrics; // Cleared on save

    @Override
    public void rebind() {
        this.runtimeMetrics = new ConcurrentHashMap<>(); // Restored upon deserialization
    }

    @AiTool("Shares a task across the ASI Container.")
    public String createGlobalTask(String task) {
        getSessionMap().put("last", task);      // Local turn memory
        getContainerMap().put("latest", task);   // Shared across all app AGIs
        getApplicationMap().put("sys", "UP");    // Shared across entire JVM
        return "Broadcasting task...";
    }
}

Java: On-the-Fly Tool Creation

The Java toolkit enables the Singularity Loop: scouting a new capability and integrating it into the starting XI in just two turns.

The Singularity Loop: 2-Turn Self-Evolution

sequenceDiagram participant AI as ASI Model participant M as Maven Toolkit participant J as Java Toolkit Note over AI, J: TURN 1: Scout & Acquire AI->>M: downloadDependencyArtifact("org.apache.commons") M-->>AI: Success: math3.jar saved to disk Note over AI, J: TURN 2: Integration & Debut AI->>J: compileAndExecute(source, extraClassPath: "math3.jar") J-->>AI: Success: Model-generated logic executing Math3 code!

The Hot-Reload Onboarding Engine

Child-First Isolation
1. In-memory Bytecode Compilation
2. URLClassLoader prepends extraClassPath
3. PARENT-FIRST Filter for ToolContext
4. Onboarding instance into Agi/Asi
Context Propagation

Dynamic tools inherit multi-threaded logging and can call other toolkits using getToolkit(Class). Other kits can reference the originating call to add rich attachments or errors.

Java ↔ JSON Schema (J2S)

Java: Recursive IssueNode DTO
@Schema(description = "Recursive dependency analysis.")
public class IssueNode {
    private String id;
    private List<IssueNode> children;
}
Generated JSON Schema (Recursive)
{
  "title": "uno.anahata.asi.model.IssueNode",
  "properties": {
    "children": {
      "type": "array",
      "items": { "description": "Recursive reference to IssueNode" }
    }
  }
}

Flight Recorder & Persistence

The Agi Container is designed from the ground up for ultra-fast passivation / serialization of the entire container. This includes the state of: container settings and state, history, context providers, resources, and toolkits.

Passivation (Kryo)

Uses the Kryo framework for high-performance binary persistence. Handles complex circular references and large object graphs natively.

State Healing (Rebindable)

The uno.anahata.asi.internal.kryo.Rebindable interface allows any Java class in the entire object graph to restore transient fields post-deserialization.

Example: Post-Deserialization State Recovery
public class NbHandle extends AbstractResourceHandle implements Rebindable {
    private transient FileObject fileObject; // Lost during serialization
    private String path;

    @Override
    public void rebind() {
        // Restore the live FileObject pointer from the persisted path string
        this.fileObject = FileUtil.toFileObject(new File(path));
        if (this.fileObject != null) {
            setupListeners(); // Re-attach IDE hooks
        }
    }
}

Recording Modes

  • Auto Save (Default): The Agi container is serialized on every turn and every tool execution to the same backup file. This allows for transactional-grade crash recovery.
  • Flight Recorder (Storage Intensive): The Agi container is serialized to a different backup file on every turn and every tool execution. This allows for fully auditable/replayable sessions.