Skip to main content

Module agent

Module agent 

Source
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:

  1. Executes each requested tool.
  2. Appends the results as a user-turn message.
  3. 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.
AgentBuilder
Fluent builder for Agent.

Enums§

AgentError
Errors that can occur while running the agentic loop.