Skip to main content

Crate aidaemon_core

Crate aidaemon_core 

Source
Expand description

§aidaemon-core (experimental sketch)

A small agent-loop kernel. It owns the loop, the tool contract, typed outcomes, receipts, budgets, stuck detection, and interrupt/resume. Every policy (approvals, completion checks, context strategies, memory) plugs in through Hook. Product features (channels, goals, scheduling, specialists) live outside this crate.

The loop, in one sentence: build the request, call the model, and if it asked for tools run them (read-only ones concurrently, mutating ones one at a time) and go around again; otherwise ask the stop hooks whether the answer is acceptable and finish with a typed RunOutcome.

See the SDK guide at https://docs.aidaemon.ai/sdk for the concepts, examples/kernel_tour.rs for a runnable tour of the kernel, and aidaemon-sdk’s examples/quickstart.rs for the shortest working agent.

Re-exports§

pub use redaction::RedactionScope;

Modules§

card
The typed state every status card renders from.
mandate_card
The owner’s confirmation card for a mandate as it travels in crate::OwnerApprovalRequest::warnings: five essentials the owner reads at a glance (each a "<label>: <text>" line with a label from Essential), then every other line as a detail. Here, below both the work crate that builds it and the channels that render it.
redaction
Secret redaction at the kernel boundary.

Structs§

AccessManifest
What one call will touch, declared by the tool from its arguments. Policies use it for scope checks and sandboxes for confinement. Empty means “not declared”, not “touches nothing”.
Agent
An agent is configuration: a stable id, a model, instructions, tools and hooks. It holds no per-run state, is cheap to clone, and can run many sessions concurrently.
AgentBuilder
Builder for Agent. provider and model are required, and an agent with tools must cover every Safeguard::REQUIRED safeguard (see AgentBuilder::attest and AgentBuilder::allow_unguarded).
ApprovalCard
An approval card’s content as facts, so every channel says the same thing in its own formatting: who asks, what will happen, why the owner is asked, and the one high-impact effect worth a warning.
Audio
Audio the model should hear, on a user message: base64 data in a container named the OpenAI way (ogg/opus, mp3, wav, flac, aac). Providers without audio input drop it. Debug omits the bytes.
Authority
What a run is allowed to do: a level plus an optional tool allow-list.
AuthorityHook
Enforces the granted Authority (level and tool set) on every call, and declares Safeguard::Authority so the agent builder accepts it. It never prompts: a composition root that wants approvals for some calls adds its own hook.
CallEffects
The effects of one call, declared by its tool from the arguments.
CallResult
One tool call of a run and what the model was told about it (see RunOutcome::tool_results).
CancellationToken
Re-exported so tools can observe cancellation without adding the dependency. A token which can be used to signal a cancellation request to one or more tasks.
Cooldown
An account (or one model of it) that will not answer until until.
DefaultFailover
The default FailoverPolicy.
EffectKey
One effect of a call on one target.
EndpointPublisher
Sets the live origin of one EndpointSource.
EndpointSource
The origins a service is reachable at, live origin first.
Extensions
Typed application values a tool can read from its ToolContext, keyed by type: at most one value per type. The application sets them on the agent with crate::AgentBuilder::tool_extensions; every call’s context carries them. Cloning is cheap (values are shared).
Failover
A provider chain: each step is tried in order until one answers.
FailoverStep
One link of a Failover chain: a provider, the model it is asked for, how long an attempt may take to start answering, and how many attempts it gets before the chain moves on.
Finish
A tool’s request to end the run once its batch completes. The run ends with crate::RunStatus::Finished and reply as its final text, without another model call and without consulting on_stop hooks.
FnService
A Service from a closure.
FnTool
Build a tool from a closure. Handy for tests and small integrations.
HookContext
Read-only view of the run handed to every hook.
Interruption
Why the run paused.
Limits
Hard budgets for one run. Turns, tokens and tool calls are checked at the top of every turn; tool calls and wall-clock time are also checked before every call in a batch, and the model call and each tool are bounded by the remaining wall-clock budget. max_turns cannot be switched off: it is clamped to HARD_TURN_CAP.
LoadedTools
The deferred tools whose schemas the model is sent. Cheap to clone; clones share the set.
MemoryStore
In-process store for tests and short-lived agents.
Message
A provider-neutral transcript entry.
ModelRequest
One provider call. Hooks may edit it in crate::Hook::before_model.
ModelResponse
A complete (non-streamed) model reply.
NestedCalls
The way a running tool has a call judged by its run (see the module docs). Present in crate::ToolContext::nested while the run drives the tool’s call.
OwnerApprovalRequest
What the owner is asked to approve.
Pending
The unfinished tool batch of an interrupted turn.
ProjectRef
The project a turn works in: a unit of work the host keeps (an app’s project, a bot placed in one), with the folder it lives in when it has one. Memory and tools key project-scoped state on ProjectRef::id, which stays the same when the project is renamed or its folder moves.
ProviderSwitch
A move from one step of a Failover chain to the next, reported as StreamEvent::Switched and then as crate::Event::ProviderSwitched.
QuotaGuard
A provider wrapper for one account. After a failure that no other model of the account can avoid (a used-up quota, an account that cannot pay, a rejected credential) it answers every call with that error, without sending it, until the cooldown ends: until the quota’s stated reset, or for a fixed time when there is none.
Receipt
The durable record of one tool call. Every call produces exactly one, refusals included, so “what actually happened” never depends on what the model says happened.
RequestOptions
How a provider should answer, beyond the messages and tools. Providers map what their API supports and ignore the rest.
Retry
Retry layer: exponential backoff on retryable errors.
RunId
RunOutcome
The typed result of crate::Agent::run or crate::Agent::resume.
RunSnapshot
What a StopCondition can see.
RunState
Everything needed to continue a run, as plain serializable data.
ServiceContext
What a service can see of its host and of the run it is in.
ServiceError
Why a service’s run failed.
ServiceHost
Runs Services until told to stop.
ServiceWaker
Ends the host’s wait for the next tick.
SharedDeclines
Owner declines shared by a family of runs: a run and the child runs it starts (and their children). A decline recorded in any of them reaches every other one before its next call, so a parent is refused an effect the owner declined inside its child, and a running child is refused one the owner declined in its parent after the child started.
StoreError
StuckConfig
Thresholds for loop detection. Configurable on purpose: OpenHands hardcoded theirs and legitimate polling got flagged (their issue #762).
ToolAnnotations
Effect hints that drive scheduling and policy.
ToolCall
One tool invocation requested by the model.
ToolContext
Trusted, harness-provided context for one call.
ToolError
A tool failure the harness could not turn into normal output. The loop still reports it to the model as an error result; it never ends the run.
ToolInfo
What before_tool hooks know about the tool behind a call.
ToolLoad
Deferred tools a run loaded, surfaced after the result of the call that answers after_tool_call (the batch whose call loaded them).
ToolOutput
What a tool hands back to the model, plus structured details for receipts.
ToolSpec
What the model sees about a tool: the OpenAI-style function object.
ToolSurfacing
Deferred tools as a provider that can surface tools mid-conversation sends them, so loading one never changes the request’s tool block (and with it the whole cached prefix). Providers without that ignore it: ModelRequest::tools already holds every tool the model may call.
UntrustedHook
Marks untrusted output as data and interrupts egress calls made after the run read untrusted content. Declares Safeguard::UntrustedOutput.
Usage
Token accounting for one call or a whole run.

Enums§

AccessLevel
How much a run may change. ReadOnly < Write.
ApprovalRisk
How much is at stake in an approval request.
AskReason
Why the owner is asked.
BuildError
Misconfiguration caught when building an agent.
CardAction
What allowing the call does.
ChannelVisibility
Visibility level of the channel the message originated from.
CoreError
Errors from run/resume itself. Things that happen inside a run (tool failures, provider outages, limits) are reported through crate::RunStatus, not here.
EffectClass
What kind of thing a call does.
Event
Everything observable about a run, in order. One stream feeds UIs, tracing exporters, stores and eval assertions.
FailoverAction
What a Failover does after a failed attempt.
FinishOutcome
How a tool-driven finish judged the work.
HighImpact
An effect that deserves a warning on the card.
HookFailure
How a hook failed to give an answer.
HookPoint
A moment of the loop at which hooks run.
Image
An image the model should look at. Carried on user messages and on tool results; providers map it to their own wire format and ignore it on other roles. Debug omits the encoded bytes so transcripts stay loggable.
InterruptKind
Who an interruption is waiting for.
InvocationStage
How far a call got before its outcome was decided.
LimitDecision
What an on_limit hook decides about a limit the run has reached.
LimitKind
MessageOrigin
Who put a message into the transcript. Policies use this instead of matching text to tell real user input from harness feedback, and providers use it to tell a hook’s per-request note from the transcript.
ModelDecision
What an after_model hook decides about a response.
ModelErrorDecision
What an on_model_error hook decides about a failed model call.
NestedVerdict
The run’s answer about a nested call.
Outbound
What a call carries out of the machine, for a call that only reads. A fetch changes nothing, yet its URL can carry private data to whoever runs the server, so it counts once the run has read untrusted content.
ProviderError
ReceiptStatus
Resolution
How to settle the call an interrupted run is waiting on.
ResponseFormat
The shape a reply must take.
Role
Who authored a message in the transcript.
RunStatus
Why a run ended. Every exit path maps to exactly one variant, so callers never have to parse prose to learn what happened.
Safeguard
A safety property every agent with tools must have before it can run.
SameToolStreak
The consecutive-call allowance of a tool: how long a run may call it in a row before the same-tool guard treats the streak as a loop.
Schedule
When a service runs (see ServiceHost for the exact rules).
ServiceEvent
What happened to a service. Every ServiceEvent::Launched is followed by exactly one ServiceEvent::Ended with the same run.
ServiceRunEnd
How one run of a service ended.
SourceTrust
Who authored the content a tool returned. Untrusted is content someone other than the owner wrote (a web page, an inbound message, a third-party file); it may carry instructions aimed at the model. The default is Untrusted, so a tool that does not say otherwise taints the run.
StopDecision
What an on_stop hook decides when the model replies without tool calls.
StreamEvent
One item of a streamed reply. A well-formed stream yields any number of deltas and ends with exactly one Done carrying the complete response.
StuckDecision
What to do when the stuck detector fires.
StuckSignal
SwitchReason
Why a Failover chain moved on from a step.
ToolChoice
How the model may use tools on this call.
ToolDecision
What a before_tool hook decides about one call.
UntrustedMode
How strictly the untrusted-content rule applies.
UserRole
Role assigned to a user based on config (owner_ids).

Constants§

AUTHORITY_BLOCKED
Prefix of the reason the crate::AuthorityHook gives when a call is outside what the run may do.
EGRESS_BLOCKED
Prefix of the reason an outbound secret scan (the crate::Safeguard::Egress hook) gives when it refuses a call.
HARD_TURN_CAP
Turn cap that applies even if Limits::max_turns is set higher. A run that needs more than this is a bug, not a task.
LOAD_TOOLS
The built-in tool that loads deferred tools.
OWNER_DECLINED
Prefix of the reason recorded when the owner declines an approval.
OWNER_UNANSWERED
Prefix of the reason for a call whose owner card got no answer (it expired, could not be delivered, or the turn was cancelled). Not a refusal: nothing is remembered as declined.
RUN_STATE_SCHEMA
Version of the RunState serialization format this kernel writes and can resume. State saved before the field existed reads as version 1. Bump it when a change would make older saved state resume wrongly, and teach resume to migrate or refuse the old version.
UNTRUSTED_BLOCKED
Prefix of the refusal a rejected egress call returns to the model after the run read untrusted content.
UNTRUSTED_EGRESS_INTERRUPT
Prefix of the interruption reason raised by UntrustedHook.

Traits§

AuthorityCeiling
A limit on what a run may do that can tighten while the run is in flight, read before every call. None means no extra limit right now.
EventSink
Receives events synchronously as they happen. Keep it cheap; forward to a channel if the consumer is slow. Events carry no timestamps: a sink is called the moment each happens, so it stamps them with whatever clock it keeps (receipts carry each call’s duration_ms, and Event::Finished the run’s elapsed_ms).
FailoverPolicy
Decides what follows a failed attempt. The default (DefaultFailover) retries what ProviderError::is_retryable allows on the same step, then moves on; it moves on at once from every other error (another provider may accept what this one refused) and stops only on a context overflow (the caller must shrink the request). A request with crate::RequestOptions::single_attempt stops at its first error whatever the policy says, unless it also sets crate::RequestOptions::fallback_when_unspent and the error proves the attempt used nothing: then it moves on to the next step.
Hook
Extension point for every policy. All methods have no-op defaults, so a hook implements only what it needs. Hooks run in registration order and outside the model’s context window: they cost no tokens and the model cannot argue its way past them.
InterruptResolver
Settles interruptions inside Agent::run_resolving: a clean-check verifier, an approval UI, a policy. None leaves the run interrupted.
Provider
A model backend. Implementations translate ModelRequest to their wire format and back. Retries and fallbacks are wrappers (Retry), not loop logic.
RunStore
Durable home for runs: an append-only event journal plus the latest state snapshot. The loop saves state after every turn and at every exit, so a crash loses at most the turn in flight.
Service
Work a ServiceHost runs in the background.
ServiceGate
Decides whether a tick launches anything.
ServiceObserver
Receives every ServiceEvent, for logs and dashboards.
StopCondition
A custom stop rule, checked with the built-in limits at the top of each turn. Return Some(reason) to end the run. Closures implement it.
Tool
An LLM-callable capability. Only spec and call are required.

Functions§

check_argument_types
check_arguments without required keys (at any depth): what the kernel enforces for every call whatever the tool’s own Tool::validate says. Which keys a call may leave out is the tool’s contract (a dispatcher may fill defaults); what a present value is, is not.
check_arguments
Check arguments against a tool’s declared JSON schema: an object when the schema says "type": "object", every required key present and not null, and each present value of the declared type (string, integer (a whole number), number, boolean, array, object, null, or a list of these), within its enum, with nested objects and array items checked the same way. A null for a key that is not required counts as absent. Keywords beyond these are not enforced.
collect_stream
Drain a stream into its final response. Useful for implementing complete on a streaming provider.
is_untrusted_egress
Whether interruption was raised by UntrustedHook: its kind is InterruptKind::Untrusted and its reason carries the hook’s prefix.
strip_reserved_arguments
Minimal schema check: the arguments must be an object containing every required key. Full JSON Schema validation is left to tools that need it. Drop every top-level argument key starting with _. Those keys are the dispatcher’s (an application passes its own facts to a tool through ToolContext, never through arguments), so a model that sends one is impersonating it. The kernel applies this to every call a model proposes before anything reads it, and the daemon’s dispatcher uses the same function.

Type Aliases§

ToolResult