# chatsci/aeiva architecture

> Architecture diagram of the GitHub repository chatsci/aeiva, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chatsci/aeiva
- Repository: https://github.com/chatsci/aeiva

## Overview

1. **Repository shape**
   - This is a Python agent platform with a single core package (`src/aeiva`) and several interaction surfaces around it.
   - The architecture is centered on a reusable agent runtime, not a single app: terminal chat, Gradio web UI, Slack, WhatsApp, realtime audio/text, browser automation, and a LifeRPG-style personal model all connect to the same core.

2. **Primary runtime entrypoints**
   - The command layer under `src/aeiva/command` is the top-level orchestration boundary.
   - Key entrypoints include `aeiva_gateway`, `aeiva_server`, `aeiva_chat_terminal`, `aeiva_chat_gradio`, `aeiva_chat_slack`, `aeiva_chat_whatsapp`, `aeiva_chat_realtime`, and `aeiva_dialogue_replay`.
   - These commands select a channel, load config, wire services together, and hand off to the agent runtime.

3. **Channel adapters and external interfaces**
   - `src/aeiva/interface` and parts of `src/aeiva/command` implement gateway adapters for terminal, Slack, and WhatsApp.
   - The current product shape also includes a web dialogue UI and a separate LifeRPG UI, both exposed by the unified gateway.
   - This makes the channel layer a thin boundary: it receives user input, normalizes it, and forwards it to the core agent; responses flow back through the same adapter.

4. **Core agent / cognition pipeline**
   - The conceptual center is the `agent`, `cognition`, `perception`, `action`, and `tool` packages.
   - `perception` ingests raw stimuli from sensors such as terminal input, audio streams, and video streams.
   - `cognition` turns those stimuli into internal state: input interpretation, brain, emotion, goal, thought, reward, world model, memory, and mind manager.
   - `action` represents what the system decides to do: plans, steps, procedures, tasks, skills, statuses, and actuators.

5. **LLM abstraction and model backends**
   - `src/aeiva/llm` provides the model boundary: client logic, provider registry, API handlers, tool-loop support, fault tolerance, and usage metrics.
   - Providers are pluggable, with at least a LiteLLM-based provider and a local MiniCPM provider.
   - This layer isolates the rest of the system from model-specific APIs and enables both remote and local inference.

6. **Tooling and execution boundary**
   - `src/aeiva/tool` is the execution substrate for external actions.
   - It includes core tools such as calculator, web search, filesystem, and shell, plus a meta browser tool for more complex web interaction.
   - The tool registry and decorator system imply a capability-based design: the agent can only invoke tools that are registered and approved.

7. **Browser automation subsystem**
   - The browser stack under `src/aeiva/tool/meta/browser_stack` is a substantial subsystem on its own.
   - It includes runtime launch, session management, snapshot/scroll/interaction scripts, element matching, target resolution, form filling, security, and service dispatch layers.
   - Architecturally, this is the web-execution engine for tasks like navigation, extraction, and form automation, with strong separation between runtime state and higher-level service actions.

8. **Memory and storage**
   - `src/aeiva/cognition/memory` handles agent memory behavior: raw memory, summary memory, memory organization/cleaning, storage, links, and service/config layers.
   - `src/aeiva/storage` provides concrete persistence backends: SQLite, Chroma, and KuzuDB, all behind shared database abstractions.
   - This creates a layered persistence model: cognition-level memory logic sits above storage engines, which can be swapped based on the workload.

9. **Realtime multimodal path**
   - `src/aeiva/realtime` is the dedicated path for low-latency audio/text interaction.
   - It contains provider abstractions for OpenAI and MiniCPM live models, plus WebRTC/FastRTC integration, response strategy, pause handling, and live UI builder/capabilities.
   - This path is separate from the normal turn-based chat flow, which matters for diagrams because realtime interaction has its own transport and model orchestration.

10. **Host, policy, and safety boundaries**
   - `src/aeiva/host` defines the host-side control plane: CLI, daemon, router, runner, protocol, approval policy, and command policy.
   - `src/aeiva/tool/meta/exec_approval.py` and browser security modules suggest explicit approval gating for sensitive actions.
   - In architecture terms, the host layer mediates between user-facing channels and privileged execution, enforcing command/approval rules.

11. **LifeRPG and social modeling**
   - `src/aeiva/liferpg`, `src/aeiva/society`, and `src/aeiva/ecs` provide structured self-modeling and social/persona abstractions.
   - The README describes LifeRPG as a separate UI for identity, roles, inventory, projects, and TODOs.
   - These packages represent a domain model layered alongside conversation: the agent is not only answering text, but also maintaining a persistent life/identity graph.

12. **Sandbox, plugins, and extension surfaces**
   - `src/aeiva/sandbox` is an isolated Docker-based execution environment for running tasks safely.
   - `src/aeiva/plugin` includes plugin abilities and a VS Code daemon/adapter, showing that Aeiva can embed into editor workflows.
   - This is important architecturally because execution is intentionally split into trusted core, sandboxed execution, and host/editor integrations.

13. **Eventing, state, and lower-level runtime primitives**
   - `src/aeiva/event`, `neuron`, `mas`, `environment`, and `embedding` provide supporting runtime primitives rather than user-facing features.
   - The event bus, scheduler, signal/state/validation layers, and environment abstractions suggest an internal asynchronous coordination model.
   - These packages likely serve as glue between cognition, tools, and execution, especially where multi-step workflows need stateful coordination.

14. **Quality, evaluation, and documentation**
   - The `.reports` directory and `tests` package indicate a strong emphasis on replayable evaluation and regression testing, especially for dialogue and browser-related behavior.
   - `src/aeiva/testing/dialogue_replay.py` and the README’s replay command show that real conversation scenarios are treated as first-class test artifacts.
   - Documentation lives under `docs/` and is extensive enough to support architecture, design plans, and operational guidance.

15. **Main data flow to capture in a diagram**
   - User input enters through a channel adapter or sensor.
   - It is interpreted by cognition, which consults memory, world model, goals, and current state.
   - The agent decides on an action or tool call, possibly invoking LLM providers and external tools.
   - Results are persisted back into memory/storage and returned through the originating channel.
   - For realtime or browser-heavy tasks, the flow detours through dedicated realtime or browser subsystems before returning to the core loop.

Main entry points: [`src/aeiva/cognition`](https://github.com/chatsci/aeiva/tree/main/src/aeiva/cognition) (Cognition), [`src/aeiva/tool`](https://github.com/chatsci/aeiva/tree/main/src/aeiva/tool) (Tools), [`src/aeiva/action`](https://github.com/chatsci/aeiva/tree/main/src/aeiva/action) (Action), [`src/aeiva/command/aeiva_gateway.py`](https://github.com/chatsci/aeiva/blob/main/src/aeiva/command/aeiva_gateway.py) (Gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_agent(("Agent<br/>runtime core"))
  node_perception["Perception<br/>stimulus ingest"]
  node_cognition["Cognition<br/>reasoning pipeline"]
  node_action["Action<br/>execution planning"]
end

subgraph group_interfaces["Interfaces"]
  node_command["Commands<br/>entrypoints"]
  node_gateway["Gateway<br/>channel router<br/>[aeiva_gateway.py]"]
  node_interface["Adapters"]
  node_host["Host ctrl<br/>control plane"]
end

subgraph group_model["Model layer"]
  node_llm["LLM gateway<br/>model boundary"]
  node_realtime["Realtime<br/>live multimodal"]
end

subgraph group_execution["Execution"]
  node_tool["Tools<br/>capability exec"]
  node_browser["Browser stack<br/>web automation"]
  node_approval{{"Approval<br/>policy gate<br/>[exec_approval.py]"}}
  node_sandbox["Sandbox<br/>isolated runtime"]
end

subgraph group_state["State"]
  node_memory["Memory"]
  node_storage[("Storage<br/>persistence backends")]
  node_lifergp["LifeRPG<br/>self model"]
  node_society["Society<br/>social model"]
  node_ecs["ECS<br/>entity model"]
end

node_command -->|"launches"| node_gateway
node_gateway -->|"routes"| node_interface
node_gateway -->|"coordinates"| node_host
node_interface -->|"inputs"| node_perception
node_perception -->|"stimuli"| node_cognition
node_cognition -->|"reads/writes"| node_memory
node_memory -->|"persists"| node_storage
node_cognition -->|"consults"| node_llm
node_cognition -->|"decides"| node_action
node_action -->|"invokes"| node_tool
node_tool -->|"delegates"| node_browser
node_tool -->|"isolates"| node_sandbox
node_tool -->|"checks"| node_approval
node_llm -->|"live path"| node_realtime
node_realtime -->|"streams back"| node_interface
node_action -.->|"policy"| node_host
node_browser -.->|"secure ops"| node_approval
node_cognition -.->|"self model"| node_lifergp
node_cognition -.->|"persona"| node_society
node_cognition -.->|"structured state"| node_ecs

click node_command "https://github.com/chatsci/aeiva/tree/main/src/aeiva/command"
click node_gateway "https://github.com/chatsci/aeiva/blob/main/src/aeiva/command/aeiva_gateway.py"
click node_interface "https://github.com/chatsci/aeiva/tree/main/src/aeiva/interface"
click node_host "https://github.com/chatsci/aeiva/tree/main/src/aeiva/host"
click node_agent "https://github.com/chatsci/aeiva/tree/main/src/aeiva/agent"
click node_perception "https://github.com/chatsci/aeiva/tree/main/src/aeiva/perception"
click node_cognition "https://github.com/chatsci/aeiva/tree/main/src/aeiva/cognition"
click node_action "https://github.com/chatsci/aeiva/tree/main/src/aeiva/action"
click node_llm "https://github.com/chatsci/aeiva/tree/main/src/aeiva/llm"
click node_realtime "https://github.com/chatsci/aeiva/tree/main/src/aeiva/realtime"
click node_tool "https://github.com/chatsci/aeiva/tree/main/src/aeiva/tool"
click node_browser "https://github.com/chatsci/aeiva/tree/main/src/aeiva/tool/meta/browser_stack"
click node_approval "https://github.com/chatsci/aeiva/blob/main/src/aeiva/tool/meta/exec_approval.py"
click node_sandbox "https://github.com/chatsci/aeiva/tree/main/src/aeiva/sandbox"
click node_memory "https://github.com/chatsci/aeiva/tree/main/src/aeiva/cognition/memory"
click node_storage "https://github.com/chatsci/aeiva/tree/main/src/aeiva/storage"
click node_lifergp "https://github.com/chatsci/aeiva/tree/main/src/aeiva/liferpg"
click node_society "https://github.com/chatsci/aeiva/tree/main/src/aeiva/society"
click node_ecs "https://github.com/chatsci/aeiva/tree/main/src/aeiva/ecs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent,node_perception,node_cognition,node_action toneBlue
class node_command,node_gateway,node_interface,node_host toneAmber
class node_llm,node_realtime toneMint
class node_tool,node_browser,node_approval,node_sandbox toneRose
class node_memory,node_storage,node_lifergp,node_society,node_ecs toneIndigo
```

## Components

### Core runtime

Agent cognition, action, and perception pipeline.

- [Agent](https://github.com/chatsci/aeiva/tree/main/src/aeiva/agent): runtime core · Reusable agent runtime that ties the system together. · `src/aeiva/agent`
- [Perception](https://github.com/chatsci/aeiva/tree/main/src/aeiva/perception): stimulus ingest · Sensors and stimulus normalization for input streams. · `src/aeiva/perception`
- [Cognition](https://github.com/chatsci/aeiva/tree/main/src/aeiva/cognition): reasoning pipeline · Interpretation, brain, emotion, goal, thought, reward, world model, and mind management. · `src/aeiva/cognition`
- [Action](https://github.com/chatsci/aeiva/tree/main/src/aeiva/action): execution planning · Plans, tasks, skills, procedures, steps, and statuses. · `src/aeiva/action`

### Interfaces

User-facing channels and gateway entrypoints.

- [Commands](https://github.com/chatsci/aeiva/tree/main/src/aeiva/command): entrypoints · Top-level orchestration and CLI entrypoints. · `src/aeiva/command`
- [Gateway](https://github.com/chatsci/aeiva/blob/main/src/aeiva/command/aeiva_gateway.py): channel router · Unified channel selection and wiring boundary. · `src/aeiva/command/aeiva_gateway.py`
- [Adapters](https://github.com/chatsci/aeiva/tree/main/src/aeiva/interface): channel adapters · Terminal, Slack, and WhatsApp gateway adapters. · `src/aeiva/interface`
- [Host ctrl](https://github.com/chatsci/aeiva/tree/main/src/aeiva/host): control plane · Host-side daemon, router, protocol, and approval policy. · `src/aeiva/host`

### Model layer

LLM and realtime model orchestration.

- [LLM gateway](https://github.com/chatsci/aeiva/tree/main/src/aeiva/llm): model boundary · Client, API handlers, provider registry, tool loop, and metrics. · `src/aeiva/llm`
- [Realtime](https://github.com/chatsci/aeiva/tree/main/src/aeiva/realtime): live multimodal · Low-latency audio/text path with live providers and WebRTC. · `src/aeiva/realtime`

### Execution

Tooling, browser automation, sandboxing, and approval.

- [Tools](https://github.com/chatsci/aeiva/tree/main/src/aeiva/tool): capability exec · Capability registry and approved tool execution surface. · `src/aeiva/tool`
- [Browser stack](https://github.com/chatsci/aeiva/tree/main/src/aeiva/tool/meta/browser_stack): web automation · Browser runtime, session, interaction, targeting, and service dispatch. · `src/aeiva/tool/meta/browser_stack`
- [Approval](https://github.com/chatsci/aeiva/blob/main/src/aeiva/tool/meta/exec_approval.py): policy gate · Sensitive-action approval and execution gating. · `src/aeiva/tool/meta/exec_approval.py`
- [Sandbox](https://github.com/chatsci/aeiva/tree/main/src/aeiva/sandbox): isolated runtime · Docker-based isolated task execution environment. · `src/aeiva/sandbox`

### State

Memory, storage, and domain models.

- [Memory](https://github.com/chatsci/aeiva/tree/main/src/aeiva/cognition/memory): memory logic · Raw, summary, organization, cleaning, linking, and memory service layers. · `src/aeiva/cognition/memory`
- [Storage](https://github.com/chatsci/aeiva/tree/main/src/aeiva/storage): persistence backends · SQLite, Chroma, and KuzuDB persistence behind shared database abstractions. · `src/aeiva/storage`
- [LifeRPG](https://github.com/chatsci/aeiva/tree/main/src/aeiva/liferpg): self model · Identity, roles, inventory, projects, and TODOs domain model. · `src/aeiva/liferpg`
- [Society](https://github.com/chatsci/aeiva/tree/main/src/aeiva/society): social model · Persona and social-system abstractions. · `src/aeiva/society`
- [ECS](https://github.com/chatsci/aeiva/tree/main/src/aeiva/ecs): entity model · Entity-component-style structured state model. · `src/aeiva/ecs`

## Connections

- Commands → Gateway: launches · Command entrypoints select a mode and wire services.
- Gateway → Adapters: routes · Gateway dispatches to the active channel adapter.
- Gateway → Host ctrl: coordinates · Host control plane mediates runtime and policy.
- Adapters → Perception: inputs · Channel adapters feed normalized user stimuli.
- Perception → Cognition: stimuli · Perception hands interpreted input to cognition.
- Cognition → Memory: reads/writes · Cognition consults and updates memory structures.
- Memory → Storage: persists · Memory logic stores data through backend databases.
- Cognition → LLM gateway: consults · Reasoning and interpretation can call the model boundary.
- Cognition → Action: decides · Cognition produces plans and executable intent.
- Action → Tools: invokes · Planned work uses registered tools and capabilities.
- Tools → Browser stack: delegates · Meta browser tool uses the browser automation engine.
- Tools → Sandbox: isolates · Some actions execute in the sandbox boundary.
- Tools → Approval: checks · Sensitive actions require approval before execution.
- LLM gateway → Realtime: live path · Realtime providers and response strategy handle live interaction.
- Realtime → Adapters: streams back · Live audio/text responses return through the originating surface.
- Action → Host ctrl: policy · Host rules constrain command and execution behavior.
- Browser stack → Approval: secure ops · Browser automation includes explicit security gating.
- Cognition → LifeRPG: self model · Identity and life-state feed higher-level cognition.
- Cognition → Society: persona · Social modeling informs response and behavior.
- Cognition → ECS: structured state · Entity-centric modeling supports internal state organization.
