Skip to main content

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

Metadata

Release files for motosan-agent-tool 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for motosan-agent-tool 0.2.3
File Size Uploaded Provenance
motosan_agent_tool-0.2.3.tar.gz 14.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for motosan-agent-tool 0.2.3
File Interpreter ABI Platform
motosan_agent_tool-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / motosan_agent_tool-0.2.3.tar.gz

Download URL motosan_agent_tool-0.2.3.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
803d07988a4b08d45f10facf4ed4eb465452891697e924b6135aedaa375b1b15
BLAKE2b-256 checksum
How to use checksums
b6cf025cc97b207ea8258599d19d9e09e8838d6cb7b35f75475c5ea3d11973e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.6

Release files / motosan_agent_tool-0.2.3-py3-none-any.whl

Download URL motosan_agent_tool-0.2.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7f6739eb604f4766e12910d448b6280cb959c15196d98a8435779edfee715ae
BLAKE2b-256 checksum
How to use checksums
e452b0f507626070e215b336054412f8be66b8561ddfbe046e67585d05e674b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.6

Security for motosan-agent-tool 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page