← Back to Plugins
Tools

Agent Os

ying-wen By ying-wen 👁 2 views ▲ 0 votes

Agent OS: semantic execution runtime plugin for OpenClaw โ€” Effect Log, Capability Gateway, Checkpoint/Fork, Concern Streams, Liveness Monitor, A2A Communication

GitHub

Install

npm install    #

Configuration Example

{
  // Directory for SQLite database and state files
  "dataDir": "~/.openclaw/agent-os",

  // Capability Gateway settings
  "gateway": {
    "enabled": true,           // Enable tool access control
    "defaultTtlMs": 3600000,   // Token TTL: 1 hour
    "defaultMaxCalls": 200     // Max tool calls per token
  },

  // Liveness detection thresholds
  "liveness": {
    "stallThresholdMs": 300000,   // 5 minutes without activity = stall
    "loopDetectionWindow": 10,    // Check last 10 actions for loops
    "loopThreshold": 3            // 3 identical calls = loop detected
  },

  // Watchdog health check interval
  "watchdogIntervalMs": 10000,    // Check every 10 seconds

  // Agent name for A2A communication
  "agentName": "my-agent",

  // A2A authentication (optional)
  "a2a": {
    "enforceAuth": false,
    "knownTokens": {},
    "sharedSecrets": {}
  }
}

README

# Agent OS โ€” OpenClaw Plugin

> Semantic execution runtime that makes AI agents observable, recoverable, and reliable.

Agent OS runs as an [OpenClaw](https://github.com/openclaw/openclaw) plugin, injecting structured state management, self-monitoring, and recovery capabilities via the plugin hook system. **Zero core file modifications.**

## What It Does

| Primitive | Purpose |
|-----------|---------|
| **Effect Log** | Append-only record of every tool call (intent + outcome). Enables replay, auditing, loop detection. |
| **Scratch Space** | Key-value working memory with semantic annotations. Survives context compaction. |
| **Concern Streams** | Tracks beliefs (with confidence), decisions (with rationale), and constraints. |
| **Capability Gateway** | Token-based access control for tool calls (TTL, max-calls, tool patterns). |
| **Checkpoint/Fork** | State snapshots for rollback + speculative execution branches. |
| **Liveness Monitor** | Detects stalls and infinite loops. Auto-recovery via watchdog. |
| **A2A Communication** | Agent-to-agent discovery, messaging, delegation, reputation, and economics. |
| **Memory Tiers** | Hot/warm/cold/archive memory with automatic consolidation and decay. |

## Quick Start

```bash
# 1. Clone
git clone https://github.com/ying-wen/openclaw-agent-os.git
cd openclaw-agent-os

# 2. Install dependencies
pnpm install    # or npm install

# 3. Run tests (requires Node 22+)
pnpm test       # 187 tests across 13 test files
```

## Requirements

- **Node.js 22+** (required for `node:sqlite`)
- **OpenClaw** (host application, `>=2026.3.24`)

## Installation

### Option A: Install from local path

```bash
# Link the plugin to OpenClaw
openclaw plugins install /path/to/openclaw-agent-os
```

### Option B: Install from npm (after publishing)

```bash
openclaw plugins install openclaw-agent-os
```

### Option C: Development mode (symlink)

```bash
# From OpenClaw config, add local extension path
# In ~/.openclaw/openclaw.json:
{
  "plugins": {
    "entries": {
      "agent-os": {
        "enabled": true,
        "source": "/path/to/openclaw-agent-os",
        "config": {}
      }
    },
    "slots": {
      "contextEngine": "agent-os"
    }
  }
}
```

## Configuration

Add plugin config in `~/.openclaw/openclaw.json` under `plugins.entries.agent-os.config`:

```jsonc
{
  // Directory for SQLite database and state files
  "dataDir": "~/.openclaw/agent-os",

  // Capability Gateway settings
  "gateway": {
    "enabled": true,           // Enable tool access control
    "defaultTtlMs": 3600000,   // Token TTL: 1 hour
    "defaultMaxCalls": 200     // Max tool calls per token
  },

  // Liveness detection thresholds
  "liveness": {
    "stallThresholdMs": 300000,   // 5 minutes without activity = stall
    "loopDetectionWindow": 10,    // Check last 10 actions for loops
    "loopThreshold": 3            // 3 identical calls = loop detected
  },

  // Watchdog health check interval
  "watchdogIntervalMs": 10000,    // Check every 10 seconds

  // Agent name for A2A communication
  "agentName": "my-agent",

  // A2A authentication (optional)
  "a2a": {
    "enforceAuth": false,
    "knownTokens": {},
    "sharedSecrets": {}
  }
}
```

### Slot Assignment

Agent OS registers as a **context engine**. To activate it, assign the `contextEngine` slot:

```json
{
  "plugins": {
    "slots": {
      "contextEngine": "agent-os"
    }
  }
}
```

This replaces the default `"legacy"` context engine with Agent OS, enabling:
- Context injection (beliefs, state, warnings) into every LLM call
- Automatic memory consolidation after each turn
- Auto-checkpointing before compaction

## Architecture

```
openclaw-agent-os/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts              โ† Plugin entry: register hooks/tools/services/contextEngine
โ”‚   โ”œโ”€โ”€ api.ts                โ† Re-export openclaw/plugin-sdk/plugin-entry
โ”‚   โ”œโ”€โ”€ config.ts             โ† Config schema + Zod-like parsing
โ”‚   โ”œโ”€โ”€ core/                 โ† 13 core modules
โ”‚   โ”‚   โ”œโ”€โ”€ effect-log.ts         SQLite-backed tool call log
โ”‚   โ”‚   โ”œโ”€โ”€ scratch-space.ts      Key-value working memory
โ”‚   โ”‚   โ”œโ”€โ”€ concern-stream.ts     Beliefs, decisions, constraints
โ”‚   โ”‚   โ”œโ”€โ”€ capability-gateway.ts Token-based access control
โ”‚   โ”‚   โ”œโ”€โ”€ checkpoint-store.ts   State snapshots
โ”‚   โ”‚   โ”œโ”€โ”€ fork-manager.ts       Speculative execution branches
โ”‚   โ”‚   โ”œโ”€โ”€ liveness-monitor.ts   Stall/loop detection
โ”‚   โ”‚   โ”œโ”€โ”€ fallback-recovery.ts  Automated recovery strategies
โ”‚   โ”‚   โ”œโ”€โ”€ context-engine.ts     ContextEngine implementation
โ”‚   โ”‚   โ”œโ”€โ”€ economics.ts          Credit ledger for A2A
โ”‚   โ”‚   โ”œโ”€โ”€ memory-tiers.ts       Hot/warm/cold/archive memory
โ”‚   โ”‚   โ”œโ”€โ”€ memory-bridge.ts      Cross-session memory bridge
โ”‚   โ”‚   โ””โ”€โ”€ conflict-resolution.ts Belief conflict detection
โ”‚   โ”œโ”€โ”€ hooks/                โ† 9 hook handlers
โ”‚   โ”‚   โ”œโ”€โ”€ before-tool-call.ts
โ”‚   โ”‚   โ”œโ”€โ”€ after-tool-call.ts
โ”‚   โ”‚   โ”œโ”€โ”€ before-prompt-build.ts
โ”‚   โ”‚   โ”œโ”€โ”€ session-lifecycle.ts
โ”‚   โ”‚   โ”œโ”€โ”€ agent-lifecycle.ts
โ”‚   โ”‚   โ”œโ”€โ”€ before-compaction.ts
โ”‚   โ”‚   โ”œโ”€โ”€ after-compaction.ts
โ”‚   โ”‚   โ”œโ”€โ”€ subagent-hooks.ts
โ”‚   โ”‚   โ””โ”€โ”€ shared-context.ts     Type definitions
โ”‚   โ”œโ”€โ”€ tools/
โ”‚   โ”‚   โ””โ”€โ”€ agent-os-state.ts     LLM-facing tool (16 actions)
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ””โ”€โ”€ watchdog.ts           Background health monitor
โ”‚   โ””โ”€โ”€ a2a/                  โ† Agent-to-Agent communication
โ”‚       โ”œโ”€โ”€ client.ts             HTTP client for remote agents
โ”‚       โ”œโ”€โ”€ endpoints.ts          Incoming request handlers
โ”‚       โ”œโ”€โ”€ auth.ts               HMAC authentication
โ”‚       โ”œโ”€โ”€ reputation.ts         Agent reliability tracking
โ”‚       โ”œโ”€โ”€ social.ts             Social graph management
โ”‚       โ””โ”€โ”€ types.ts              A2A protocol types
โ”œโ”€โ”€ tests/                    โ† 13 test files, 187+ tests
โ”œโ”€โ”€ docs/
โ”‚   โ””โ”€โ”€ architecture.md
โ”œโ”€โ”€ openclaw.plugin.json      โ† Plugin manifest
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ vitest.config.ts
โ””โ”€โ”€ LICENSE
```

## Development Workflow

### Running Tests

```bash
# All tests (sequential, required for SQLite thread safety)
pnpm test

# Watch mode
pnpm test:watch

# Type checking
pnpm typecheck
```

Tests use `pool: "forks"` with `maxForks: 1` because SQLite `DatabaseSync` is not thread-safe across Vitest worker threads.

### Test Files

| File | Coverage |
|------|----------|
| `core-modules.test.ts` | Effect Log, Scratch Space, Checkpoints, Streams, Liveness, Fork, Gateway |
| `gateway-interception.test.ts` | Capability Gateway token validation |
| `liveness-detection.test.ts` | Stall/loop detection scenarios |
| `recovery-replay.test.ts` | Checkpoint restore + replay |
| `fallback-recovery.test.ts` | Automated recovery strategies |
| `context-injection.test.ts` | Context engine prompt injection |
| `subagent-integration.test.ts` | Multi-agent context propagation |
| `new-features.test.ts` | Conflict detection, enhanced gateway |
| `a2a-endpoints.test.ts` | A2A HTTP endpoints |
| `a2a-auth.test.ts` | HMAC authentication |
| `scheduler-economics-memory.test.ts` | Credits, memory tiers |
| `e2e-full-pipeline.test.ts` | End-to-end pipeline |
| `e2e-stress.test.ts` | Stress testing |

### Adding a New Feature

1. Write tests in `tests/`
2. Implement in `src/core/` (or appropriate subdirectory)
3. Wire into hooks/tools in `src/index.ts`
4. Run `pnpm test` to verify
5. Update `openclaw.plugin.json` if new config options are needed

### E2E Testing with OpenClaw Gateway

```bash
# 1. Start OpenClaw gateway (in another terminal)
openclaw gateway run --port 18789

# 2. Connect an agent
openclaw agent

# 3. Use the agent_os_state tool to verify
#    Actions: status, set_state, get_state, add_belief, remember, recall, etc.
```

## Tool: agent_os_state

The plugin registers an `agent_os_state` tool with 16 actions:

| Action | Description |
|--------|-------------|
| `set_state` | Set a key-value pair in scratch space |
| `get_state` | Get a value by key |
| `list_state` | List all state entries |
| `remember` | Store a fact with semantic annotation |
| `recall` | Search memories by query |
| `add_belief` | Record a belief with confidence score |
| `add_decision` | Record a decision with rationale and alternatives |
| `status` | Full health report (liveness, streams, state, effects) |
| `a2a_discover` | Discover a remote agent's capabilities |
| `a2a_send` | Send a message to a remote agent |
| `a2a_delegate` | Delegate a task to a remote agent |
| `interrupt_child` | Interrupt a child agent session |
| `balance` | Check credit balance (A2A economics) |
| `settle` | Settle a task payment |
| `recall_memory` | Search across all memory tiers |
| `consolidate_memory` | Trigger memory consolidation |

## Hook Integration

Agent OS hooks into the following OpenClaw lifecycle events:

| Hook | What It Does |
|------|-------------|
| `before_tool_call` | Log intent to Effect Log, check Capability Gateway token |
| `after_tool_call` | Record completion, update liveness monitor |
| `before_prompt_build` | Inject context (beliefs, warnings, state) into system prompt |
| `session_start` | Initialize concern stream for the session |
| `agent_end` | Auto-checkpoint scratch space + effect log |
| `before_compaction` | Snapshot state before compaction |
| `after_compaction` | Create post-compaction checkpoint |
| `subagent_spawning` | Propagate parent context to child agent |
| `subagent_ended` | Merge child results, detect belief conflicts |

## Publishing

```bash
# Bump version
npm version patch  # or minor/major

# Publish to npm
npm publish

# Users can then install via:
openclaw plugins install openclaw-agent-os
```

## License

MIT
tools

Comments

Sign in to leave a comment

Loading comments...