Crate llm_coding_tools_serdesai

Crate llm_coding_tools_serdesai 

Source
Expand description

§llm-coding-tools-serdesai

Crates.io Docs.rs

Lightweight, high-performance serdesAI 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)
  • Schema builders - Composable helpers for custom tool definitions

§Installation

Add to your Cargo.toml:

[dependencies]
llm-coding-tools-serdesai = "0.1"

§Quick Start

Minimal runnable agent (requires OPENAI_API_KEY):

use llm_coding_tools_serdesai::absolute::{GlobTool, GrepTool, ReadTool};
use llm_coding_tools_serdesai::agent_ext::AgentBuilderExt;
use llm_coding_tools_serdesai::{BashTool, SystemPromptBuilder, create_todo_tools};
use serdes_ai::prelude::*;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let (todo_read, todo_write, _state) = create_todo_tools();
    let mut pb = SystemPromptBuilder::new();

    // Build agent with tools - call .system_prompt() last
    let agent = AgentBuilder::<(), String>::from_model("openai: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(todo_read))
        .tool(pb.track(todo_write))
        .system_prompt(pb.build())  // Last, after tracking all tools
        .build();

    // Run agent with tools
    let response = agent
        .run("Search for TODO comments in src/", ())
        .await?;
    println!("{}", response.output());

    Ok(())
}

See the serdesai-basic example for a complete working setup.

§Usage

File tools come in absolute::* (unrestricted) and allowed::* (sandboxed) variants:

use llm_coding_tools_serdesai::absolute::{ReadTool, WriteTool};
use llm_coding_tools_serdesai::allowed::{ReadTool as AllowedReadTool, WriteTool as AllowedWriteTool};
use llm_coding_tools_serdesai::AllowedPathResolver;
use std::path::PathBuf;

// Unrestricted access (absolute paths)
let read = ReadTool::<true>::new();

// Sandboxed access (paths relative to allowed directories)
let allowed_paths = vec![PathBuf::from("/home/user/project"), PathBuf::from("/tmp")];
let resolver = AllowedPathResolver::new(allowed_paths).unwrap();
let sandboxed_read: AllowedReadTool<true> = AllowedReadTool::new(resolver.clone());
let sandboxed_write = AllowedWriteTool::new(resolver);

Other tools: BashTool, WebFetchTool, TaskTool, TodoReadTool, TodoWriteTool. Use SystemPromptBuilder to track tools and pass pb.build() to .system_prompt(). Set working_directory() so the environment section is populated. Use AgentBuilderExt::tool() to add tools that implement Tool<Deps> to the agent. Context strings are re-exported in llm_coding_tools_serdesai::context (e.g., BASH, READ_ABSOLUTE).

§Examples

# Basic agent setup with AgentBuilderExt
cargo run --example serdesai-basic -p llm-coding-tools-serdesai

# Sandboxed file access with allowed::* tools
cargo run --example serdesai-sandboxed -p llm-coding-tools-serdesai

§License

Apache 2.0

Re-exports§

pub use absolute::EditTool;
pub use absolute::GlobTool;
pub use absolute::GrepTool;
pub use absolute::ReadTool;
pub use absolute::WriteTool;
pub use bash::BashTool;
pub use todo::TodoReadTool;
pub use todo::TodoWriteTool;
pub use todo::create_todo_tools;
pub use webfetch::WebFetchTool;

Modules§

absolute
Tools using llm_coding_tools_core::path::AbsolutePathResolver.
agent_ext
Extension traits for integrating tools with serdes-ai AgentBuilder.
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.
convert
Type conversions between core types and serdesAI types.
todo
Todo list management tools.
webfetch
Web content fetching tool.

Structs§

AbsolutePathResolver
Re-export path resolvers from core. Path resolver that requires absolute paths.
AllowedPathResolver
Re-export path resolvers from core. 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
Re-export SystemPromptBuilder and Substitute from core. Builder that tracks tools and generates formatted system prompts.
Todo
A single task item.
TodoState
Thread-safe shared state for todo list.
ToolOutput
Re-export core types for convenience. 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
Re-export core types for convenience. Unified error type for all tool operations.

Traits§

PathResolver
Re-export path resolvers from core. Strategy for resolving and validating file paths.
Substitute
Re-export SystemPromptBuilder and Substitute from core. Extension trait for placeholder substitution on system prompt strings.
ToolContext
Re-export context module and ToolContext trait for convenience. Trait for tools that provide usage context for LLM system prompts.

Type Aliases§

ToolResult
Re-export core types for convenience. Result type alias for tool operations.