pub struct ModelApprover { /* private fields */ }Expand description
Core traits and types.
Always available regardless of feature flags. Includes:
Agent- The fundamental trait for all agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/Result- Unified error handling AToolReviewerbacked by a model:auto_reviewfor ADK-Rust.
It sends one request per held call, in a context of its own: a fixed system prompt, then
the call, its fingerprint, the policy’s reason and the user’s recent messages, bounded.
It declares no tools and sees no session history, so it can do nothing but answer. It
approves only above min_confidence and escalates below it, on a
timeout, on an error and on any answer that is not a verdict. Its calls go through the
run’s ModelCallScope, so they count against the run budget and the spend ledger, and
a budget that refuses the call escalates it.
§Prompt injection
A model reviewer is one more surface a prompt injection can aim at: text the agent read — a web page, a file, a tool result — can steer the agent into a harmful call and then try to talk the reviewer into approving it. The mitigations:
| Mitigation | Effect |
|---|---|
| Only held calls | Deny rules, protected paths and sandbox refusals are decided before the reviewer; it can approve only what the policy would let a person approve |
| No tool results | The reviewer never sees what tools returned, where most injected text arrives |
| Untrusted blocks | Arguments, the policy’s reason and the user’s messages are wrapped as data, and the system prompt tells the model to ignore instructions in them |
| Bounded context | Arguments and messages are cut to max_context_chars |
| Strict answer | Anything but a JSON verdict escalates; approval needs min_confidence |
| Fingerprint binding | A verdict covers the exact call reviewed: agent, tool origin, name and arguments |
| Audit | Every verdict is recorded, signed when the trail signs, with the reviewer as the actor |
| Scope | ReviewScope keeps tools that move money or delete data with a person, and deny_only removes approval altogether |
None of these makes the reviewer immune: it lowers the cost of unattended runs and keeps every decision governed and on record, and a deployment that cannot accept a wrong approval keeps those tools out of its scope.
§Example
use std::sync::Arc;
use std::time::Duration;
use adk_core::{ModelApprover, ReviewScope, ToolReviewer};
let approver = ModelApprover::new(Arc::new(Haiku))
.scope(ReviewScope::default().for_tools(["bash"]))
.guidance("This agent maintains a Rust workspace; builds and tests are routine.")
.timeout(Duration::from_secs(30));
assert_eq!(approver.reviewer().id, "model:claude-haiku-5-5");
assert_eq!(ToolReviewer::timeout(&approver), Duration::from_secs(30));Implementations§
Source§impl ModelApprover
impl ModelApprover
Sourcepub const DEFAULT_MIN_CONFIDENCE: f64 = 0.8
pub const DEFAULT_MIN_CONFIDENCE: f64 = 0.8
The confidence an approval needs by default.
Sourcepub const DEFAULT_MAX_CONTEXT_CHARS: usize = 4_000
pub const DEFAULT_MAX_CONTEXT_CHARS: usize = 4_000
How many characters of arguments and of user messages the reviewer sees by default.
Sourcepub fn new(model: Arc<dyn Llm>) -> ModelApprover
pub fn new(model: Arc<dyn Llm>) -> ModelApprover
A reviewer asking model, covering every held call, approving at
DEFAULT_MIN_CONFIDENCE.
Sourcepub fn scope(self, scope: ReviewScope) -> ModelApprover
pub fn scope(self, scope: ReviewScope) -> ModelApprover
Decides only the calls scope covers.
Sourcepub fn min_confidence(self, confidence: f64) -> ModelApprover
pub fn min_confidence(self, confidence: f64) -> ModelApprover
Approves or denies only at confidence (0 to 1) or above; escalates below it.
Sourcepub fn guidance(self, guidance: impl Into<String>) -> ModelApprover
pub fn guidance(self, guidance: impl Into<String>) -> ModelApprover
Adds the operator’s guidance to the system prompt: what the agent is for and what is routine. It is trusted, so it never comes from the workspace or the user.
Sourcepub fn timeout(self, timeout: Duration) -> ModelApprover
pub fn timeout(self, timeout: Duration) -> ModelApprover
Escalates a review that takes longer than timeout.
Sourcepub fn deny_only(self) -> ModelApprover
pub fn deny_only(self) -> ModelApprover
Never approves: a call is denied or escalated.
Sourcepub fn max_context_chars(self, chars: usize) -> ModelApprover
pub fn max_context_chars(self, chars: usize) -> ModelApprover
Cuts the arguments and the user’s messages to chars characters each.
Trait Implementations§
Source§impl Clone for ModelApprover
impl Clone for ModelApprover
Source§fn clone(&self) -> ModelApprover
fn clone(&self) -> ModelApprover
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModelApprover
impl Debug for ModelApprover
Source§impl ToolReviewer for ModelApprover
impl ToolReviewer for ModelApprover
Source§fn reviewer(&self) -> SubjectRef
fn reviewer(&self) -> SubjectRef
SubjectRef::service("model:<model id>").Source§fn covers<'life0, 'life1, 'async_trait>(
&'life0 self,
review: &'life1 ToolReview,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
ModelApprover: 'async_trait,
fn covers<'life0, 'life1, 'async_trait>(
&'life0 self,
review: &'life1 ToolReview,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
ModelApprover: 'async_trait,
review at all. A call it does not cover goes to a
person as if no reviewer were set, and no verdict is recorded. Defaults to every call.Source§fn timeout(&self) -> Duration
fn timeout(&self) -> Duration
review before it escalates.Source§fn review<'life0, 'life1, 'async_trait>(
&'life0 self,
review: &'life1 ToolReview,
) -> Pin<Box<dyn Future<Output = Result<ReviewVerdict, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
ModelApprover: 'async_trait,
fn review<'life0, 'life1, 'async_trait>(
&'life0 self,
review: &'life1 ToolReview,
) -> Pin<Box<dyn Future<Output = Result<ReviewVerdict, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
ModelApprover: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for ModelApprover
impl !UnwindSafe for ModelApprover
impl Forget for ModelApprover
impl Freeze for ModelApproverwhere
*const ArcInner<dyn Llm> is !null: Freeze,
PhantomData<ArcInner<dyn Llm>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<String>: Freeze,
PhantomData<u8>: Freeze,
impl Move for ModelApprover
impl Send for ModelApprover
impl Sync for ModelApprover
impl Unpin for ModelApprover
impl UnsafeUnpin for ModelApproverwhere
*const ArcInner<dyn Llm> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Llm>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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> ⓘ
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> ⓘ
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> ⓘ
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 moreimpl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.