pub struct Agent<M: Model> {
pub config: AgentConfig,
/* private fields */
}Expand description
An immutable agent definition.
Generic over M: Model — stores the model provider alongside config,
tool schemas, and an optional sender for tool dispatch. Conversation
history is owned externally and passed into execution methods.
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 async fn step(&self, history: &mut Vec<Message>) -> Result<AgentStep>
pub async fn step(&self, history: &mut Vec<Message>) -> 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(
&self,
history: &mut Vec<Message>,
events: UnboundedSender<AgentEvent>,
) -> AgentResponse
pub async fn run( &self, history: &mut Vec<Message>, 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<'a>(
&'a self,
history: &'a mut Vec<Message>,
) -> impl Stream<Item = AgentEvent> + 'a
pub fn run_stream<'a>( &'a self, history: &'a mut Vec<Message>, ) -> impl Stream<Item = AgentEvent> + 'a
Run the agent loop as a stream of AgentEvents.
Uses the model’s streaming API so text deltas are yielded token-by-token. Tool call responses are dispatched after the stream completes (arguments arrive incrementally and must be fully accumulated first).