Author's bio: ππ Hi, I'm CryptoPatrick! I'm currently enrolled as an Undergraduate student in Mathematics, at Chalmers & the University of Gothenburg, Sweden. If you have any questions or need more info, then please join my Discord Channel: AiMath
π Important Notices
- Framework Support: Currently designed for Rig agents, but extensible to other frameworks
- Storage: Uses SQLite for persistent storage with full-text search capabilities
- Inspired by Atuin: Brings the power of Atuin's searchable shell history to AI agents
π€ What is AgentSmith
agentsmith is a Rust library that provides AI agents with persistent, fuzzy-searchable, metadata-rich memory that survives process restarts. Inspired by Atuin for shell history, AgentSmith ensures your agents never forget past conversations.
Built specifically for Rig agents, AgentSmith wraps your existing agents with a memory layer that automatically:
- Records all conversations to a SQLite database
- Enables fuzzy search across historical interactions
- Provides session management for organizing conversations
- Allows agents to recall relevant context from past discussions
Use Cases
- Persistent AI Assistants: Build chatbots that remember users across sessions
- Context-Aware Agents: Enable agents to reference past conversations naturally
- Conversation Analytics: Search and analyze agent interactions over time
- Session Management: Organize conversations by session for different contexts
- Agent Memory Research: Experiment with long-term memory for AI agents
π· Features
agentsmith provides a complete memory layer for AI agents with persistent storage and intelligent retrieval:
π§ Core Functionality
- Persistent History: Automatic storage of all agent interactions in SQLite
- Fuzzy Search: Full-text search across conversation history with relevance ranking
- Session Management: Group conversations into sessions for different contexts
- Metadata Tracking: Store timestamps, roles, and custom metadata with each interaction
π§ Memory Capabilities
- Automatic Recording: All agent interactions are automatically saved
- Smart Retrieval: Retrieve recent messages or search by content
- Context Injection: Automatically include relevant past context in conversations
- Cross-Session Search: Search across all conversations or within specific sessions
π€ Smart Agent Features
- Transparent Wrapping: Drop-in wrapper for existing Rig agents
- Automatic Context: Agents automatically recall relevant past interactions
- Session Summaries: Generate summaries of conversation sessions
- Conversation History: Access chronological history of interactions
πΎ Persistence
- SQLite Storage: Reliable, file-based persistence with no external dependencies
- Migration Support: Built-in database schema migrations
- Session Continuity: Resume conversations across process restarts
- Export Capabilities: Import/export conversation history
π Architecture
- π Overall Architecture
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Application (CLI/Backend/App) β
β Single call: smart_agent.chat() β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ
β SmartAgent Component β
β β’ Search history for relevant traces β
β β’ Inject past context as system message β
β β’ Call underlying Rig agent β
β β’ Log user & assistant turns with metadata β
β β’ Auto-summarize every N turns β
β β’ Track success, duration, token usage β
ββββββββββββββββ¬βββββββββββββββββββββββββββ¬βββββββββββββββββ
β β
βββββββββΌβββββββββ ββββββββββΌββββββββββ
β Rig Agent β β AgentHistory β
β β’ GPT-4/etc β β β’ SQLite Pool β
β β’ Custom LLM β β β’ FTS5 Search β
β β’ Tools β β β’ JSONL Import β
ββββββββββββββββββ β β’ Summarization β
βββββββββββ¬βββββββββ
β
ββββββββββΌ βββββββββ
β SQLite Database β
β β’ sessions β
β β’ traces β
β β’ traces_fts β
ββββββββββββββββββββ
User β SmartAgent β History Search β Rig Agent β Log Response β SQLite
- π Data Flow Diagram
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β chat("How did we fix X?") β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
ββββββββββΌ βββββββββ
β 1. FTS5 β
β Search ββββββββ
β top_k=4 β β
ββββββββββββββββββββ β
β β
β relevant β
β traces β
βΌ β
ββββββββββββββββββββββ β
β 2. Build β β
β Context ββββββ
β Messages β
βββββββββββ¬βββββββββββ
β
β system: "Relevant past...\n"
β + user: "How did we fix X?"
βΌ
ββββββββββββββββββββββ
β 3. Rig Agent β
β .chat() β
βββββββββββ¬βββββββββββ
β
β response
βΌ
ββββββββββββββββββββββ
β 4. Log Turn β
β β’ User msg β
β β’ Assistant β
β β’ Metadata β
β - duration β
β - success β
β - tokens β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β 5. Store in β
β traces table β
β + FTS5 index β
ββββββββββββββββββββββ
- πΎ Storage Layer Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β AgentHistory β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Public API β β
β β β’ new(path, session_id) β β
β β β’ log_turn(message, metadata) β Trace β β
β β β’ search(query, limit, success_only) β Vec<Trace> β β
β β β’ recent(n) β Vec<Trace> β β
β β β’ summarize_session(agent) β String β β
β β β’ import_jsonl(path) β usize β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ β
β β SQLite Pool (sqlx) β β
β β β’ Connection management β β
β β β’ Async queries β β
β β β’ Migration runner β β
β ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌβββββββββββββββββββββ
β SQLite Database (file.db) β
β βββββββββββββββββββββββββββββββββββ β
β β sessions β β
β β - id (PK) β β
β β - summary β β
β β - updated_at β β
β βββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββ β
β β traces β β
β β - id (PK) β β
β β - session_id (FK) β β
β β - role (user/assistant/sys) β β
β β - content (TEXT) β β
β β - metadata (JSON) β β
β β β’ duration_ms β β
β β β’ success β β
β β β’ tokens_used β β
β β β’ tools_called β β
β β - created_at β β
β β - embedding (future) β β
β βββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββ β
β β traces_fts (FTS5 virtual) β β
β β - role β β
β β - content β β
β β - metadata β β
β β + INSERT/UPDATE/DELETE triggersβ β
β βββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββ
- β³ Trace Lifecycle
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Message (from Rig) β
β β’ role: String β
β β’ content: String β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
β + metadata HashMap
β (duration, success, tokens)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Trace::new() β
β β’ Generate UUID β
β β’ Set timestamp β
β β’ Attach session_id β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AgentHistory::log_trace() β
β β’ Serialize metadata to JSON β
β β’ INSERT INTO traces β
β β’ FTS5 trigger auto-indexes β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Persisted in SQLite β
β β’ Queryable via FTS5 MATCH β
β β’ Ranked by relevance β
β β’ Filterable by metadata β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π How to Use
Installation
Add agentsmith to your Cargo.toml:
[]
= "0.1"
Or install with cargo:
Basic Example
use ;
use openai;
async
Advanced Usage
use ;
async
π§ͺ Examples
The repository includes several examples demonstrating different features:
# Persistent chat REPL that remembers across restarts
# Demonstrate Atuin-style search capabilities
# Import conversation logs from other sources
# Basic usage example
π§ͺ Testing
Run the test suite:
# Run all tests
# Run with output
π Documentation
Comprehensive documentation is available at docs.rs/agentsmith, including:
- API reference for all public types and functions
- Tutorial on wrapping Rig agents with persistent memory
- Examples of searching and managing conversation history
- Best practices for session management
π Author
CryptoPatrick
Keybase Verification: https://keybase.io/cryptopatrick/sigs/8epNh5h2FtIX1UNNmf8YQ-k33M8J-Md4LnAN
π£ Support
Leave a β if you think this project is cool.
π License
This project is licensed under MIT. See LICENSE for details.