pub struct DriverCapPolicy { /* private fields */ }Expand description
Enforces the driver classes’ autonomy caps on the governed path (spec 3.5 §7.13, A-I21).
It only ever tightens: compose it with the harness’s mode policy and the kernel’s
DriverPolicy through StrictestPolicy, so a call it allows is decided by those
layers. It knows driver tools by name, whether an in-process adapter or an MCP server
serves them.
| Tool’s cap | Decision |
|---|---|
AlwaysHeld — a DNS change, a campaign launch | RequireApproval on every call, in every mode (A-I21) |
WithinBudget with an amount — a renewal, a bid | Allow within the owner’s DriverBudget for the tool, in its currency; RequireApproval beyond it or without one |
| Any other driver tool, and every tool that is not a driver’s | Allow (decided by the other layers) |
§Example
use adk_core::{PolicyDecision, ToolPolicy, ToolPolicyRequest};
use adk_drivers::{DriverBudget, DriverCapPolicy};
use serde_json::json;
let policy = DriverCapPolicy::new(DriverBudget::new().cap("ads_set_bid", "USD", 200));
let change = ToolPolicyRequest::new("dns_change_records", json!({"zone": "example.com."}));
assert!(matches!(policy.evaluate(&change).await, PolicyDecision::RequireApproval { .. }));
let bid = ToolPolicyRequest::new("ads_set_bid", json!({"campaign": "c1", "bid_minor": 150, "currency": "USD"}));
assert_eq!(policy.evaluate(&bid).await, PolicyDecision::Allow);
let high = ToolPolicyRequest::new("ads_set_bid", json!({"campaign": "c1", "bid_minor": 900, "currency": "USD"}));
assert!(matches!(policy.evaluate(&high).await, PolicyDecision::RequireApproval { .. }));Implementations§
Source§impl DriverCapPolicy
impl DriverCapPolicy
Sourcepub fn new(budget: DriverBudget) -> Self
pub fn new(budget: DriverBudget) -> Self
The policy with the owner’s budget.
Sourcepub fn decide(&self, tool: &str, args: &Value) -> PolicyDecision
pub fn decide(&self, tool: &str, args: &Value) -> PolicyDecision
The decision for a call to tool with args.
Trait Implementations§
Source§impl Clone for DriverCapPolicy
impl Clone for DriverCapPolicy
Source§impl Debug for DriverCapPolicy
impl Debug for DriverCapPolicy
Source§impl Default for DriverCapPolicy
impl Default for DriverCapPolicy
Source§impl ToolPolicy for DriverCapPolicy
impl ToolPolicy for DriverCapPolicy
Source§fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ToolPolicyRequest,
) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn evaluate<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ToolPolicyRequest,
) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Decides one call.
Source§fn policy_ref(&self) -> Option<String>
fn policy_ref(&self) -> Option<String>
A name or version for audit records, which cite the policy as
tool_policy:<name>. The default is None, cited as tool_policy.Source§fn evaluate_call<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
request: &'life1 ToolPolicyRequest,
call: &'life2 PolicyCall<'life3>,
) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn evaluate_call<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
request: &'life1 ToolPolicyRequest,
call: &'life2 PolicyCall<'life3>,
) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Decides one call, given its
PolicyCall facts as well as the request. Read moreAuto Trait Implementations§
impl Forget for DriverCapPolicy
impl Freeze for DriverCapPolicy
impl Move for DriverCapPolicy
impl RefUnwindSafe for DriverCapPolicy
impl Send for DriverCapPolicy
impl Sync for DriverCapPolicy
impl Unpin for DriverCapPolicy
impl UnsafeUnpin for DriverCapPolicywhere
*const LeafNode<String, BudgetCap> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, BudgetCap)>>: UnsafeUnpin,
impl UnwindSafe for DriverCapPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more