Skip to main content

Shared AI agent tool kit for LLM agents

Project description

motosan-agent-tool

CI

Shared AI agent tool kit — Rust, Python, and TypeScript. Provides the core Tool trait, registry, and 18 feature-gated built-in tools used by motosan-chat and crucible-agent.

Quick Start

Rust

use motosan_agent_tool::{Tool, ToolDef, ToolResult, ToolContext, ToolRegistry};
use serde_json::json;
use std::sync::Arc;

// Implement a tool
struct MyTool;

impl Tool for MyTool {
    fn def(&self) -> ToolDef {
        ToolDef {
            name: "my_tool".into(),
            description: "Does something useful".into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "query": { "type": "string" }
                },
                "required": ["query"]
            }),
        }
    }

    fn call(
        &self,
        args: serde_json::Value,
        _ctx: &ToolContext,
    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ToolResult> + Send + '_>> {
        Box::pin(async move {
            let query = args["query"].as_str().unwrap_or("");
            ToolResult::text(format!("Result for: {query}"))
        })
    }
}

// Register and use
#[tokio::main]
async fn main() {
    let registry = ToolRegistry::new();
    registry.register(Arc::new(MyTool)).await;

    let tool = registry.get("my_tool").await.unwrap();
    let ctx = ToolContext::new("user-1", "my-app");
    let result = tool.call(json!({"query": "hello"}), &ctx).await;
    println!("{:?}", result.as_text());
}

Python

from motosan_agent_tool import tool, ToolRegistry

@tool(description="Greet someone")
def greet(name: str) -> str:
    return f"Hello, {name}!"

registry = ToolRegistry()
registry.register(greet)

Design

This crate unifies the tool interfaces of motosan-chat and crucible-agent:

  • ToolDef — schema validation (type checking, enum checking, required fields)
  • ToolResult — typed content (Text | Json) + optional metadata (citation, duration_ms)
  • ToolContext — common fields (caller_id, platform, cwd) + extensible extra map
  • ToolRegistry — thread-safe async tool storage

Built-in Tools (Rust)

All tools are feature-gated. Enable individually or use all_tools to enable all.

Tool Feature Description
WebSearchTool web_search Brave Search API integration
FetchUrlTool fetch_url HTTP fetch with HTML extraction + SSRF protection
ReadFileTool read_file Local file reader with path traversal protection
ReadPdfTool read_pdf PDF text extraction (local files and URLs)
ReadSpreadsheetTool read_spreadsheet Excel (.xlsx/.xls) and CSV reader
JsEvalTool js_eval Sandboxed JS evaluation via Boa Engine
PythonEvalTool python_eval Python subprocess execution with timeout
DatetimeTool datetime Current time, date arithmetic, date diff with timezone support
CurrencyConvertTool currency_convert Live exchange rates with caching and API fallback
CostCalculatorTool cost_calculator Multi-currency cost breakdown with auto conversion
GeneratePdfTool generate_pdf Generate PDF from text/Markdown
BrowserNavigateTool browser Open URLs via agent-browser
BrowserActTool browser Click, fill, type, hover, select, check, press
BrowserReadTool browser Read text, HTML, attributes from elements
BrowserSnapshotTool browser Capture accessibility tree snapshot
BrowserScreenshotTool browser Take page screenshots
BrowserWaitTool browser Wait for navigation, selector, or network idle
BrowserAuthTool browser Save/load authentication state
BrowserTabTool browser Multi-page tab management
# Enable specific tools
[dependencies]
motosan-agent-tool = { version = "0.3", features = ["datetime", "web_search"] }

# Or enable all
motosan-agent-tool = { version = "0.3", features = ["all_tools"] }

Multi-language Support

Package Language Install
motosan-agent-tool Rust cargo add motosan-agent-tool
motosan-agent-tool Python (≥3.9) pip install motosan-agent-tool
motosan-agent-tool TypeScript npm install motosan-agent-tool

All three packages share the same API surface: Tool, ToolDef, ToolResult, ToolContent, ToolContext, ToolRegistry, ToolError.

The Python package also provides FunctionTool and a @tool decorator for defining tools from plain functions.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

motosan_agent_tool-0.2.3.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

motosan_agent_tool-0.2.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file motosan_agent_tool-0.2.3.tar.gz.

File metadata

  • Download URL: motosan_agent_tool-0.2.3.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.6

File hashes

Hashes for motosan_agent_tool-0.2.3.tar.gz
Algorithm Hash digest
SHA256 803d07988a4b08d45f10facf4ed4eb465452891697e924b6135aedaa375b1b15
MD5 48b522f3c931be2852bf13cfe8d118e9
BLAKE2b-256 b6cf025cc97b207ea8258599d19d9e09e8838d6cb7b35f75475c5ea3d11973e6

See more details on using hashes here.

File details

Details for the file motosan_agent_tool-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for motosan_agent_tool-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a7f6739eb604f4766e12910d448b6280cb959c15196d98a8435779edfee715ae
MD5 dc93d6499e372b7693a14b0c88d1dc73
BLAKE2b-256 e452b0f507626070e215b336054412f8be66b8561ddfbe046e67585d05e674b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page