sgr-agent
Pure Rust LLM client + agent framework. Structured output, function calling, 14 file-system tools, parallel execution, 5 agent variants. Works on iOS, Android, WASM.
Quick start
[]
# Client only
= "0.7"
# Agent + all tools
= { = "0.7", = ["tools-all"] }
Structured output
use ;
use Message;
use JsonSchema;
use Deserialize;
async
Function calling
use ;
use tool;
use Message;
let llm = new;
let tools = vec!;
let = llm.tools_call_stateful.await?;
// calls[0].name == "get_weather", calls[0].arguments == {"city": "Tokyo"}
Agent with tools
use Arc;
use ;
use ToolCallingAgent;
use ;
use AgentContext;
use ToolRegistry;
use ;
use Message;
let fs = new;
let tools = new
.register
.register
.register
.register
.register
.register;
let agent = new;
let mut ctx = new;
let mut messages = vec!;
run_loop.await?;
Features
| Feature | Default | What |
|---|---|---|
oxide |
yes | OpenAI via openai-oxide (Responses API, HTTP/2) |
genai |
no | Multi-provider (Gemini, Anthropic, OpenRouter, Ollama) |
agent |
no | Agent framework: Tool trait, ToolRegistry, agent loop, 5 variants |
tools |
no | 14 file-system tools via sgr-agent-tools |
tools-eval |
no | + JavaScript eval (Boa engine) |
tools-shell |
no | + shell command execution |
tools-patch |
no | + Codex-compatible diff editing |
tools-local-fs |
no | + LocalFs backend (local filesystem) |
tools-all |
no | All of the above |
session |
no | Session persistence, loop detection, memory, hints |
app-tools |
no | Built-in tools: bash, fs, git, apply_patch |
providers |
no | Provider config (TOML), auth |
telemetry |
no | OTEL tracing → Phoenix / LangSmith |
Crate structure
sgr-agent-core 0.2 <- Tool, FileBackend, AgentContext (typed store), ToolError
^ ^ 6 lightweight deps
sgr-agent-tools sgr-agent (this crate)
0.4 LLM framework + parallel tool execution
14 tools + re-exports core + optional tools
LocalFs + MockFs
| Crate | Use for |
|---|---|
sgr-agent-core |
Building tool crates, FileBackend impls |
sgr-agent-tools |
14 tools + LocalFs + MockFs |
sgr-agent (this) |
Full framework: LLM clients, agent loop, tools |
Tools (14)
With features = ["tools-all"]:
| Tool | Type | Description |
|---|---|---|
ReadTool |
observe | Read file + trust metadata + indentation mode |
WriteTool |
act | Write file + JSON auto-repair |
DeleteTool |
act | Delete (single or batch) |
SearchTool |
observe | Smart search: fuzzy, Levenshtein, auto-expand |
ListTool |
observe | List directory |
TreeTool |
observe | Directory tree |
ReadAllTool |
observe | Batch read all files |
ShellTool |
act | Shell commands (timeout, workdir) |
ApplyPatchTool |
act | Codex-compatible diff DSL |
EvalTool |
compute | JavaScript via Boa engine |
MkDirTool |
act | Create directory (deferred) |
MoveTool |
act | Move/rename (deferred) |
FindTool |
observe | Find by name (deferred) |
Backends: LocalFs (real filesystem), MockFs (in-memory for tests).
Agent variants
| Variant | Best for |
|---|---|
ToolCallingAgent |
Any FC model (simplest, recommended) |
SgrAgent |
Structured output via discriminated union schema |
HybridAgent |
2-phase: reasoning → action (complex tasks) |
FlexibleAgent |
Weak/local models (text parsing, no FC needed) |
PlanningAgent |
Read-only exploration → structured plan |
Creating custom tools
use ;
use AgentContext;
use json_schema_for;
;
Testing with MockFs
use MockFs;
let fs = new;
fs.add_file;
let tool = ReadTool;
// tool.execute(json!({"path": "readme.md"}), &mut ctx).await
assert!;
assert_eq!;
Examples
# Structured output (gpt-4o-mini)
# Function calling
# Full agent with tools
License
MIT