Typed output
Return a model call, or an agent's final answer, as your own type. Derive Deserialize and JsonSchema and ask for it.
The request carries the schema of your type (derived with schemars), and the instructions repeat it for providers that do not enforce schemas. A reply that does not parse gets one repair attempt: the parse error goes back to the model, which answers again. A second failure is StructuredError::Invalid.
rust
use aidaemon_sdk::structured::{complete_typed, AgentStructuredExt};
use schemars::JsonSchema;
use serde::Deserialize;
/// How a support ticket should be handled.
#[derive(Deserialize, JsonSchema)]
struct Triage {
/// 1 is the most urgent.
priority: u8,
refund: bool,
}
// One model call.
let triage = complete_typed::<Triage>(&provider, request).await?;
println!("{} {}", triage.value.priority, triage.value.refund);
// An agent's final answer. Tools still run as usual;
// only the final answer must match the type.
let typed = agent.run_typed::<Triage>("support:ticket-1", "Where is my order?").await?;
println!("{}", typed.value.priority);What comes back
complete_typed::<T>(&provider, request)returnsTyped<T>:value, theresponseit was read from, theusageof every call made (the repair included) andrepaired.agent.run_typed::<T>(session_id, input)returnsTypedOutcome<T>:value, the fulloutcome(receipts, usage, state) andrepaired.run_typed_fromandresume_typeddo the same for a saved state or an interrupted run. A run that pauses again for approval ends asStructuredError::NotFinished, so you can resume it.
Both live in aidaemon_sdk::structured and need no extra feature. The structured_output test in the SDK crate runs them against the scripted provider.