Expand description
§llm-coding-tools-rig
Lightweight, high-performance Rig framework Tool implementations for coding tools.
§Features
- File operations - Read, write, edit, glob, grep with two access modes:
absolute::*- Unrestricted filesystem accessallowed::*- Sandboxed to configured directories
- Shell execution - Cross-platform command execution with timeout
- Web fetching - URL content retrieval with format conversion
- Todo management - Shared-state todo list tracking
- Context strings - LLM guidance text for tool usage (re-exported from core)
§Installation
Add to your Cargo.toml:
[dependencies]
llm-coding-tools-rig = "0.1"§Quick Start
Minimal runnable agent (requires OPENAI_API_KEY):
use llm_coding_tools_rig::absolute::{GlobTool, GrepTool, ReadTool};
use llm_coding_tools_rig::{BashTool, SystemPromptBuilder, TodoTools};
use rig::providers::openai;
use rig::client::{ProviderClient, CompletionClient};
use rig::completion::Prompt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let todos = TodoTools::new();
let mut pb = SystemPromptBuilder::new();
// Build agent with system prompt tracking
let client = openai::Client::from_env();
let agent = client
.agent("gpt-4o")
.tool(pb.track(ReadTool::<true>::new()))
.tool(pb.track(GlobTool::new()))
.tool(pb.track(GrepTool::<true>::new()))
.tool(pb.track(BashTool::new()))
.tool(pb.track(todos.read))
.tool(pb.track(todos.write))
.preamble(&pb.build()) // Build system prompt after tracking tools
.build();
let response = agent
.prompt("Search for TODO comments in src/")
.await?;
println!("{response}");
Ok(())
}Example preamble output (truncated):
# Environment
Working directory: /home/user/project
# Tool Usage Guidelines
## `Read` Tool
Reads files from disk.
## `Bash` Tool
Executes shell commands.§Usage
File tools come in absolute::* (unrestricted) and allowed::* (sandboxed) variants:
use llm_coding_tools_rig::absolute::{ReadTool, WriteTool};
use llm_coding_tools_rig::allowed::{ReadTool as AllowedReadTool, WriteTool as AllowedWriteTool};
use llm_coding_tools_rig::AllowedPathResolver;
use std::path::PathBuf;
let read = ReadTool::<true>::new();
let resolver = AllowedPathResolver::new([PathBuf::from("/home/user/project")]).unwrap();
let sandboxed_read: AllowedReadTool<true> = AllowedReadTool::new(resolver.clone());
let sandboxed_write = AllowedWriteTool::new(resolver);Other tools: BashTool, WebFetchTool, TodoTools.
Use SystemPromptBuilder to register tools and pass pb.build() to .preamble(). Set working_directory() so the environment section is populated.
Context strings are re-exported in llm_coding_tools_rig::context (e.g., BASH, READ_ABSOLUTE).
§Examples
# Basic toolset setup with SystemPromptBuilder
cargo run --example basic -p llm-coding-tools-rig
# Sandboxed file access with allowed::* tools
cargo run --example sandboxed -p llm-coding-tools-rig§License
Apache 2.0
Re-exports§
pub use absolute::EditArgs;pub use absolute::EditTool;pub use absolute::GlobArgs;pub use absolute::GlobTool;pub use absolute::GrepArgs;pub use absolute::GrepTool;pub use absolute::ReadArgs;pub use absolute::ReadTool;pub use absolute::WriteTool;pub use absolute::WriteToolArgs;pub use bash::BashArgs;pub use bash::BashTool;pub use todo::TodoReadArgs;pub use todo::TodoReadTool;pub use todo::TodoTools;pub use todo::TodoWriteArgs;pub use todo::TodoWriteTool;pub use webfetch::WebFetchArgs;pub use webfetch::WebFetchTool;
Modules§
- absolute
- Tools using
llm_coding_tools_core::path::AbsolutePathResolver. - allowed
- Tools using
llm_coding_tools_core::path::AllowedPathResolver. - allowed_
tools - Re-export allowed module tool types (namespaced to avoid conflicts)
- bash
- Shell command execution tool.
- context
- Tool context strings for LLM agents.
- todo
- Todo list management tools.
- webfetch
- Web content fetching tool.
Structs§
- Absolute
Path Resolver - Path resolver that requires absolute paths.
- Allowed
Path Resolver - Path resolver that restricts access to allowed directories.
- Bash
Output - Result of shell command execution.
- Glob
Output - Output from glob file matching.
- Grep
File Matches - All matches within a single file.
- Grep
Line Match - A single line match within a file.
- Grep
Output - Output from grep search.
- System
Prompt Builder - Builder that tracks tools and generates formatted system prompts.
- Todo
- A single task item.
- Todo
State - Thread-safe shared state for todo list.
- Tool
Output - Wrapper for tool output with truncation metadata.
- WebFetch
Output - Result from URL fetch operation.
Enums§
- Edit
Error - Errors specific to edit operations.
- Todo
Priority - Task priority level.
- Todo
Status - Task status.
- Tool
Error - Unified error type for all tool operations.
Traits§
- Path
Resolver - Strategy for resolving and validating file paths.
- Substitute
- Extension trait for placeholder substitution on system prompt strings.
- Tool
Context - Trait for tools that provide usage context for LLM system prompts.
Type Aliases§
- Tool
Result - Result type alias for tool operations.