rs-agent 1.0.0

Lattice AI Agent Framework for Rust - Build production AI agents with clean abstractions
Documentation
# rs-agent Implementation Summary

This document summarizes the Rust implementation of the go-agent framework.

## Project Structure

```
rs-agent/
├── src/
│   ├── lib.rs           # Main library exports
│   ├── error.rs         # Error types (AgentError)
│   ├── types.rs         # Core types (ToolSpec, Message, etc.)
│   ├── agent/
│   │   └── mod.rs       # Main Agent orchestrator
│   ├── tools/
│   │   └── mod.rs       # Tool trait and ToolCatalog
│   ├── memory/
│   │   └── mod.rs       # Memory system with InMemoryStore
│   └── models/
│       └── mod.rs       # LLM trait interface
├── examples/
│   ├── quickstart.rs               # Basic usage example
│   ├── tool_catalog.rs             # Custom tool registration and invocation
│   ├── memory_checkpoint.rs        # Memory, files, and checkpoint/restore
│   ├── multi_agent.rs              # Multi-agent coordination
│   └── utcp_integration.rs         # UTCP integration placeholder
├── Cargo.toml           # Dependencies and features
└── README.md            # Documentation

## Implemented Features

### ✅ Core Components

1. **Agent** (`src/agent/mod.rs`)
   - Main orchestrator for LLM interactions
   - Memory management integration
   - Tool invocation support
   - Context building with token limits
   - Checkpoint/restore capabilities

2. **Memory System** (`src/memory/mod.rs`)
   - `MemoryStore` trait for different backends
   - `InMemoryStore` implementation
   - `SessionMemory` for managing conversations
   - Vector similarity search (cosine similarity)
   - Short-term/long-term memory separation

3. **Tool System** (`src/tools/mod.rs`)
   - `Tool` trait with async support
   - `ToolCatalog` for registration and lookup
   - Thread-safe tool invocation

4. **CodeMode + Orchestrator** (`src/agent/codemode.rs`, `src/agent/mod.rs`)
   - Exposes UTCP CodeMode as `codemode.run_code`
   - Optional Codemode orchestrator to route natural language to tool chains
   - Re-exports CodeMode types for consumer convenience

5. **Model Interface** (`src/models/mod.rs`)
   - `LLM` trait for model providers
   - Support for multi-modal inputs (text + files)

6. **Type System** (`src/types.rs`)
   - `ToolSpec`, `ToolRequest`, `ToolResponse`
   - `Message` with roles (System, User, Assistant, Tool)
   - `GenerationResponse` from models
   - `AgentOptions` for configuration

### 🔧 Error Handling

- Comprehensive `AgentError` enum with `thiserror`
- Covers Model, Memory, Tool, Configuration, UTCP errors
- Custom `Result<T>` type alias

### 📚 Examples

1. **Quickstart** - Basic agent usage with mock LLM
2. **Multi-Agent** - Coordinator + specialist agents with tools
3. **UTCP Integration** - Placeholder for future UTCP support

## Key Differences from go-agent

### Rust-Specific Improvements

1. **Memory Safety**: No garbage collection, compile-time guarantees
2. **Async/Await**: Tokio runtime for efficient concurrency
3. **Type Safety**: Strong type system with generics and traits
4. **Error Handling**: Result types instead of error returns
5. **Thread Safety**: Built-in with Arc, RwLock, and Send/Sync

### Architecture Differences

- **Tool Catalog**: Uses `parking_lot::RwLock` for lock-free reads
- **Memory**: Separates short-term (cached) and long-term (persistent) storage
- **Agent**: Immutable by default with builder pattern

## Roadmap

### Next Steps

1. **LLM Providers**
   - [ ] Gemini implementation
   - [ ] Ollama implementation
   - [ ] Anthropic implementation

2. **Memory Backends**
   - [ ] PostgreSQL + pgvector
   - [ ] Qdrant vector database
   - [ ] MongoDB

3. **Advanced Features**
   - [ ] Sub-agent support (agent-as-tool)
   - [ ] UTCP provider registration
   - [ ] Streaming responses
   - [ ] Tool orchestrator (LLM-driven tool selection)
   - [ ] Code mode integration
   - [ ] Shared spaces for multi-agent coordination

4. **Testing & Documentation**
   - [ ] Integration tests
   - [ ] Benchmark suite
   - [ ] API documentation
   - [ ] Tutorial guide

## Usage

### Basic Example

```rust
use rs_agent::{Agent, AgentOptions};
use rs_agent::memory::{InMemoryStore, SessionMemory};
use std::sync::Arc;

// Create memory
let store = Box::new(InMemoryStore::new());
let memory = Arc::new(SessionMemory::new(store, 10));

// Create agent (with your LLM implementation)
let agent = Agent::new(model, memory, AgentOptions::default())
    .with_system_prompt("You are a helpful assistant");

// Generate response
let response = agent
    .generate("session_123", "What is Rust?")
    .await?;
```

### Tool Creation

```rust
use rs_agent::{Tool, ToolSpec, ToolRequest, ToolResponse, Result};
use async_trait::async_trait;

struct MyTool;

#[async_trait]
impl Tool for MyTool {
    fn spec(&self) -> ToolSpec {
        ToolSpec {
            name: "my_tool".to_string(),
            description: "Description".to_string(),
            input_schema: serde_json::json!({
                "type": "object",
                "properties": { ... }
            }),
            examples: None,
        }
    }

    async fn invoke(&self, req: ToolRequest) -> Result<ToolResponse> {
        // Implementation
        Ok(ToolResponse {
            content: "result".to_string(),
            metadata: None,
        })
    }
}
```

## Dependencies

### Core
- `tokio` - Async runtime
- `async-trait` - Async trait support
- `serde` / `serde_json` - Serialization

### Error Handling
- `thiserror` - Error derivation
- `anyhow` - Error handling utilities

### Data Structures
- `parking_lot` - Efficient locks
- `uuid` - Unique identifiers
- `chrono` - Date/time handling

### Integration
- `rs-utcp` - Universal Tool Calling Protocol
- `reqwest` - HTTP client for API calls

### Optional Features
- `google-generative-ai-rs` (gemini feature)
- `fastembed` (memory feature)
- `sqlx` (postgres feature)
- `qdrant-client` (qdrant feature)

## Testing

Run tests:
```bash
cargo test
```

Run examples:
```bash
cargo run --example quickstart
cargo run --example tool_catalog
cargo run --example memory_checkpoint
cargo run --example multi_agent
cargo run --example utcp_integration
```

Build the project:
```bash
cargo build --release
```

## Contributing

The project follows standard Rust conventions:
- Use `cargo fmt` for formatting
- Use `cargo clippy` for linting
- Add tests for new features
- Update documentation

## License

Apache 2.0 (matching go-agent)

## Acknowledgments

- Based on [go-agent]https://github.com/Protocol-Lattice/go-agent
- Integrates with [rs-utcp]https://github.com/Protocol-Lattice/rs-utcp
- Inspired by Google's ADK