Skip to main content

aidaemon_core/
safeguard.rs

1/// A safety property every agent with tools must have before it can run.
2///
3/// The kernel does not implement these: a hook declares the ones it provides
4/// through [`crate::Hook::safeguards`], or the composition root attests one
5/// that something else enforces (for example its own tool adapter) with
6/// [`crate::AgentBuilder::attest`]. [`crate::AgentBuilder::build`] refuses an
7/// agent with tools that leaves any of them uncovered, so forgetting to wire
8/// a policy is a build error instead of a silent hole.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[non_exhaustive]
11pub enum Safeguard {
12    /// Every call stays within the authority explicitly granted by whoever
13    /// owns the agent (owner configuration, role, grants, modes). That grant
14    /// may be full by the owner's choice; approval prompts are one way to
15    /// enforce a narrower grant, not a requirement.
16    Authority,
17    /// Calls stay inside the paths and resources the task was granted.
18    Scope,
19    /// Output from tools the agent does not control (web pages, MCP
20    /// servers, third-party APIs) reaches the model marked as data, not
21    /// instructions, and calls with egress made after reading it are
22    /// verified by a clean check or, by the owner's explicit choice,
23    /// recorded.
24    UntrustedOutput,
25    /// Calls that need the owner's approval are put to the owner (as an
26    /// [`crate::InterruptKind::OwnerApproval`] interruption) before they run,
27    /// unless a standing grant already covers them.
28    Approval,
29    /// Outbound calls (egress annotations or effects) never carry
30    /// credentials or other secrets off the machine.
31    Egress,
32}
33
34impl Safeguard {
35    /// Every safeguard an agent with tools must cover.
36    pub const REQUIRED: [Safeguard; 5] = [
37        Safeguard::Authority,
38        Safeguard::Scope,
39        Safeguard::UntrustedOutput,
40        Safeguard::Approval,
41        Safeguard::Egress,
42    ];
43}
44
45impl std::fmt::Display for Safeguard {
46    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47        f.write_str(match self {
48            Safeguard::Authority => "authority",
49            Safeguard::Scope => "scope",
50            Safeguard::UntrustedOutput => "untrusted output",
51            Safeguard::Approval => "approval",
52            Safeguard::Egress => "egress",
53        })
54    }
55}