Skip to main content

ShadowMode

Struct ShadowMode 

Source
pub struct ShadowMode { /* private fields */ }
Expand description

Toggleable shadow-mode manager for agent tool calls.

Implementations§

Source§

impl ShadowMode

Source

pub fn new(active: bool) -> Self

Create a new instance. Pass true to start in shadow mode.

Source

pub fn with_clock( active: bool, clock: impl Fn() -> f64 + Send + 'static, ) -> Self

Create with a custom clock (useful for tests).

Source

pub fn is_active(&self) -> bool

Source

pub fn activate(&mut self)

Source

pub fn deactivate(&mut self)

Source

pub fn records(&self) -> &[ShadowRecord]

Source

pub fn clear_records(&mut self)

Source

pub fn intercept<F>( &mut self, tool_name: &str, args: Value, kwargs: Value, when_shadow: Value, f: F, ) -> Value
where F: FnOnce() -> Value,

Intercept a tool call.

If active: record the call, return when_shadow without calling f. If inactive: call f and return its result.

  • args: positional args (usually json!([arg1, arg2]))
  • kwargs: keyword args (usually json!({"key": val}))
  • when_shadow: the placeholder to return in shadow mode
  • f: the real implementation (only called when inactive)
Source

pub fn to_jsonl(&self, path: impl AsRef<Path>) -> Result<usize>

Save all records to path as JSONL (overwrites). Returns count.

Source

pub fn load_jsonl(path: impl AsRef<Path>) -> Result<Vec<ShadowRecord>>

Load records from a JSONL file.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.