Skip to main content

PolicyEngine

Struct PolicyEngine 

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

Combines multiple ActionPolicy instances with a ContextMinimizer into a single evaluation engine.

Policies are evaluated in order. The first deny verdict wins; if none deny, the last warn wins; if none warn, the action is allowed. Session action counters track per-session usage for rate limiting.

Implementations§

Source§

impl PolicyEngine

Source

pub fn new() -> Self

Create a new policy engine with default context minimization and no policies.

Source

pub fn with_context_minimizer(context_minimizer: ContextMinimizer) -> Self

Create a new policy engine with a custom context minimizer.

Source

pub fn add_policy(&mut self, policy: ActionPolicy)

Add a policy to the engine. Policies are evaluated in insertion order.

Source

pub fn policy_count(&self) -> usize

Return the number of configured policies.

Source

pub fn evaluate_action( &self, action: &AgentAction, tool_def: Option<&ToolDefinition>, session_id: &str, ) -> PolicyDecision

Evaluate an action against all configured policies.

Returns a combined PolicyDecision:

  • First deny verdict wins (short-circuit).
  • If no deny, the last warn verdict is returned.
  • If no violations at all, allow is returned.

Also checks session-level rate limits if any policy has max_actions_per_session configured.

Source

pub fn minimize_context(&self, messages: &[Message]) -> Vec<Message>

Minimize a sequence of messages using the configured context minimizer.

Source

pub fn record_action(&self, session_id: &str)

Record an action for a session (increment counter).

Source

pub fn reset_session(&self, session_id: &str)

Reset the action counter for a session.

Trait Implementations§

Source§

impl Debug for PolicyEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PolicyEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V