Approval Service
The approval service turns calls held for confirmation into an inbox of approval requests
with a policy: who may approve, how many distinct approvers a call needs, whether the
requester may approve their own call, when the request escalates, and when it expires. It
runs over any ApprovalStore, so requests are as durable as the store — in memory, SQLite,
PostgreSQL, Redis, MongoDB, Neo4j, or Firestore.
| Capability | Behaviour |
|---|---|
| Inbox | Lists the requests an approver may decide now — by name, by group, or through a live delegation — oldest first, paged by cursor; InboxQuery::with_session narrows it to the decisions one session — application, user and session ID — waits on |
| Quorum | A request resolves once quorum distinct approvers approve; a delegate's approval counts for the delegator |
| Slots | A request with slots resolves only once distinct approvers fill every slot, one each — an editor and a publisher who are two people — whatever order they decide in |
| Directory | An ApproverDirectory on the service states each approver's and delegator's membership of the groups it governs; callers' claims to those groups are ignored |
| Self-approval | Refused by default for the requester, the acting agent, and anyone acting through their delegation |
| Actions | Approve, edit (approve with substituted arguments), reject, respond (answer the model instead of running the call) |
| Concurrency | Every change is a compare-and-swap on the request's version; of two approvers deciding one version, one wins and the other receives 409 approval.version_conflict |
| Expiry | tick denies requests past expires_at, once |
| Escalation | tick fires each escalation step once its delay has passed, adding its approvers and notifying |
| Delegation | A subject lets another decide in their place within a time window and an application or tool scope |
| Notification | ApprovalNotifier hears submission, escalation, decisions, resolution, expiry, and cancellation; adk-server ships a signed webhook notifier |
| Resolution hooks | An ApprovalResolution runs once the deciding answer is recorded and before the outcome reaches the call or wakes its run |
| Resume | A resolution is written to the store under the call's fingerprint, wakes the durable run waiting for it, and is otherwise taken by the next run, which resumes the held call |
| Binding | The fingerprint names the acting agent and the tool's origin, so a resolution authorizes only the agent that held the call, on the tool it was held for; a held call that resumes against another MCP server or a redefined tool is answered as not run |
How a Held Call Becomes a Request
- The governed path holds a call that needs confirmation and records it in the run's
ApprovalStore. - With
RunConfig::approval_serviceset, it also offers the call to the service'sApprovalRouter, which returns theApprovalPolicy(orNoneto leave the call in the store only). The request ID is derived from the session, the call's fingerprint, and the time it was first held, and a call held again while its request is pending gets that request back, so one held call never has two open requests. - Approvers decide through
ApprovalService::decideor the server endpoints. - The decision that resolves the request is written to the store: an approval (with any
edited arguments) or a denial carrying the reason. The request's
run_idis woken withDurableRunStore::wakewhen the service has a run store (StoreApprovalService::with_run_store), and so is every run of the session parked on the call (aRunCheckpointRef::AwaitingApprovalnaming its fingerprint), such as a later run that held the call again while the request was still open.adk-server'sDurableWorkersetsRunConfig::durable_run_idto the claimed run's ID, so a run it parks on a held call is the run its approval wakes. - The next run resumes the held call under its original call ID, and the governed path takes
the decision. An edited call passes the
ToolPolicyand the agent's tool screen again before it executes; a policy denial of the edit refuses the call. A run without a decision for the call does not ask its confirmation handler about it again: the call keeps waiting and the run goes on to the model (spec 3.3 §7.3).LlmAgent,CodeActAgentand the realtime runners follow this rule;CodeActAgentanswers the new message in a turn that cannot suspend and keeps the waiting call's checkpoint, unless that turn decided an identical call, which answers the waiting one.CodeActAgentchecks the waiting call under the arguments it was held with, after plugin and screen rewrites, and a run that resumes it on a decision gives the message the run brought to the model. - A call decided any other way — by the confirmation handler, a call-ID decision, a
fingerprint approval, or
Harness::decide— has its open request withdrawn (ApprovalService::withdraw: closed as cancelled, with no outcome written and no run woken) and its pending entry cleared, so the request cannot authorize a later call with the same fingerprint. A request an approver resolved at the same moment is waited for until its outcome is in the store, and that outcome is absorbed, as is an outcome already applied or recorded while the confirmation handler was asked; a request that does not settle within ten seconds fails the call withapproval.outcome_unsettled.Harness::deciderefuses a rule it cannot remember before it touches the request, withdraws the request before it records the person's decision, and refuses the decision when an approver, an expiry or another decision settled the call first. Of twoHarness::decidecalls for one call at once in one process — two surfaces answering together — the second is refused withharness.decision.invalid; the store's decision write is not conditional, so processes that share a store and decide one call at the same moment are not told apart.
use std::sync::Arc;
use std::time::Duration;
use adk_core::{
ApprovalCall, ApprovalPolicy, ApprovalRisk, ApprovalRoute, ApproverSelector, RunConfig,
StoreApprovalService,
};
use adk_session::SqliteApprovalStore;
async fn configure() -> adk_core::Result<RunConfig> {
let store = SqliteApprovalStore::new("sqlite://approvals.db?mode=rwc").await?;
store.migrate().await?;
// Large transfers need two people from finance and escalate to the CFO office.
let router = |call: &ApprovalCall| {
let amount = call.request.args["amount"].as_f64().unwrap_or(0.0);
let finance = ApprovalPolicy::new([ApproverSelector::group("finance")])
.expires_after(Duration::from_secs(4 * 3600));
Some(if amount > 10_000.0 {
ApprovalRoute::new(
finance
.with_quorum(2)
.escalate_after(Duration::from_secs(1800), [ApproverSelector::group("cfo-office")]),
)
.with_risk(ApprovalRisk::High)
} else {
ApprovalRoute::new(finance)
})
};
let service = StoreApprovalService::new(Arc::new(store)).with_router(router);
Ok(RunConfig::builder().approval_service(Arc::new(service)).build())
}
RunConfigBuilder::approval_service also installs the service's store as the run's
approval_store, so decisions reach the governed path.
Without a router, a held call stays in the store only. A host that decides calls in an inbox
gives such a service a router of its own with ApprovalService::route_unrouted, and adds a
notifier to a built service with ApprovalService::add_notifier: the
agent kernel routes every unrouted call to the
operator group and publishes held and decided on its bus. A router the service was built
with keeps deciding, including to leave a call in the store only. Both methods answer whether
the service took what it was given; their defaults take nothing, so a wrapper forwards them.
ApprovalService::add_resolution adds an ApprovalResolution, which runs for each request a
decision resolves, after the decision is recorded and before the outcome is written for the
call and its run is woken. A host puts there what the resumed call must already see:
adk-surface's LocalSource grants the standing rule of "Always allow" from it, so the turn
the approved call resumes is checked against the rule
(Surfaces). A hook reports its own failures, and the outcome applies
whatever it does. The default takes none, and a wrapper forwards it.
Policy
| Field | Default | Meaning |
|---|---|---|
approvers | — | ApproverSelector::Subject(SubjectRef) or ApproverSelector::Group(name) |
slots | none | Selectors distinct approvers must fill, one approver each; a selector listed twice needs two people. Whoever a slot selects may approve |
quorum | 1 | Distinct approvals needed; ApprovalPolicy::for_slots sets it to the number of slots |
forbid_self_approval | true | Refuse the requester and the acting agent; allow_self_approval() clears it |
escalation | none | Steps {after, to}, ordered by after |
on_expiry | Deny | What expiry does |
expires_after | none | Request lifetime when the request carries no expires_at |
The requester is the acting context's on_behalf_of subject, or the session's user when the
call carries no acting context. Group membership is asserted by the caller deciding
(ApprovalDecision::approver_groups); adk-server takes it from the authenticated request.
Slots
A policy with slots needs one distinct approver per slot. Approvals beyond the quorum do not
resolve the request while a slot is open, and the service matches approvers to slots over all
counted approvals, so a person who could fill either of two slots never blocks the other.
ApprovalRequest::open_slots lists the slots still waiting.
use adk_core::{ApprovalPolicy, ApproverSelector};
/// An editor and a publisher, two distinct people, neither the requester.
fn release_policy() -> ApprovalPolicy {
ApprovalPolicy::for_slots([
ApproverSelector::group("role:editor"),
ApproverSelector::group("role:publisher"),
])
}
Approver Directory
StoreApprovalService::with_directory makes an ApproverDirectory the authority on
membership of the groups it governs (ApproverDirectory::governs, every group by default):
the service asks it for the groups of the approver and of any delegator, for every decision
and every inbox, and records the answer in approver_groups and authority_groups. A claim
to a governed group does not count, so a surface cannot claim a role for the person deciding;
groups it does not govern, such as an operator scope, are kept as asserted. adk_kernel::charter::CharterDirectory answers from the site charter in force.
use std::sync::Arc;
use adk_core::principal::SubjectRef;
use adk_core::{ApprovalRequest, ApproverDirectory, InMemoryApprovalStore, StoreApprovalService};
use async_trait::async_trait;
struct Staff;
#[async_trait]
impl ApproverDirectory for Staff {
async fn groups(
&self,
subject: &SubjectRef,
_request: &ApprovalRequest,
) -> adk_core::Result<Vec<String>> {
Ok(match subject.id.as_str() {
"ana@example.com" => vec!["finance".to_string()],
_ => Vec::new(),
})
}
}
fn service() -> StoreApprovalService {
StoreApprovalService::new(Arc::new(InMemoryApprovalStore::new()))
.with_directory(Arc::new(Staff))
}
Decisions
| Action | Requires | Effect |
|---|---|---|
| Approve | — | Counts toward the quorum |
| Edit | edited_args | Approves the substituted arguments; approvals of earlier arguments stop counting |
| Reject | optional reason | Resolves at once; the call is refused with the reason |
| Respond | response text | Resolves at once; the call does not run and the model receives the response |
| Error code | HTTP | When |
|---|---|---|
approval.version_conflict | 409 | The request changed since the version read; re-read and decide again |
approval.already_resolved | 409 | The request is no longer pending |
approval.expired | 409 | The request is past its expiry |
approval.already_decided | 409 | The approver's authority already counts toward the quorum |
approval.not_an_approver | 403 | Not eligible directly or by delegation |
approval.delegation_inactive | 403 | The only matching delegation is outside its window |
approval.self_approval | 403 | Self-approval is forbidden |
approval.action_not_allowed | 400 | The request does not allow the action, or an edit or response lacks its content |
Decisions a Reviewer Made
A run with a ToolReviewer (Model Reviewer) decides
some held calls before they reach the inbox. When it approves or denies one, the governed path
files it with ApprovalService::record_review: the service routes the call as it would a held
call and stores a request already resolved — Approved or Rejected, one decision by the
reviewer (SubjectRef::service("model:<model id>")) carrying its rationale, and
outcome_applied set, because the run applied the verdict itself. Nothing is written to the
store and no run is woken. Notifiers hear Decided and Resolved, so the kernel publishes
decided naming the reviewer, and the service's audit trail records the decision with source
reviewer. A call the reviewer escalates is submitted as a pending request like any other
held call, with the reviewer's note in its summary. The trait's default files nothing;
a wrapper forwards it to the service it wraps.
Expiry and Escalation
ApprovalService::tick(now) expires overdue requests and fires due escalation steps. The
service reads now from its Clock everywhere else, so tests drive it with ManualClock.
Run it periodically — adk_server::approvals::spawn_approval_ticker does — on any number of
replicas: each expiry and each escalation step is a compare-and-swap, so it happens once.
tick also applies resolutions whose application an earlier failure interrupted, after
APPROVAL_REAPPLY_GRACE, and only while the call is still pending in the store, so a decision
is never written twice.
Delegation
use adk_core::principal::SubjectRef;
use adk_core::{ApprovalDelegation, ApprovalService, DelegationScope, DelegationWindow};
use chrono::{Duration, Utc};
async fn cover(service: &dyn ApprovalService) -> adk_core::Result<()> {
let now = Utc::now();
let delegation = ApprovalDelegation::new(
SubjectRef::human("ana@example.com"),
SubjectRef::human("bo@example.com"),
DelegationWindow::new(now, now + Duration::days(7)),
)
.with_from_groups(["finance"])
.with_scope(DelegationScope { app_name: Some("payments".into()), tool_names: vec![] });
service.delegate(delegation).await?;
Ok(())
}
A decision through a delegation records via_delegation and counts for the delegator.
Outside the window the delegate is refused with approval.delegation_inactive.
Server Endpoints
Enable the approvals feature of adk-server and mount the service:
use std::sync::Arc;
use std::time::Duration;
use adk_core::{ApprovalService, StoreApprovalService};
use adk_server::ServerBuilder;
use adk_server::approvals::spawn_approval_ticker;
// `config` is a ServerConfig with a RequestContextExtractor; `store` an Arc<dyn ApprovalStore>.
let service: Arc<dyn ApprovalService> = Arc::new(StoreApprovalService::new(store));
let app = ServerBuilder::new(config)
.with_approval_service(service.clone())
.build();
let ticker = spawn_approval_ticker(service, Duration::from_secs(30));
| Route | Effect |
|---|---|
GET /api/approvals | The caller's inbox (state, group, app, user, session, cursor, limit); session needs app and names a session of user, the caller by default, and never widens the inbox |
GET /api/approvals/{id} | One request the caller may decide or asked for |
POST /api/approvals/{id}/decide | {"expectedVersion", "action", "editedArgs", "reason", "via"} |
POST /api/approvals/{id}/cancel | {"reason"}; the requester or an approver |
POST /api/approvals/delegations | Delegates the caller's authority: {"to", "notBefore", "notAfter", "scope"} |
DELETE /api/approvals/delegations/{id}?toKind=&toId= | Revokes a delegation the caller granted or holds |
Every route requires an authenticated caller and answers 401 otherwise. The caller is
human(user_id) in the groups named by its scopes; ApprovalEndpoints::with_identity changes
the mapping. Responses omit the call's fingerprint, which carries the unredacted arguments;
approvers see argsRedacted, the acting agent, and the tool's origin (its publisher and
declaration digest) on the request. showsCallArgs says whether argsRedacted are the call's
own arguments (ApprovalRequest::shows_call_args): an edit replaces the call's arguments
with editedArgs whole, so a client edits only a request that shows them, never a redacted
view (spec 3.3 §7.2).
Webhook Notifications
WebhookApprovalNotifier posts each ApprovalNotification as JSON in the
Standard Webhooks format: webhook-id (the
notification ID, {request id}:{version}, stable across retries), webhook-timestamp, and
webhook-signature (v1, and the base64 HMAC-SHA256 of {id}.{timestamp}.{body}). It
signs and sends through the shared adk_core::webhook_delivery::WebhookDelivery: retries with
exponential backoff and jitter in the background, dead-lettering after the last attempt, and an
egress policy that allows HTTPS to public addresses only (with_delivery changes it). See
Wake-ups and Webhooks.
use std::sync::Arc;
use adk_core::StoreApprovalService;
use adk_server::approvals::WebhookApprovalNotifier;
// The secret is base64, optionally prefixed with `whsec_`.
let notifier = WebhookApprovalNotifier::new("https://hooks.example.com/approvals", &webhook_secret)?;
let service = StoreApprovalService::new(store).with_notifier(Arc::new(notifier));
Notification is best effort: a delivery that fails every attempt is dead-lettered and the decision stands, because the store holds the request's state.
Backends
The store methods behind the service — create_request, get_request, replace_request,
list_requests, put_delegation, delegations_to, delete_delegation, and
take_approval — are implemented by every backend and checked by the
approval_store_conformance_tests! and approval_service_conformance_tests! suites. See
Durable Stores for the primitive each backend uses.
Related
- Tool Authorization — the governed path and held calls
- Durable Stores — backends and the conformance suites
- Durable Runtime —
DurableRunStore::wake