Crate tool_orchestrator

Crate tool_orchestrator 

Source
Expand description

Tool Orchestrator - Rhai-based tool orchestration for AI agents

Implements Anthropic’s “Programmatic Tool Calling” pattern for token-efficient tool orchestration. Instead of sequential tool calls, AI writes Rhai scripts that orchestrate multiple tools, returning only the final result.

§Features

This crate supports multiple build targets via feature flags:

  • native (default) - Thread-safe Rust library with Arc/Mutex
  • wasm - WebAssembly bindings for browser/Node.js via wasm-bindgen

§Benefits

  • 37% token reduction - intermediate results don’t pollute context
  • Parallel execution - multiple tools in one pass
  • Complex orchestration - loops, conditionals, data processing

§Example (Native)

use tool_orchestrator::{ToolOrchestrator, ExecutionLimits};

let mut orchestrator = ToolOrchestrator::new();
orchestrator.register_executor("greet", |input| {
    Ok(format!("Hello, {}!", input.as_str().unwrap_or("world")))
});

let result = orchestrator.execute(
    r#"greet("Claude")"#,
    ExecutionLimits::default()
)?;

assert_eq!(result.output, "Hello, Claude!");

§Example (WASM)

import { WasmOrchestrator, ExecutionLimits } from 'tool-orchestrator';

const orchestrator = new WasmOrchestrator();
orchestrator.register_tool('greet', (input) => {
    const name = JSON.parse(input);
    return `Hello, ${name}!`;
});

const result = orchestrator.execute(
    'greet("Claude")',
    ExecutionLimits.quick()
);

console.log(result.output); // "Hello, Claude!"

Re-exports§

pub use engine::dynamic_to_json;
pub use engine::ToolExecutor;
pub use engine::ToolOrchestrator;
pub use sandbox::ExecutionLimits;
pub use sandbox::DEFAULT_MAX_ARRAY_SIZE;
pub use sandbox::DEFAULT_MAX_MAP_SIZE;
pub use sandbox::DEFAULT_MAX_OPERATIONS;
pub use sandbox::DEFAULT_MAX_STRING_SIZE;
pub use sandbox::DEFAULT_MAX_TOOL_CALLS;
pub use sandbox::DEFAULT_TIMEOUT_MS;
pub use sandbox::EXTENDED_MAX_OPERATIONS;
pub use sandbox::EXTENDED_MAX_TOOL_CALLS;
pub use sandbox::EXTENDED_TIMEOUT_MS;
pub use sandbox::QUICK_MAX_OPERATIONS;
pub use sandbox::QUICK_MAX_TOOL_CALLS;
pub use sandbox::QUICK_TIMEOUT_MS;
pub use types::OrchestratorError;
pub use types::OrchestratorResult;
pub use types::ToolCall;

Modules§

engine
Rhai engine setup and tool orchestration.
sandbox
Execution limits and sandboxing for safe script execution.
types
Core types for tool orchestration.