Expand description
High-level agent that drives the completion ↔ tool-call loop.
An Agent wraps a CompletionModel, a system prompt, an optional set
of [Tool]s, and common sampling parameters. Call Agent::prompt for a
one-shot exchange or Agent::chat to continue an existing history.
§Agentic loop
When the model returns ModelChoice::ToolCall, the agent:
- Executes each requested tool.
- Appends the results as a user-turn message.
- Sends a new completion request.
This repeats until the model returns ModelChoice::Message or the
max_iterations limit is reached.
§Example
ⓘ
let agent = Agent::builder(model)
.preamble("You are a helpful assistant.")
.tool(calculator)
.max_tokens(1024)
.build();
let reply = agent.prompt("What is 3 * 7?").await?;
println!("{reply}");Structs§
- Agent
- A configured LLM agent.
- Agent
Builder - Fluent builder for
Agent.
Enums§
- Agent
Error - Errors that can occur while running the agentic loop.