Expand description
Rhai engine setup and tool orchestration.
This module contains the core ToolOrchestrator struct that executes
Rhai scripts with access to registered tools. It implements Anthropic’s
“Programmatic Tool Calling” pattern.
§Architecture
The orchestrator uses feature-gated thread-safety primitives:
nativefeature: UsesArc<Mutex<T>>for thread-safe executionwasmfeature: UsesRc<RefCell<T>>for single-threaded WASM
§Key Components
ToolOrchestrator- Main entry point for script executionToolExecutor- Type alias for tool callback functionsdynamic_to_json- Converts Rhai values to JSON for tool input
§Example
ⓘ
use tool_orchestrator::{ToolOrchestrator, ExecutionLimits};
let mut orchestrator = ToolOrchestrator::new();
// Register a tool
orchestrator.register_executor("greet", |input| {
let name = input.as_str().unwrap_or("world");
Ok(format!("Hello, {}!", name))
});
// Execute a script that uses the tool
let result = orchestrator.execute(
r#"greet("Claude")"#,
ExecutionLimits::default()
)?;
assert_eq!(result.output, "Hello, Claude!");§Security
The Rhai engine is sandboxed by default with no access to:
- File system
- Network
- Shell commands
- System time (except via provided primitives)
All resource limits are enforced via ExecutionLimits.
Structs§
- Tool
Orchestrator - Tool orchestrator - executes Rhai scripts with registered tool access.
Functions§
- dynamic_
to_ json - Convert Rhai
Dynamicvalue toserde_json::Value.
Type Aliases§
- Shared
Counter - Thread-safe counter wrapper (native:
Arc<Mutex<usize>>) - Shared
Vec - Thread-safe vector wrapper (native:
Arc<Mutex<Vec<T>>>) - Tool
Executor - Tool executor function type (native: thread-safe
Arc<dyn Fn>)