pub struct PolicyEngine { /* private fields */ }Expand description
The referee engine that evaluates tool calls against configured policies.
The PolicyEngine holds a set of ApprovalPolicy rules and an
ApprovalHandler for escalating decisions that require human input.
It tracks auto-approval counts per policy to enforce rate limits.
Implementations§
Source§impl PolicyEngine
impl PolicyEngine
Sourcepub fn new(
policies: Vec<ApprovalPolicy>,
handler: Arc<dyn ApprovalHandler>,
) -> Self
pub fn new( policies: Vec<ApprovalPolicy>, handler: Arc<dyn ApprovalHandler>, ) -> Self
Create a new policy engine with the given rules and handler.
Sourcepub async fn evaluate(
&self,
tool_name: &str,
input: &Value,
fighter_id: &FighterId,
) -> PunchResult<ApprovalDecision>
pub async fn evaluate( &self, tool_name: &str, input: &Value, fighter_id: &FighterId, ) -> PunchResult<ApprovalDecision>
Evaluate a tool call against the configured policies.
The referee checks the ring rules:
- Find the first policy whose tool patterns match the tool name
- If no policy matches, the move is allowed (permissive by default)
- If the matched policy auto-approves and the risk is not Critical, check the auto-approval counter
- If the counter is exhausted (or risk is Critical), escalate to the handler
Sourcepub fn auto_approve_count(&self, policy_index: usize) -> Option<u32>
pub fn auto_approve_count(&self, policy_index: usize) -> Option<u32>
Get the current auto-approval count for a policy at the given index.
Returns None if the index is out of bounds.
Sourcepub fn reset_counters(&self)
pub fn reset_counters(&self)
Reset all auto-approval counters to zero.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PolicyEngine
impl !RefUnwindSafe for PolicyEngine
impl Send for PolicyEngine
impl Sync for PolicyEngine
impl Unpin for PolicyEngine
impl UnsafeUnpin for PolicyEngine
impl !UnwindSafe for PolicyEngine
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