saorsa-agent
Agent runtime for the Saorsa AI framework, providing a complete environment for AI agents to execute tools and interact with the system.
Overview
The saorsa-agent crate implements the core agent loop that enables AI models to:
- Execute tools in a controlled environment
- Manage tool sessions and state
- Handle tool execution errors and recoveries
- Provide a unified interface for multiple LLM providers
Features
Agent Core
- Tool Registry: Manages available tools and their schemas
- Session Management: Maintains context across tool calls
- Error Recovery: Handles tool failures gracefully
- Streaming Support: Processes streaming responses from LLM providers
Tool Suite
The agent comes with a comprehensive suite of built-in tools:
File Operations Tools
Read Tool (read)
Read file contents with optional line range filtering.
Usage:
With line range:
Examples:
- Read entire file:
{"file_path": "src/main.rs"} - Read lines 5-10:
{"file_path": "src/main.rs", "line_range": "5-10"} - Read from line 20 onwards:
{"file_path": "src/main.rs", "line_range": "20-"}
Write Tool (write)
Write content to files with automatic directory creation.
Usage:
Edit Tool (edit)
Perform surgical text replacements in files.
Usage:
Grep Tool (grep)
Search file contents using regex patterns.
Usage:
Find Tool (find)
Locate files by name patterns.
Usage:
Ls Tool (ls)
List directory contents with metadata.
Usage:
System Operations Tools
Bash Tool (bash)
Execute bash commands in a controlled environment.
Usage:
With working directory:
With timeout:
Quick Start
Basic Agent Usage
use ;
use AnthropicProvider;
async
Using Specific Tools
use ;
// Read a file
let read_tool = ReadTool;
let result = read_tool.execute?;
println!;
// Execute a bash command
let bash_tool = BashTool;
let result = bash_tool.execute?;
println!;
Agent Configuration
Tool Registry
The agent maintains a registry of available tools:
use Agent;
let agent = new;
let registry = agent.tool_registry;
// List all available tools
for name in registry.tool_names
// Get a specific tool
if let Some = registry.get_tool
Custom Tools
You can add custom tools to the registry:
use ;
;
// Add to registry
let mut registry = new;
registry.register_tool;
Error Handling
All tool operations return a Result:
use ToolError;
match read_tool.execute
Security Considerations
- File Operations: Restricted to the working directory tree
- Command Execution: Runs in a sandboxed environment with timeout limits
- Input Validation: All tool inputs are validated against JSON schema
- Logging: All tool executions are logged for auditability
Development
Running Tests
Integration Tests
Run the tool suite integration tests:
License
This project is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.