Skip to main content

agent

Function agent 

Source
pub fn agent(
    tools: impl Tool + 'static,
    client: Client,
    base_request: Request,
    history: Vec<Message>,
    history_budget: Option<usize>,
) -> BoxStream<'static, AgentEvent>
Expand description

Drive the LLM ↔ tool agentic loop and yield AgentEvents.

  • tools — the tool bundle to dispatch tool calls to
  • client — HTTP client (owned, moved into the stream)
  • request — base request config (system prompt, model, etc.; messages will be set per-turn)
  • history — initial conversation history; truncate or summarize before passing if needed

Drop the returned stream to abort.

§Example

use agentix::{AgentEvent, Request, Provider, ToolBundle};
use futures::StreamExt;

let client = reqwest::Client::new();
let request = Request::new(Provider::OpenAI, "sk-...");
let mut stream = agentix::agent(ToolBundle::default(), client, request, vec![], None);
while let Some(event) = stream.next().await {
    match event {
        AgentEvent::Token(t) => print!("{t}"),
        AgentEvent::ToolResult { name, content, .. } => println!("\n[{name}] → {content}"),
        AgentEvent::Error(e) => eprintln!("error: {e}"),
        _ => {}
    }
}