use troupekit::agent::Limits;
use troupekit::prelude::*;
const MODEL: &str = "anthropic/claude-haiku-5-5";
async fn capped(max_tokens: u32) -> Result<BuiltAgent, KitError> {
Agent::new("capped")
.model(MODEL)
.instructions("Answer in one sentence.")
.max_tokens(max_tokens)
.max_turns(2)
.limits(Limits {
call: Some(1_000),
run: Some(5_000),
..Limits::default()
})
.build()
.await
}
#[tokio::main]
async fn main() -> Result<(), KitError> {
for max_tokens in [4_096, 256] {
let agent = capped(max_tokens).await?;
match agent.run_with("Why do agents need spend limits?").await {
Ok(outcome) => println!(
"max_tokens {max_tokens}: answered for {} millionths of a dollar: {}",
outcome.usage().cost_usd_micros,
outcome.text()
),
Err(KitError::Paused { run_id, reason }) => {
println!("max_tokens {max_tokens}: run {run_id} paused before any model call: {reason:?}")
}
Err(other) => return Err(other),
}
}
Ok(())
}