Skip to content
Select themeDarkLightAuto
Documentation version0.5.0-alpha.2
Select languageEnglish

Connect and manage threads

An HttpAgent holds connection settings. A Thread owns one conversation’s messages, state and pending decisions. A run is one request and its update stream. Creating a thread is local; it does not retrieve server history. Two threads created with the same ID are independent local views, not automatically synchronized objects.

use ag_ui::client::{HttpAgent, Update};
use futures_util::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = HttpAgent::new("http://localhost:3000/agent")?;
let mut thread = agent.thread("conversation-1");
{
let mut run = thread.send("Hello")?;
while let Some(update) = run.next().await {
match update {
Update::Message(message) => println!("{:?}", message.change),
Update::Error(error) => eprintln!("{error}"),
Update::Done(end) => println!("{end:?}"),
_ => {}
}
}
}
let report = thread.send("Continue")?.collect_report().await;
println!("{:?}, diagnostics: {:?}", report.end, report.diagnostics);
Ok(())
}

The ? checks pending decisions and request configuration before mutation. HTTP starts on the first poll. The run borrows its thread; read additional state through run.thread(). collect_report() retains diagnostics even when the server reports success.

Continue with the component guide.

Continue with the component guide.

Continue with the component guide.