use std::sync::Arc;
use oxide_agent::client::HttpOllamaClient;
use oxide_agent::session::{CompressionStrategy, Session, SessionConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = Arc::new(HttpOllamaClient::new("http://localhost:11434"));
let truncate_config = SessionConfig {
max_tokens: 8_000,
compression_threshold: 0.80,
compression_strategy: CompressionStrategy::TruncateOldest,
};
let mut session = Session::new(Arc::clone(&client), "llama3", truncate_config);
session.set_system_prompt("You are a helpful Rust expert. Keep answers concise.");
let r1 = session.ask("What is a lifetime in Rust?").await?;
println!("Turn 1: {r1}\n");
let r2 = session.ask("Can you show me a code example?").await?;
println!("Turn 2: {r2}\n");
println!(
"History: {} messages, ~{} tokens\n",
session.history().len(),
session.estimated_tokens()
);
let summarize_config = SessionConfig {
max_tokens: 32_000,
compression_threshold: 0.80,
compression_strategy: CompressionStrategy::Summarize {
model: "llama3".into(),
},
};
let mut long_session = Session::new(client, "llama3", summarize_config);
long_session.set_system_prompt("You are a Rust compiler assistant.");
for i in 1..=5 {
let reply = long_session.ask(format!("Question {i}: explain concept {i}")).await?;
println!("Long session turn {i}: {}", &reply[..reply.len().min(80)]);
}
Ok(())
}