Crate llm_coding_tools_rig

Crate llm_coding_tools_rig 

Source
Expand description

§llm-coding-tools-rig

Crates.io Docs.rs

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 access
    • allowed::* - 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§

AbsolutePathResolver
Path resolver that requires absolute paths.
AllowedPathResolver
Path resolver that restricts access to allowed directories.
BashOutput
Result of shell command execution.
GlobOutput
Output from glob file matching.
GrepFileMatches
All matches within a single file.
GrepLineMatch
A single line match within a file.
GrepOutput
Output from grep search.
SystemPromptBuilder
Builder that tracks tools and generates formatted system prompts.
Todo
A single task item.
TodoState
Thread-safe shared state for todo list.
ToolOutput
Wrapper for tool output with truncation metadata.
WebFetchOutput
Result from URL fetch operation.

Enums§

EditError
Errors specific to edit operations.
TodoPriority
Task priority level.
TodoStatus
Task status.
ToolError
Unified error type for all tool operations.

Traits§

PathResolver
Strategy for resolving and validating file paths.
Substitute
Extension trait for placeholder substitution on system prompt strings.
ToolContext
Trait for tools that provide usage context for LLM system prompts.

Type Aliases§

ToolResult
Result type alias for tool operations.