use everruns::{Agent, OpenAI};
#[everruns::tool]
async fn service_status(service: String) -> Result<String, String> {
Ok(format!("{service} is healthy"))
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = Agent::builder()
.name("lifecycle-demo")
.instructions("Always call service_status before answering a status question.")
.provider(OpenAI::from_env()?)
.model("gpt-5.6-terra")
.tool(service_status())
.on_agent_start(|context| async move {
println!(
"agent {} started session {}",
context.agent_name, context.session_id
);
})
.on_turn_start(|context| async move {
println!("turn input role: {:?}", context.input.role);
})
.on_tool_start(|context| async move {
println!("calling {} with {}", context.tool_name, context.arguments);
})
.on_tool_end(|context| async move {
println!(
"tool {} finished (success={})",
context.tool_name,
context.success()
);
})
.on_completion(|context| async move {
println!("turn completed: {:?}", context.turn.stop_reason);
})
.build()?;
let turn = agent
.session()
.send_and_wait("Is the payments service healthy?")
.await?;
println!("response: {}", turn.response);
for failure in &turn.hook_failures {
eprintln!("hook warning: {failure}");
}
Ok(())
}