|
| 1 | +--- |
| 2 | +sidebar_position: 5 |
| 3 | +title: "Right Agent Persistent Memory with Hindsight | Integration Guide" |
| 4 | +description: "Add persistent memory to Right Agent — closed-box AI agents that run Claude Code inside OpenShell sandboxes. One Telegram bot per agent, with a per-chat Claude Code session over a shared, chat-tagged Hindsight bank. Hindsight is the native memory provider, selected during `right init`." |
| 5 | +--- |
| 6 | + |
| 7 | +# Right Agent |
| 8 | + |
| 9 | +Persistent memory for [Right Agent](https://github.com/onsails/right-agent) using [Hindsight](https://hindsight.vectorize.io). |
| 10 | + |
| 11 | +Right Agent runs [Claude Code](https://docs.anthropic.com/en/docs/claude-code) inside [OpenShell](https://github.com/NVIDIA/OpenShell) sandboxes. Each agent is its own Telegram bot — DMs, groups, and forum topics each get their own Claude Code session, all sharing one chat-tagged Hindsight bank. |
| 12 | + |
| 13 | +Hindsight is the native, recommended memory provider — selected during `right init`. No plugin to install, no sandbox network policy to edit. |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +Install Right Agent (see the [install guide](https://github.com/onsails/right-agent/blob/master/docs/INSTALL.md)), then run the init wizard: |
| 18 | + |
| 19 | +```bash |
| 20 | +right init |
| 21 | +right up |
| 22 | +``` |
| 23 | + |
| 24 | +`right init` walks you through picking a memory provider. Choose `hindsight` when prompted: |
| 25 | + |
| 26 | +``` |
| 27 | +? memory provider: |
| 28 | +> hindsight — hindsight cloud api (recommended) |
| 29 | + file — local MEMORY.md (no cloud dependency) |
| 30 | +? hindsight api key: <paste your key, or press Enter to use HINDSIGHT_API_KEY at runtime> |
| 31 | +? hindsight bank id (default: my-agent): <press Enter to accept> |
| 32 | +``` |
| 33 | + |
| 34 | +Get an API key at [Hindsight Cloud](https://ui.hindsight.vectorize.io/signup). |
| 35 | + |
| 36 | +The agent auto-retains every turn and auto-recalls relevant context on every new message. |
| 37 | + |
| 38 | +## Features |
| 39 | + |
| 40 | +- **Auto-recall** — on every new user message, queries Hindsight for memories tagged with the current Telegram chat and injects them as system context. |
| 41 | +- **Auto-retain** — after every turn, queues the conversation for retention. Asynchronous and resilient; never blocks the agent. |
| 42 | +- **Explicit tools** — `memory_retain`, `memory_recall`, and `memory_reflect` MCP tools for when automatic isn't enough. |
| 43 | +- **Per-chat tagging** — DMs, groups, and forum topics share one bank but each conversation only sees its own memories plus untagged globals. |
| 44 | +- **Resilient writes** — local SQLite retain queue plus circuit breaker; pending writes replay automatically when Hindsight is reachable again. |
| 45 | +- **No plugin, no policy edits** — Hindsight is built into Right Agent's MCP aggregator on the host. The sandbox needs no Hindsight-specific egress rule. |
| 46 | +- **Bundled `rightmemory` skill** — tells the agent when to use each tool and what belongs in memory vs. in its identity files (`IDENTITY.md`, `USER.md`, `TOOLS.md`). |
| 47 | + |
| 48 | +## How It Works |
| 49 | + |
| 50 | +### Memory flow |
| 51 | + |
| 52 | +- **On every new user message**, Right Agent recalls memories tagged with the current Telegram chat and injects them into the agent's system prompt under a `## Memory` section. Recalled content is wrapped as untrusted external context to defend against prompt injection from memory writes. |
| 53 | +- **After every turn**, the conversation is queued for retention. If Hindsight is unreachable, the entry sits in a local SQLite queue and retries with backoff — the agent never blocks on memory writes. |
| 54 | +- **The agent can also call retain, recall, and reflect directly** via the memory MCP tools when automatic behavior isn't enough. |
| 55 | + |
| 56 | +### Per-chat scoping |
| 57 | + |
| 58 | +One Hindsight bank per agent (set at `right init`, defaults to the agent name). Within that bank, every memory is tagged with the originating Telegram chat (`chat:<chat_id>`), and recall queries with `tags_match: "any"` — so a 1:1 DM, a group, and a forum topic each see their own memories plus any untagged globals. Group conversations don't bleed into 1:1s, but the agent keeps a shared baseline of facts that apply everywhere. |
| 59 | + |
| 60 | +### Where the Hindsight client runs |
| 61 | + |
| 62 | +Right Agent's MCP aggregator runs on the host — outside the sandbox — and is the only process that talks to the Hindsight API. Agents inside the sandbox call `memory_retain`, `memory_recall`, and `memory_reflect` over the aggregator's per-agent MCP endpoint, and the aggregator makes the Hindsight calls from the host. The sandbox network policy needs no Hindsight-specific egress rule, and Hindsight credentials never enter the sandbox. |
| 63 | + |
| 64 | +## Memory Tools |
| 65 | + |
| 66 | +The aggregator exposes three memory tools to every Hindsight-mode agent: |
| 67 | + |
| 68 | +| Tool | Purpose | |
| 69 | +|---|---| |
| 70 | +| `mcp__right__memory_retain(content, context)` | Save a fact permanently with a short label (`"user preference"`, `"api format"`, etc.). | |
| 71 | +| `mcp__right__memory_recall(query)` | Ranked semantic + keyword + graph search across the agent's memory. | |
| 72 | +| `mcp__right__memory_reflect(query)` | Deep analysis across memories — synthesize patterns, compare past decisions. | |
| 73 | + |
| 74 | +The bundled `rightmemory` skill tells the agent when to reach for each one and what belongs in memory rather than in the agent's identity files. |
| 75 | + |
| 76 | +## Configuration |
| 77 | + |
| 78 | +`right init` writes the Hindsight configuration into `~/.right/agents/<name>/agent.yaml`: |
| 79 | + |
| 80 | +```yaml |
| 81 | +memory: |
| 82 | + provider: hindsight |
| 83 | + api_key: hs_live_xxxxxxxxxxxxxxxx # or omit to use HINDSIGHT_API_KEY env var |
| 84 | + bank_id: my-agent # defaults to the agent name |
| 85 | + recall_budget: 8000 # optional, token budget for auto-recall |
| 86 | +``` |
| 87 | +
|
| 88 | +To change any of these later, edit the file and run `right restart <agent>`. To switch an existing agent between providers, run `right agent config <agent>` and re-run the wizard. |
| 89 | + |
| 90 | +### Using an environment variable |
| 91 | + |
| 92 | +If you'd rather keep the API key out of `agent.yaml`, leave `api_key` empty and set `HINDSIGHT_API_KEY` in the environment where `right up` runs: |
| 93 | + |
| 94 | +```bash |
| 95 | +export HINDSIGHT_API_KEY=hs_live_xxxxxxxxxxxxxxxx |
| 96 | +right up |
| 97 | +``` |
| 98 | + |
| 99 | +The aggregator reads `HINDSIGHT_API_KEY` at startup and uses it as the fallback for any agent whose `agent.yaml` doesn't set `memory.api_key`. |
| 100 | + |
| 101 | +## Troubleshooting |
| 102 | + |
| 103 | +**`Memory: degraded` shown in `/doctor` or in the Telegram chat.** The resilient client's circuit breaker tripped after repeated upstream errors. Pending retains are queued locally and replay when the circuit closes. Check Hindsight Cloud status and verify the API key is still valid. |
| 104 | + |
| 105 | +**Memories not appearing after restart.** Verify `memory.bank_id` in `~/.right/agents/<name>/agent.yaml` matches the bank you previously wrote to. The default is the agent name; if you edited it manually, restarts pick up the new value and won't see memories under the old bank. |
| 106 | + |
| 107 | +**`HINDSIGHT_API_KEY` ignored.** The `memory.api_key` field in `agent.yaml` takes precedence over the environment variable. Leave `api_key` empty (or remove it) to fall back to `HINDSIGHT_API_KEY`. |
| 108 | + |
| 109 | +**Quota exhausted.** Right Agent surfaces a chat-level notice when Hindsight returns a quota error. Writes are dropped while quota is exhausted; reads keep working. Top up at [Hindsight Cloud](https://ui.hindsight.vectorize.io) and queued retains catch up on the next successful write. |
| 110 | + |
| 111 | +**Switching from `file` to `hindsight` (or vice versa).** Run `right agent config <agent>` and re-run the wizard, then `right restart <agent>`. An existing local `MEMORY.md` is preserved but ignored while in Hindsight mode; switching back surfaces it again. |
| 112 | + |
| 113 | +## Links |
| 114 | + |
| 115 | +- [Right Agent on GitHub](https://github.com/onsails/right-agent) |
| 116 | +- [Install guide](https://github.com/onsails/right-agent/blob/master/docs/INSTALL.md) |
| 117 | +- [Hindsight Cloud signup](https://ui.hindsight.vectorize.io/signup) |
0 commit comments