Demonstrates an LLM agent that persists user context across sessions using rig's Tool trait.
The LLM decides when to save a memory based on the tool description and system-prompt guidelines — no manual pattern matching is needed.
Memories are stored in a JSON file and loaded into the system prompt on each request.
- Rust 2024 edition (1.85+)
- An Anthropic API key
ANTHROPIC_API_KEY=sk-... cargo run> remember that we use conventional commits
> how should I format my commit messages?
> quit
Memories persist in memories.json across runs.
cargo testUser input
│
▼
┌──────────────────────────┐
│ build_preamble() │ All memories injected into system prompt
│ render_memories_for_prompt()
└──────────┬───────────────┘
▼
┌──────────────────────────┐
│ Claude (Anthropic) │ Decides to answer or call save_memory
└──────────┬───────────────┘
▼
┌──────────────────────────┐
│ SaveMemoryTool │ Sanitizes + persists to memories.json
│ MemoryStore (JSON) │
└──────────────────────────┘
memory_tool.rs—MemoryStore,SaveMemoryTool, prompt helpers, testsmain.rs— REPL loop wiring the agent to the memory tool