Let the model call your code safelyYou wrap a host capability with a name, purpose, typed arguments, result, and handler. The model sees when and how to call it while your app keeps control of execution.rustacademyacademy/topics/typed-toolswebsite/content-src/academy/course.mjsacademyLet the model call your code safely
You wrap a host capability with a name, purpose, typed arguments, result, and handler. The model sees when and how to call it while your app keeps control of execution.
fn()8 focused minutesNot started
Worked example
See the idea in context
use axllm::{tool, FieldType};
let search = tool("search")
.description("Search docs")
.arg("query", FieldType::string())
.handler(|args| Ok(json!(["hit"])));
Explain when to call it
The name and description orient the model toward product documentation searches.
Constrain the call
query must be a string and the result is declared as a string.
Bind trusted code
searchDocs runs in your host environment when the tool is selected.
Run itIn your own project
cargo add axllm
use axllm::{ai, ax};
use serde_json::json;
let llm = ai("openai", json!({"apiKey": std::env::var("OPENAI_API_KEY")?}))?;
let classify = ax("review:string -> sentiment:class \"positive, negative, neutral\"")?;
Set OPENAI_APIKEY in your environment before running provider-backed code.
In the ax repo
From a clone of the ax repo:
npm run example -- rust src/examples/rust/generation/basic_generation.rs