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,
conversation history, tool schemas, and an optional sender for tool dispatch.
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(&mut self) -> Result<AgentStep>
pub async fn step(&mut self) -> Result<AgentStep>
Perform a single LLM round: send request, dispatch tools, return step.
Composes a Request from config state (system prompt + history +
tool schemas), calls the stored model, dispatches any tool calls via
the ToolSender channel, and appends results to history.
Sourcepub async fn run(
&mut self,
events: UnboundedSender<AgentEvent>,
) -> AgentResponse
pub async fn run( &mut self, 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.
Sourcepub fn run_stream(&mut self) -> impl Stream<Item = AgentEvent> + '_
pub fn run_stream(&mut self) -> impl Stream<Item = AgentEvent> + '_
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.