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: AgentConfigAgent configuration (name, prompt, model, limits, tool_choice).
Implementations§
Source§impl<M: Model> Agent<M>
impl<M: Model> Agent<M>
Sourcepub fn push_message(&mut self, message: Message)
pub fn push_message(&mut self, message: Message)
Push a message into the conversation history.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear the conversation history, keeping configuration intact.
Sourcepub async fn step<D: Dispatcher>(&mut self, dispatcher: &D) -> Result<AgentStep>
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.
Sourcepub async fn run<D: Dispatcher>(
&mut self,
dispatcher: &D,
events: UnboundedSender<AgentEvent>,
) -> AgentResponse
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.
Sourcepub fn run_stream<'a, D: Dispatcher + 'a>(
&'a mut self,
dispatcher: &'a D,
) -> impl Stream<Item = AgentEvent> + 'a
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.