pub struct Agent { /* private fields */ }Expand description
The ReAct loop: ask LLM, execute tools, repeat.
Agent orchestrates the interaction between an LLM provider, a tool registry,
and a transcript. It drives a loop until the model stops calling tools or the
budget (steps or transcript size) is exceeded.
§Usage
let agent = Agent::builder()
.llm(Arc::new(provider))
.tools(registry)
.system_prompt("You are a helpful assistant")
.max_steps(32)
.build()?;
let outcome = agent.run("Help me debug this file").await?;§Events
The agent emits StepEvents through an optional channel, allowing UI layers
to observe progress without coupling to internals. See StepEvent for variants.
§Isolation
Each Agent::run() call is independent. The transcript is maintained across
steps within a single run but cleared between runs. Use seed_transcript() to
carry state between runs if needed.
Implementations§
Source§impl Agent
impl Agent
pub fn builder() -> AgentBuilder
Sourcepub fn set_transcript(&mut self, transcript: Vec<Message>)
pub fn set_transcript(&mut self, transcript: Vec<Message>)
Restore transcript for multi-turn reuse. Call after run() returns
to re-seed the agent with the conversation history.
Sourcepub fn set_events(&mut self, tx: Option<UnboundedSender<StepEvent>>)
pub fn set_events(&mut self, tx: Option<UnboundedSender<StepEvent>>)
Replace the events channel. Dropping the old sender closes its
channel (letting any spawned printer task finish). Pass None to
disable event emission entirely.
Sourcepub fn confirm_plan(&mut self)
pub fn confirm_plan(&mut self)
Confirm a proposed plan, allowing execution to proceed.
Sourcepub fn reject_plan(&mut self, reason: &str)
pub fn reject_plan(&mut self, reason: &str)
Reject a proposed plan with a reason.