use aidaemon_sdk::prelude::*;
use aidaemon_sdk::testing::{ScriptedProvider, call, text, tool_calls};
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::json;
#[tool(read_only)]
async fn lookup_order(
order_id: String,
) -> Result<String, String> {
match order_id.as_str() {
"ORD-1001" => Ok("Alice Rivera, Acme Blender, $89.00, delivered".into()),
_ => Err(format!("no order {order_id}")),
}
}
#[derive(Deserialize, JsonSchema)]
struct Escalation {
reason: String,
#[schemars(range(min = 1, max = 3))]
priority: u8,
}
#[tool(write, idempotent = false)]
async fn escalate(#[args] escalation: Escalation, ctx: &ToolContext) -> String {
format!(
"ticket for {} escalated at priority {}: {}",
ctx.session_id, escalation.priority, escalation.reason
)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!(
"{}",
serde_json::to_string_pretty(&Escalate.spec().parameters)?
);
let agent = aidaemon_sdk::preset("support")
.provider_from_env_or(scripted())
.instructions("You triage support tickets. Look the order up, then escalate damage claims.")
.tool(LookupOrder)
.tool(Escalate)
.path_free_tool("escalate")
.build()
.await?;
let ticket = "Order ORD-1001 arrived with a cracked jar.";
let outcome = agent.run("support:synthetic-ticket-1", ticket).await?;
for receipt in outcome.receipts() {
println!("[{}] {:?}", receipt.tool, receipt.status);
}
println!("{}", outcome.final_text.unwrap_or_default());
Ok(())
}
fn scripted() -> ScriptedProvider {
ScriptedProvider::new([
tool_calls([call("c1", "lookup_order", json!({"order_id": "ORD-1001"}))]),
tool_calls([call(
"c2",
"escalate",
json!({"reason": "Delivered blender has a cracked jar.", "priority": 2}),
)]),
text("I've passed your cracked-jar claim to a colleague, who will be in touch."),
])
}