Skip to content

OS Architecture

AgentCTX is an operating system for AI agents. Like a traditional OS manages processes, memory, and I/O for programs, AgentCTX manages context, memory, tools, and trust for agents.

Traditional OSAgentCTXPurpose
Process schedulerOrchestratorDispatch and coordinate agents
Virtual memory5-layer memoryHierarchical persistence with decay
File systemKnowledge planeIndexed, searchable data
System callsCTX statementsStructured requests to the kernel
Device driversMCP backendsAbstracted tool access
KernelGatewayCentral routing and enforcement
ShellCLI (actx)Human/agent interface
Audit logSidecar translationsSigned, verifiable records
┌─────────────────────────────────────────────┐
│ Agents (Claude, Gemini, GPT, Custom) │ ← User space
├─────────────────────────────────────────────┤
│ CTX Language │ ← System call interface
├─────────────────────────────────────────────┤
│ Gateway (Middleware Pipeline) │ ← Kernel
│ ┌─────┬────────┬────────┬────────┐ │
│ │Identity│ RBAC │Budget │Routing │ ... │ ← Kernel modules
│ └─────┴────────┴────────┴────────┘ │
├─────────────────────────────────────────────┤
│ Planes │ ← Subsystems
│ ┌──────┬──────────┬────────┬───────┐ │
│ │Tools │Knowledge │Memory │Skills │ │
│ └──────┴──────────┴────────┴───────┘ │
├─────────────────────────────────────────────┤
│ Storage (CAS + SurrealDB) │ ← Disk
├─────────────────────────────────────────────┤
│ Sidecar (Trust Boundary) │ ← Audit
├─────────────────────────────────────────────┤
│ MCP Backends (GitHub, Filesystem, etc.) │ ← Hardware/Devices
└─────────────────────────────────────────────┘

The gateway is the kernel — every agent request passes through it. It enforces:

  • Identity — who is making the request
  • Authorization — what they’re allowed to do
  • Budget — how many tokens they can spend
  • Routing — which plane handler processes the request
  • Alignment — sentinel checks for behavioral deviation

The orchestrator manages multi-agent workloads:

FeatureDescription
DispatchRoute tasks to the best available agent
Process groupsGroup related agents for coordinated work
Dependency graphEnsure tasks execute in the correct order
Coherence detectionDetect when agents are duplicating work
Prompt compilationGenerate optimized prompts for dispatched agents
Lifecycle managementSpawn, monitor, and terminate agents

Like virtual memory, AgentCTX’s memory system has a hierarchy:

L1: Ephemeral ← Fast, session-only (like CPU cache)
L2: Individual ← Per-agent persistent (like RAM)
L3: Team ← Shared across team (like shared memory)
L4: Organization ← Org-wide (like network storage)
L5: Global ← Platform-wide (like cloud storage)

Memories decay over time (like LRU eviction) and can be promoted to higher layers.

NATS JetStream provides the message bus for:

  • Agent-to-agent communication (pub/sub)
  • Event distribution (memory updates, tool calls)
  • Federation (cross-organization message routing)
  • Queue workers (async task processing via broker)

The cognition layer captures how agents think, not just what they do:

+m:context "analyzing auth module" ← thinking about auth
+m:check "OWASP compliance" ← verifying security
+m:edge "injection risk in search" ← found an issue
+m:escalate "critical vulnerability" ← raising priority

These cognition traces are structured, stored, and searchable — enabling replay, audit, and cross-agent learning.

CategoryCount
Core modules12
Active modules21
Scaffolding (Rust migration)6
Deprecated (legacy fallback)4 files
Rust crates8
SurrealQL schemas10
Test files246+
Total source files306+