← Back to Plugins
Tools

Agentsense

fraction12 By fraction12 ⭐ 1 stars 👁 25 views ▲ 0 votes

๐Ÿง  Knowledge graph memory plugin for OpenClaw โ€” your agent remembers who, what, and how things connect

GitHub

Install

npm install
```

Configuration Example

{
  "plugins": {
    "allow": ["agentsense"],
    "slots": {
      "memory": "agentsense"
    },
    "load": {
      "paths": ["~/.openclaw/extensions/agentsense"]
    },
    "entries": {
      "agentsense": {
        "enabled": true,
        "config": {
          "autoCapture": true,
          "autoRecall": true
        }
      }
    }
  }
}

README

# ๐Ÿง  AgentSense

**Your AI agent doesn't just talk. It *remembers* who, what, and how things connect.**

AgentSense is a knowledge graph memory plugin for [OpenClaw](https://github.com/openclaw/openclaw). It watches your conversations, extracts the people, projects, tools, and decisions you discuss, and weaves them into a persistent web of relationships your agent can query instantly.

Think of it as giving your agent a second brain โ€” not a pile of notes, but a map of your world.

---

## Why?

OpenClaw already has memory. It chunks your markdown files, embeds them, and searches semantically. That's good for *"what did we talk about?"*

But it can't answer *"who's connected to what?"*

AgentSense can.

```
You: Tell me about Alice

graph_search โ†’ alice chen [person]
                โ†’ partner โ†’ solar bid tool [project]
                    โ†’ competes_with โ†’ buildcost ai [company]
                    โ†’ competes_with โ†’ estimate pro [company]
                โ†’ colleague โ†’ bob martinez [person]
```

One query. Three hops. Relationships your agent never has to re-discover.

---

## How It Works

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Your Conversations                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚    Plugin Hooks     โ”‚
            โ”‚  agent_end          โ”‚
            โ”‚  before_compaction  โ”‚    โ† Captures raw text
            โ”‚  message_received   โ”‚      (instant, free)
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚  Observations Table โ”‚    โ† SQLite buffer
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚   Extraction Cron   โ”‚
            โ”‚   (Haiku, hourly)   โ”‚    โ† Reads text, finds entities,
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      writes structured data
                       โ”‚
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚   Knowledge Graph   โ”‚
            โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
            โ”‚  โ”‚Nodes โ”‚โ†’โ”‚Edges โ”‚ โ”‚    โ† People, projects, tools,
            โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚      decisions โ€” all connected
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ–ผ             โ–ผ             โ–ผ
   graph_search    /graph cmd    auto-recall
   (agent tool)    (Telegram)    (context injection)
```

**Capture** is instant and free โ€” hooks buffer raw conversation text.
**Extraction** happens asynchronously via a cron job. Bring your own model.
**Query** is local FTS5 โ€” no API calls, no embedding costs.

---

## Quick Start

### 1. Clone

```bash
git clone https://github.com/fraction12/agentsense.git ~/.openclaw/extensions/agentsense
cd ~/.openclaw/extensions/agentsense
npm install
```

### 2. Configure

Add to your `openclaw.json`:

```json
{
  "plugins": {
    "allow": ["agentsense"],
    "slots": {
      "memory": "agentsense"
    },
    "load": {
      "paths": ["~/.openclaw/extensions/agentsense"]
    },
    "entries": {
      "agentsense": {
        "enabled": true,
        "config": {
          "autoCapture": true,
          "autoRecall": true
        }
      }
    }
  }
}
```

### 3. Restart

```bash
openclaw gateway restart
```

### 4. Verify

```bash
openclaw status
# Should show: Memory: enabled (plugin agentsense)
```

That's it. AgentSense will start capturing from your conversations immediately.

---

## The Extraction Cron

AgentSense captures text automatically, but **extraction requires an LLM**. The plugin doesn't call any LLM directly โ€” instead, you set up an OpenClaw cron job that reads pending observations and writes entities.

This is by design. Your model, your cost, your schedule.

**Example cron setup** (using Haiku under Claude Max โ€” free):

Create a cron via OpenClaw that runs an isolated Haiku session hourly. The session reads pending observations from SQLite, extracts entities, and writes them back. See [CRON_SETUP.md](./CRON_SETUP.md) for the full prompt template.

Without the cron, observations accumulate but the graph stays empty. The plugin still works โ€” `memory_search` and `memory_get` function normally, and you can manually add entities via SQLite.

---

## What You Get

### `graph_search` Tool

Your agent gets a new tool for structured entity lookup:

```
graph_search("Alice")
โ†’ alice chen [person]
  โ†’ partner โ†’ solar bid tool [project]
  โ†’ colleague โ†’ bob martinez [person]
```

### `/graph` Telegram Command

```
/graph              โ†’ Stats overview
/graph search X     โ†’ Find entities
/graph recent       โ†’ Latest additions
/graph connections X โ†’ All relationships for an entity
/graph types        โ†’ Breakdown by entity type
```

### Auto-Recall

The `before_agent_start` hook automatically injects relevant entities into your agent's context before every turn. No tool call needed โ€” your agent just *knows*.

### Preserved Memory Tools

AgentSense replaces `memory-core` as the memory plugin but **re-registers `memory_search` and `memory_get`** identically. Your existing memory system works exactly as before. The graph is additive.

---

## Configuration

| Option | Default | Description |
|--------|---------|-------------|
| `autoCapture` | `true` | Buffer conversation text via hooks |
| `autoRecall` | `true` | Inject graph context before agent turns |
| `dbPath` | `~/.openclaw/memory/agentsense.db` | SQLite database location |
| `captureMinMessageLength` | `50` | Minimum text length to capture |
| `maxRecallEntities` | `5` | Max entities injected per turn |

---

## Entity Types

AgentSense recognizes: `person`, `project`, `decision`, `event`, `idea`, `preference`, `place`, `tool`, `organization`, `company`

Relationships are freeform strings: `works_on`, `partner`, `built`, `uses`, `decided`, `prefers`, `employed_by`, `located_in`, `manages`, `created` โ€” whatever the extraction model finds.

---

## Architecture Decisions

**SQLite + FTS5, not Neo4j.** A knowledge graph doesn't need a graph database. SQLite is single-file, zero-config, fast enough for thousands of nodes, and already a dependency via `better-sqlite3`.

**Cron extraction, not inline.** Early versions called Haiku directly from hooks. This required an API key, added latency, and crashed when the key expired. Moving extraction to a cron job means: zero API dependencies in the plugin, no hook failures, batch context for better extraction quality.

**Memory plugin slot.** AgentSense registers as `kind: "memory"`, replacing `memory-core` in the plugin slot. This lets it re-register the standard memory tools while adding graph capabilities. Switch back to `memory-core` anytime โ€” your graph data persists on disk untouched.

**Eager DB initialization.** The database initializes at plugin registration time, not in the service `start()` method. This prevents a race condition where hooks fire before the service is ready.

---

## Rollback

Switch back to the default memory system in 30 seconds:

```json
{
  "plugins": {
    "slots": {
      "memory": "memory-core"
    }
  }
}
```

```bash
openclaw gateway restart
```

Your graph database persists at `~/.openclaw/memory/agentsense.db`. Re-enable AgentSense anytime and everything is still there.

---

## Requirements

- OpenClaw 2026.2.17+
- Node.js 20+
- `better-sqlite3` (installed automatically)

---

## File Structure

```
agentsense/
โ”œโ”€โ”€ index.ts              # Main entry โ€” tools, hooks, commands, services
โ”œโ”€โ”€ graph-db.ts           # SQLite + FTS5 database layer
โ”œโ”€โ”€ config.ts             # Plugin configuration schema
โ”œโ”€โ”€ types.ts              # TypeScript type definitions
โ”œโ”€โ”€ extractor.ts          # Extraction prompt template + JSON parser
โ”œโ”€โ”€ hooks/
โ”‚   โ”œโ”€โ”€ auto-capture.ts   # Buffers text on agent_end / before_compaction
โ”‚   โ”œโ”€โ”€ auto-recall.ts    # Injects graph context on before_agent_start
โ”‚   โ””โ”€โ”€ message-capture.ts # Captures individual messages
โ”œโ”€โ”€ tools/
โ”‚   โ””โ”€โ”€ graph-search.ts   # graph_search agent tool
โ”œโ”€โ”€ cli/
โ”‚   โ””โ”€โ”€ graph-cli.ts      # CLI commands (stats, search, entities)
โ”œโ”€โ”€ skill/
โ”‚   โ””โ”€โ”€ SKILL.md          # Agent skill documentation
โ””โ”€โ”€ openclaw.plugin.json  # Plugin manifest
```

---

## The Honest Truth

At small scale (< 100 nodes), AgentSense is mostly redundant with OpenClaw's built-in memory search. The embedding-based system finds the same information, often with richer context.

The graph earns its keep at scale. When you have hundreds of entities with dense connections, relationship queries โ€” *"who connects to what through whom?"* โ€” become something keyword and vector search fundamentally cannot do.

The auto-recall injection is useful from day one. Relevant entities pre-loaded into every turn, zero tool calls, zero latency.

Build the graph. Let it grow. The connections compound.

---

## License

MIT

---

*Built by [Dushyant Garg](https://github.com/fraction12) & Jarvis โ€” because an agent that forgets who you know isn't really paying attention.*
tools

Comments

Sign in to leave a comment

Loading comments...