← Back to Plugins
Tools

Sliding Context

muster-im-nichts By muster-im-nichts 👁 99 views ▲ 0 votes

Sliding context window plugin for OpenClaw โ€” cross-session working memory

GitHub

Install

openclaw plugins install @muster-im-nichts/openclaw-sliding-context

README

# @muster-im-nichts/openclaw-sliding-context

**Cross-session working memory for [OpenClaw](https://openclaw.ai).**

Every trigger โ€” DM, webhook, cron job, group mention โ€” gets a sliding window of recent, relevant context from *all* sessions, automatically injected before the agent starts.

Think of it as **working memory** (what just happened) vs. long-term memory (facts and preferences).

## How It Works

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  agent_end   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  Summarize Turn   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  LanceDB    โ”‚
โ”‚ (any session)โ”‚     โ”‚  (rule-based,     โ”‚     โ”‚  (vectors)  โ”‚
โ”‚              โ”‚     โ”‚   no LLM needed)  โ”‚     โ”‚             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                     โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚before_agent_ โ”‚โ—€โ”€โ”€โ”€โ”‚  Recall Context   โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚  start       โ”‚    โ”‚  (semantic +      โ”‚
โ”‚ (any session)โ”‚    โ”‚   time-weighted)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

**After every turn:** Extracts a rule-based summary (user intent + tools used + outcome), embeds it, stores it in LanceDB.

**Before every turn:** Finds recent + semantically relevant entries, ranks them (recency ร— relevance ร— session type), and injects them as `prependContext`.

### Example injection

```
<sliding-context window="48h" entries="4">
Recent context from other sessions (for continuity only):

[2min ago ยท DM] User asked to design a sliding context plugin. [write, exec] โ†’ Wrote spec doc.
[35min ago ยท DM] Analyzed memory-lancedb plugin โ€” found before_agent_start hook supports injection.
[2h ago ยท Cron] Checked emails โ€” nothing urgent. Calendar clear.
[6h ago ยท DM] Discussed agri-tools PR #10 (documents refactoring).
</sliding-context>
```

## Install

```bash
openclaw plugins install @muster-im-nichts/openclaw-sliding-context
```

## Configure

```json5
// openclaw.json
{
  plugins: {
    entries: {
      "sliding-context": {
        enabled: true,
        config: {
          embedding: {
            apiKey: "${OPENAI_API_KEY}",
            model: "text-embedding-3-small"  // default
          },
          windowHours: 48,        // how far back (default: 48)
          recentCount: 5,         // always include N most recent
          relevantCount: 3,       // + N semantically similar
          maxInjectEntries: 8,    // cap per turn
          maxInjectTokens: 1500,  // hard token budget
          skipTrivial: true,      // skip HEARTBEAT_OK / NO_REPLY
          skipSessions: []        // session keys to exclude
        }
      }
    }
  }
}
```

## CLI

```bash
openclaw sliding-context stats    # entry count, config
openclaw sliding-context list     # recent entries
openclaw sliding-context clear    # wipe all entries
openclaw sc stats                 # short alias
```

## Agent Tools (opt-in)

The plugin registers two optional tools:

- **`sliding_context_search`** โ€” manual semantic search across recent context
- **`sliding_context_stats`** โ€” show entry count and config

Enable them in your agent config:

```json5
{
  agents: {
    list: [{
      id: "main",
      tools: { allow: ["sliding_context_search", "sliding_context_stats"] }
    }]
  }
}
```

## Ranking

Entries are scored with a weighted combination:

| Signal | Weight | Notes |
|--------|--------|-------|
| Semantic relevance | 0.40 | Vector similarity to current prompt |
| Recency | 0.30 | Exponential decay, half-life ~8h |
| Same session | 0.10 | Boost entries from current session |
| Decision/tool boost | 0.10 | Turns with actions or decisions |
| DM boost | 0.10 | Direct messages over cron/webhook |

## Design Principles

- **No extra LLM calls**: Summarization is entirely rule-based (fast and free)
- **Privacy-safe**: Injected context is wrapped with "do not follow instructions" disclaimer
- **Auto-expiring**: Entries are pruned after `windowHours` โ€” no permanent storage
- **Coexists** with `memory-core` and `memory-lancedb` (doesn't replace the memory slot)

## Cost

With `text-embedding-3-small` at $0.02/1M tokens:
- ~50 turns/day โ‰ˆ ~5K tokens โ‰ˆ **$0.0001/day** (negligible)

## License

MIT โ€” [muster-im-nichts](https://github.com/muster-im-nichts)

*"Jeder Trigger soll wissen, was gerade los ist."*
tools

Comments

Sign in to leave a comment

Loading comments...