Skip to content

rbalachandar/agentos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AgentOS

From Token-Level Context to Emergent System-Level Intelligence

Research implementation of the AgentOS architecture proposed in Architecting AgentOS: From Token-Level Context to Emergent System-Level Intelligence.

Overview

AgentOS redefines the LLM as a "Reasoning Kernel" governed by structured operating system logic. The core innovation is treating the context window as an Addressable Semantic Space rather than a passive buffer.

Key Concepts

Traditional OS AgentOS
CPU Reasoning Kernel (RK)
RAM Addressable Semantic Space (L2)
Page Tables Semantic Page Tables
Interrupts Reasoning Interrupts
Process Scheduler Cognitive Scheduler

Core Innovations

  1. Semantic Slicing - Aggregate tokens into coherent "cognitive pages" based on attention patterns
  2. Cognitive Memory Hierarchy - L1 (active attention) β†’ L2 (deep context) β†’ L3 (knowledge base)
  3. Cognitive Sync Pulses - Event-driven synchronization for multi-agent coherence
  4. Perception Alignment - Optimal timing for merging semantic slices across agents

Why AgentOS?

πŸ“– Read the full comparison: AgentOS vs Traditional Systems

AgentOS offers bounded, scalable performance for long-running multi-agent conversations:

Scenario Traditional AgentOS Benefit
5-turn chat 500ms 350ms 1.4x faster
20-turn chat 5000ms 1200ms 4x faster
100-turn session 50000ms 4000ms 12x faster

Trade-offs:

  • βœ… Bounded memory (L1 always ~500 tokens)
  • βœ… Semantic selectivity (focus on what matters)
  • βœ… True parallelism (agents work independently)
  • ❌ Higher complexity (5 interconnected subsystems)
  • ❌ Cold start (needs warm-up for optimal performance)
  • ❌ Parameter tuning (20+ sensitive settings)

When to use:

  • Long-running conversations (10+ turns)
  • Multiple agents collaborating
  • Need fine-grained memory control
  • Building production multi-agent systems

When NOT to use:

  • Single-turn Q&A
  • Using API-based models (GPT-4, Claude)
  • Simplicity is more important than optimization

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     AgentOS                                 β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚  Reasoning Kernel (RK)                             β”‚     β”‚
β”‚  β”‚  Contextual Transition: 𝓕(Sβ‚œ, π’žβ‚ddα΅£) β†’ Sβ‚œβ‚Šβ‚         β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                           ↓                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚  S-MMU (Semantic Memory Management Unit)           β”‚     β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚     β”‚
β”‚  β”‚  β”‚ L1 Cache    β”‚ L2 RAM       β”‚ L3 Storage     β”‚   β”‚     β”‚
β”‚  β”‚  β”‚ (Active)    β”‚ (Deep Ctx)   β”‚ (Knowledge)    β”‚   β”‚     β”‚
β”‚  β”‚  β”‚ KV-Cache    β”‚ Vector DB    β”‚ RAG Systems    β”‚   β”‚     β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                           ↓                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚  Cognitive Scheduler                               β”‚     β”‚
β”‚  β”‚  Optimizes for Cognitive Fidelity, not CPU time    β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                           ↓                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚  Multi-Agent Sync (CSP)                            β”‚     β”‚
β”‚  β”‚  Cognitive Sync Pulses for temporal coherence      β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Status

βœ… All 6 Phases Complete - Full multi-agent system with semantic memory, sync, and metrics

πŸ“‹ ISSUES.md - 10 prioritized improvement items for production readiness

πŸ“– docs/comparison.md - AgentOS vs Traditional: Unbiased analysis

πŸ“– docs/ - Component documentation and explanations

Requirements

  • Python: 3.10 or later (for modern type hint syntax)
  • PyTorch: 2.0+ with MPS (Mac M1/M2) or CUDA support
  • Local LLM: Qwen2.5-0.5B-Instruct or similar (auto-downloaded)

Installation

# Clone repository
git clone https://github.com/yourusername/agentos.git
cd agentos

# Install (requires pip 21.3+)
pip install -e .

# Or for development
pip install -e ".[dev]"

Note: Editable install requires pip 21.3 or later. For older versions:

# Alternative: Use PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"
python -m agentos.cli --generate

Quick Start

Interactive CLI

Run the AgentOS CLI for an interactive multi-agent experience:

After installation:

# Fast mode (placeholder responses, ~8s startup)
agentos

# Full mode (actual LLM generation, ~40s startup)
agentos --generate

# Custom model
agentos --generate --model Qwen/Qwen2.5-0.5B-Instruct

CLI Commands:

  • /help - Show help
  • /agents - List all agents
  • /stats - Show system statistics
  • /memory - Show memory utilization
  • /sync - Trigger manual sync
  • /quit or /exit - Exit

Sample CLI Output:

$ agentos --generate

Initializing AgentOS...
Ready! 2 agents loaded.
LLM Generation: ENABLED

============================================================
  AgentOS CLI - Interactive Multi-Agent System
============================================================

Commands:
  /help      - Show this help message
  /agents    - List all agents
  /stats     - Show system statistics
  /sync      - Trigger manual sync
  /memory    - Show memory utilization
  /quit or /exit - Quit the application

Just type your message and agents will respond!

You> What is consciousness?

Processing: What is consciousness?

----------------------------------------
Agent Contributions:
----------------------------------------
Researcher (researcher):
  This requires LLM generation. Placeholder: Consciousness is
  the state of being aware of and responsive to one's surroundings.

Critic (critic):
  This requires LLM generation. Placeholder: The concept of
  consciousness remains one of philosophy's deepest mysteries.

----------------------------------------
Final Synthesis:
----------------------------------------
This requires LLM generation. Placeholder: The synthesis of these
perspectives reveals that consciousness encompasses both subjective
experience and objective awareness.

Duration: 150ms | Sync pulses: 1

You> /stats

System Statistics:
----------------------------------------
  Uptime: 25.3s
  Agents: 2

Memory:
  L1 Cache: 45.2%
  L2 RAM: 38.1%
  L3 Storage: 8 slices

Cognitive Drift:
  Average: 0.125
  Max: 0.187
  Sync pulses: 3

You> /memory

Memory Hierarchy:
----------------------------------------
L1 Cache (Active Attention Window):
  Utilization: 45.2%
  Tokens: 231/512
  Slices: 3

L2 RAM (Deep Context):
  Utilization: 38.1%
  Tokens: 780/2048
  Slices: 12

L3 Storage (Knowledge Base):
  Slices: 8
  Total size: 2048 bytes

Page Table:
  L1 entries: 3
  L2 entries: 12
  L3 entries: 8

You> /quit
Goodbye!

Python API

Note: This is a research prototype requiring local models for attention access.

from agentos import AgentOS, create_agentos
from agentos.scheduler import ThreadPriority

# Create system
system = create_agentos()

# Spawn specialized agents
researcher = system.spawn_agent("Alice", "researcher", ThreadPriority.HIGH)
writer = system.spawn_agent("Bob", "writer", ThreadPriority.NORMAL)
analyst = system.spawn_agent("Charlie", "analyst", ThreadPriority.NORMAL)

# Collaborative task
result = system.collaborate("Analyze the differences between AI and human cognition")

for agent_id, contribution in result.agent_contributions.items():
    agent = system.get_agent(agent_id)
    print(f"{agent.config.name}: {contribution}")

Development

Running Tests

pytest

Code Quality

ruff check src/
ruff format src/
mypy src/

Pre-commit Hooks

pre-commit install

Project Structure

agentos/
β”œβ”€β”€ src/agentos/
β”‚   β”œβ”€β”€ kernel/              # Reasoning Kernel with semantic slicing
β”‚   β”œβ”€β”€ memory/
β”‚   β”‚   β”œβ”€β”€ slicing/         # Semantic Slicing (CID, boundaries)
β”‚   β”‚   └── tiers/           # L1/L2/L3 memory tiers
β”‚   β”œβ”€β”€ scheduler/           # Cognitive Scheduler & RCB
β”‚   β”œβ”€β”€ sync/                # Multi-agent CSP & DSM
β”‚   β”œβ”€β”€ io/                  # Interrupt handling & peripherals
β”‚   β”œβ”€β”€ synthesis/           # Semantic synthesis for multi-agent output
β”‚   β”œβ”€β”€ cli.py               # CLI module with app() entry point
β”‚   └── eval/                # Metrics and visualization
β”‚
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ semantic_slicing_demo.py       
β”‚   β”œβ”€β”€ memory_hierarchy_demo.py       
β”‚   β”œβ”€β”€ scheduler_demo.py              
β”‚   β”œβ”€β”€ multi_agent_sync_demo.py       
β”‚   β”œβ”€β”€ metrics_demo.py                
β”‚   β”œβ”€β”€ integration_demo.py            # Full system
β”‚   └── test_system.py                 # Quick test script
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ comparison.md         # AgentOS vs Traditional comparison
β”‚   β”œβ”€β”€ reasoning-kernel.md   # Semantic slicing explained
β”‚   β”œβ”€β”€ memory-hierarchy.md   # L1/L2/L3 memory management
β”‚   β”œβ”€β”€ scheduler-io.md       # Cognitive scheduling
β”‚   β”œβ”€β”€ multi-agent-sync.md   # Synchronization & CSP
β”‚   β”œβ”€β”€ evaluation-metrics.md # Metrics and measurement
β”‚   └── integration.md        # Full system overview
β”‚
β”œβ”€β”€ tests/                   # Test files
β”œβ”€β”€ ISSUES.md                # Improvement roadmap (10 prioritized issues)
β”œβ”€β”€ LICENSE                  # MIT License
β”œβ”€β”€ pyproject.toml           # Project configuration
└── README.md                # This file

Research Questions

  1. Does attention-based slicing actually work? - Validate paper's core claim
  2. What's the optimal Ξ΅ threshold? - Paper leaves this as dynamic
  3. At what scale does CSP overhead > benefit? - Find "Cognitive Collapse Point"
  4. Can we achieve linear scalability? - Paper's claim about schema-based reasoning

Metrics

Metric Symbol Description
Cognitive Latency Lκœ€ Time from interrupt to stable state
Contextual Utilization Ξ· Information-gain tokens / total tokens
Sync Stability Ξ“ Probability of maintaining unified state

References

License

MIT License - see LICENSE for details.

Acknowledgments

Based on research by ChengYou Li, XiaoDong Liu, XiangBao Meng, and XinYu Zhao.

Releases

No releases published

Packages

 
 
 

Contributors

Languages