Skip to main content

Agent

Struct Agent 

Source
pub struct Agent<M: Model> {
    pub config: AgentConfig,
    /* private fields */
}
Expand description

A stateful agent execution unit.

Generic over M: Model — stores the model provider alongside config and conversation history. Callers drive execution via step() (single LLM round), run() (loop to completion), or run_stream() (yields events as a stream).

Fields§

§config: AgentConfig

Agent configuration (name, prompt, model, limits, tool_choice).

Implementations§

Source§

impl<M: Model> Agent<M>

Source

pub fn push_message(&mut self, message: Message)

Push a message into the conversation history.

Source

pub fn messages(&self) -> &[Message]

Return a reference to the conversation history.

Source

pub fn clear_history(&mut self)

Clear the conversation history, keeping configuration intact.

Source

pub async fn step<D: Dispatcher>(&mut self, dispatcher: &D) -> Result<AgentStep>

Perform a single LLM round: send request, dispatch tools, return step.

Composes a Request from config state (system prompt + history + dispatcher tools), calls the stored model, dispatches any tool calls via dispatcher.dispatch(), and appends results to history.

Source

pub async fn run<D: Dispatcher>( &mut self, dispatcher: &D, events: UnboundedSender<AgentEvent>, ) -> AgentResponse

Run the agent loop to completion, returning the final response.

Wraps Agent::run_stream — collects all events, sends each through events, and extracts the Done response. The event sender allows callers (like Runtime) to observe execution without reimplementing the step loop.

Source

pub fn run_stream<'a, D: Dispatcher + 'a>( &'a mut self, dispatcher: &'a D, ) -> impl Stream<Item = AgentEvent> + 'a

Run the agent loop as a stream of AgentEvents.

The canonical step loop. Calls Agent::step up to max_iterations times, yielding events as they are produced. Always finishes with a Done event containing the AgentResponse.

Auto Trait Implementations§

§

impl<M> Freeze for Agent<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Agent<M>
where M: RefUnwindSafe,

§

impl<M> Send for Agent<M>
where M: Send,

§

impl<M> Sync for Agent<M>
where M: Sync,

§

impl<M> Unpin for Agent<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for Agent<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for Agent<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.