llm_tools
llm_tools
Section titled “llm_tools”Lightweight, WASM-safe tool registry for LLM function-calling.
This crate provides [ToolRegistry] — a name-indexed collection of
[RegisteredTool]s — together with the [registry_from!] macro that
collects tools at compile time.
How it works
Section titled “How it works”-
Annotate a plain Rust function with
#[llm_tool](from the [llm_tool_macros] crate). The proc macro generates companion functions (<fn>_llm_tool_info,<fn>_llm_tool_exec, etc.) that expose the tool’s JSON Schema and executor. -
Use [
registry_from!] to sweep those generated functions into a [ToolRegistry]:use llm_tools::registry_from;let registry = registry_from!(get_weather, web_search);let schemas = registry.schemas(); // Vec<ToolSchema> for the LLMlet result = registry.exec("get_weather", args); -
Pass
registry.schemas()to the LLM request and route tool calls back throughregistry.exec()orregistry.exec_call().
The tool_choice submodule provides helpers for constructing the
tool_choice field accepted by most LLM APIs.
Type Aliases
Section titled “Type Aliases”ContextExecFn
Section titled “ContextExecFn”type ContextExecFn = dyn Fn + Send + Sync;Type-erased context-aware executor.
The Box<dyn Any + Send> carries a ToolContext at runtime.
Structs
Section titled “Structs”RegisteredTool
Section titled “RegisteredTool”Fields
| Field | Type | Description |
|---|---|---|
name | String | |
description | String | |
parameters | serde_json::Value | |
exec | fn(_: serde_json::Value) -> serde_json::Value | |
needs_context | bool | |
context_exec | Option<Arc<ContextExecFn>> |
ToolRegistry
Section titled “ToolRegistry”Fields
| Field | Type | Description |
|---|---|---|
by_name | HashMap<String, RegisteredTool> |
Methods
schemas
Section titled “schemas”fn schemas(&self) -> Vec<types::ToolSchema>fn exec(&self, name: &str, args: serde_json::Value) -> serde_json::Valueexec_call
Section titled “exec_call”fn exec_call(&self, call: &types::ToolCall) -> serde_json::Valuefn names(&self) -> Vec<String>