Quickstart
An agent with one tool in about fifteen lines. It runs against a real model when ANTHROPIC_API_KEY or OPENAI_API_KEY is set, and against a scripted one otherwise.
use aidaemon_sdk::prelude::*;
use aidaemon_sdk::testing::{call, text, tool_calls, ScriptedProvider};
/// Today's weather for a city.
#[tool(read_only)]
async fn forecast(city: String) -> String {
format!("{city}: 21°C and sunny (synthetic data)")
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let agent = aidaemon_sdk::preset("weather")
.provider_from_env_or(scripted())
.instructions("Answer weather questions in one sentence. Use the forecast tool.")
.tool(Forecast)
.build()
.await?;
let outcome = agent.run("cli:me", "Weather in Lisbon?").await?;
println!("{}", outcome.final_text.unwrap_or_default());
Ok(())
}
// What the model says when no API key is set.
fn scripted() -> ScriptedProvider {
let lookup = call("c1", "forecast", serde_json::json!({"city": "Lisbon"}));
ScriptedProvider::new([tool_calls([lookup]), text("Lisbon is 21°C and sunny.")])
}cargo run -p aidaemon-sdk --example quickstart --features testingEverything above the scripted() helper is the real program; the helper only exists so the example runs without a key. Drop provider_from_env_or for provider_from_env in your own code.
What the preset gives you
aidaemon_sdk::preset(id) starts from working defaults, and every part can be replaced:
| Part | Default | Change with |
|---|---|---|
| Provider | none: name one | .provider(..), .provider_from_env(), .provider_from_env_or(..) |
| Model | AIDAEMON_MODEL, else the provider's default | .model(..) |
| Safeguards | authority, scope guard over the workspace, egress guard, approvals for destructive calls, redaction, untrusted-output marking | .authority(..), .approvals(..), .undeclared_writes(..), .without_default_hooks() |
| Tools | none; with a workspace, the file, search and shell tools | .tool(..), .workspace(dir) |
| Run store | in memory | .store(..), .sqlite(path) |
| Memory | none | .memory(system, turn): any MemorySystem |
| Anything else | .hook(..), .configure(|builder| ..) for the full AgentBuilder |
A coding agent confined to the current directory, with runs kept in SQLite:
let agent = aidaemon_sdk::preset("helper")
.provider_from_env()
.instructions("You maintain this repository. Verify changes with tests.")
.workspace(".") // the default file, search and shell tools, confined here
.sqlite("runs.db") // runs survive a crash or restart
.build()
.await?;What you get back
agent.run(session_id, message) returns a RunOutcome:
outcome.status—RunStatus::Completed,Interrupted,LimitReached,Stopped,Stuck, ...outcome.final_text— the answeroutcome.receipts()— a receipt per tool call: what ran, with what arguments, how it endedoutcome.usage()— token usageoutcome.state— a serializableRunStateyou can store and resume
The session id is yours to choose. With a run store attached (.sqlite(..) above), the same id continues the same conversation.
Dropping down
The preset is a convenience over Agent::builder(id). If you want full control, build the agent yourself and add each hook explicitly; the coding_agent example does exactly that. Use .allow_unguarded() on the plain builder only when you deliberately want no hooks.