Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rig-memory-tool-example

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.

Prerequisites

  • Rust 2024 edition (1.85+)
  • An Anthropic API key

Run

ANTHROPIC_API_KEY=sk-... cargo run

Usage

> remember that we use conventional commits
> how should I format my commit messages?
> quit

Memories persist in memories.json across runs.

Test

cargo test

Architecture

User 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.rsMemoryStore, SaveMemoryTool, prompt helpers, tests
  • main.rs — REPL loop wiring the agent to the memory tool

About

A simple example for using context memory with Rig-rs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages