1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//! # aidaemon-sdk (experimental)
//!
//! One dependency for building agents on the aidaemon kernel. The kernel
//! ([`aidaemon_core`], re-exported at the crate root) owns the loop, typed
//! outcomes, receipts, limits, events and interrupt/resume. Everything else
//! is an optional module, enabled by a feature of the same name:
//!
//! | Module | Feature | What it adds |
//! |---|---|---|
//! | [`providers`] | `providers` (default) | OpenAI-compatible and Anthropic models, streaming |
//! | [`tools`] | `tools` (default) | Workspace file tools, search, sandboxed shell, web fetch, checklist |
//! | [`policies`] | `policies` (default) | Approvals, scope and egress guards, streak guard, redaction, instructions, context window, conversation compaction, memory, tracing |
//! | [`secrets`] | `secrets` (default; `keychain` for the OS store) | Secret stores whose values come out as `Secret` and are redacted from every run |
//! | [`agents`] | `agents` (default) | Agents as tools, child budgets |
//! | [`store`] | `sqlite` (default) | Durable runs on SQLite, crash recovery queries, upkeep (`store::maintenance`: planner statistics, live snapshots) |
//! | [`mcp`] | `mcp` | MCP servers as tools |
//! | [`eval`] | `eval` | YAML scenarios, N-of-M pass rates, baseline comparison |
//! | [`memory`] | `memory` (+ `fastembed`) | Long-term memory: facts, episodes, hybrid recall; every part swappable |
//! | [`events`] | `events` | The immutable event store, its payloads and the run aggregate |
//! | [`work`] | `work` | **Internal, unstable:** the daemon's goals, mandates, tasks and notifications. Not for applications; schedule your own work with [`ServiceHost`] |
//! | [`channels`] | `channels` | The `Channel` contract and the runner that connects channels to agents |
//! | [`channels::telegram`], [`channels::slack`], [`channels::discord`] | `telegram`, `slack`, `discord` | Built-in channel adapters |
//! | `channels::conformance` | `conformance` | The channel conformance kit, for your own adapter's tests |
//! | [`secrets`] | `secrets` | Where an agent keeps its secrets: the `SecretStore` trait, the OS keychain, an env file, an in-memory store |
//! | [`testing`] | `testing` | Scripted provider for tests (and Tokio's `test-util`, for paused time); the shared behavior suite (`testing::behavior`) |
//! | [`tool`] | `macros` (default) | `#[tool]`: a tool from a plain function, schema derived |
//! | [`mod@preset`] | `providers` + `policies` (default) | A short start: provider, safeguards, store and default tools in a few lines |
//! | [`structured`] | always | Typed output: a model call or an agent's final answer as your type, one repair retry |
//!
//! Background work is in the kernel, at the crate root: a [`Service`]
//! states its [`Schedule`] (every so often, every tick, continuously, or
//! daily at a UTC time) and a [`ServiceHost`] runs it, with backoff after
//! failures, one run at a time per service, and one [`ServiceEvent::Ended`]
//! per run (its number, outcome and duration) for a [`ServiceObserver`].
//! The `scheduled_worker` example drives an agent from one.
//!
//! ```no_run
//! # #[cfg(all(feature = "providers", feature = "tools", feature = "policies"))]
//! # async fn demo() -> Result<(), Box<dyn std::error::Error>> {
//! use aidaemon_sdk::prelude::*;
//! use aidaemon_sdk::{Authority, AuthorityHook};
//!
//! let workspace = tools::Workspace::new(".")?;
//! let mut builder = Agent::builder("helper")
//! .model("claude-sonnet-5-5")
//! .instructions("You maintain this repository. Verify changes with tests.")
//! .provider(providers::Anthropic::builder().api_key("<key>").build()?)
//! .hook(AuthorityHook::new(Authority::full()))
//! .hook(policies::ScopeGuard::new([workspace.root()]))
//! .hook(policies::EgressGuard::new())
//! .hook(policies::ApprovalPolicy::new(policies::ApprovalMode::DestructiveOnly))
//! .hook(policies::UntrustedOutput::default());
//! for tool in tools::default_tools(workspace) {
//! builder = builder.tool_arc(tool);
//! }
//! let agent = builder.build()?;
//!
//! let mut outcome = agent.run("cli:synthetic-user-1", "Fix the failing test").await?;
//! while let RunStatus::Interrupted { interruption } = &outcome.status {
//! println!("approve {}? (auto-approving in this example)", interruption.call.name);
//! outcome = agent.resume(outcome.state, Resolution::Approve).await?;
//! }
//! println!("{:?}: {}", outcome.status, outcome.final_text.unwrap_or_default());
//! # Ok(())
//! # }
//! ```
//!
//! See the SDK guide at <https://docs.aidaemon.ai/sdk>.
pub use *;
/// Test helpers: the kernel's scripted provider and response builders and,
/// with the `macros`, `agents` and `channels` features, the
/// [`behavior`](testing::behavior) suite every assembled agent should pass.
pub use ;
/// Write a tool as a plain function: `#[tool]` derives its JSON schema from
/// the parameters (with `schemars`) and emits a unit struct, named after the
/// function in `PascalCase`, that implements [`Tool`].
///
/// ```
/// use aidaemon_sdk::{tool, Tool};
///
/// /// Look up an order: customer, item and total.
/// #[tool(read_only)]
/// async fn lookup_order(
/// /// The order id, like `ORD-1001`.
/// order_id: String,
/// ) -> String {
/// format!("{order_id}: Acme Kettle, 45.00 (synthetic)")
/// }
///
/// let spec = LookupOrder.spec();
/// assert_eq!(spec.name, "lookup_order");
/// assert_eq!(spec.parameters["additionalProperties"], false);
/// ```
///
/// - **Description:** the function's doc comment (required; or pass
/// `description = "..."`). A parameter's doc comment becomes its
/// description in the schema.
/// - **Name:** the function's name, or `name = "..."`.
/// - **Arguments:** each parameter is one key of the argument object
/// (owned types implementing `Deserialize` and `JsonSchema`; `Option<T>`
/// is optional). `#[serde(...)]` and `#[schemars(...)]` attributes on a
/// parameter are kept. Or mark one parameter `#[args]` to take the whole
/// object as your own type (`#[derive(Deserialize, JsonSchema)]`). A
/// `&ToolContext` parameter, anywhere, receives the call's context
/// (session, cancellation, the application's `extensions`).
/// - **Returns:** `String`, `&str`, `ToolOutput`, `serde_json::Value`, or a
/// `Result` of one of them whose error displays (an error reaches the
/// model as a failed call). The function may be sync or async.
/// - **Annotations** are explicit, never guessed. With no preset a tool is
/// [`ToolAnnotations::DESTRUCTIVE`], the same conservative default as a
/// hand-written tool. `read_only`, `write` and `destructive` pick
/// [`ToolAnnotations::READ_ONLY`], [`ToolAnnotations::WRITE`] or
/// [`ToolAnnotations::DESTRUCTIVE`]; `idempotent = bool` and
/// `egress = bool` (alias `open_world`) then override that one field. A
/// read-only tool that contacts another host must say `egress = true`.
/// - **Trust:** output is untrusted unless you pass `trusted` (the result
/// is the owner's own data, not content someone else wrote).
/// - **Effects and access:** `effects = path` names a
/// `fn(&Args) -> CallEffects`, `access = path` a
/// `fn(&Args) -> AccessManifest` (with `#[args]`, `Args` is your type).
/// Without `effects` a tool gets the kernel's defaults: no effects for a
/// read-only call that is not egress; otherwise the effects its `access`
/// implies ([`CallEffects::from_access`]: a written path is a write, a
/// host an egress), so an owner's denial binds the rest of the run; and
/// unknown with neither.
/// - `timeout_secs = N` overrides `Limits::tool_timeout`; `crate = path`
/// points the generated code at a re-export of `aidaemon_sdk`.
///
/// Arguments are checked before anything runs: a call that is not an
/// object, has a key the schema does not declare, or does not deserialize
/// is refused by `validate` and answered with an error result by `call`.
pub use tool;
pub use aidaemon_providers as providers;
pub use aidaemon_tools as tools;
pub use aidaemon_policies as policies;
pub use aidaemon_secrets as secrets;
pub use aidaemon_agents as agents;
pub use aidaemon_coding_agents as coding_agents;
pub use aidaemon_store_sqlite as store;
pub use aidaemon_mcp as mcp;
pub use aidaemon_eval as eval;
pub use aidaemon_memory as memory;
pub use aidaemon_events as events;
pub use aidaemon_work as work;
pub use aidaemon_surfaces as surfaces;
/// Chat channels: the contract, the runner, and the built-in adapters.
/// The names most agents need, plus the enabled modules.