pub struct EnforcementMiddleware { /* private fields */ }Expand description
Enforcement middleware for checking limits before operations
Implementations§
Source§impl EnforcementMiddleware
impl EnforcementMiddleware
Sourcepub fn with_policy(policy: EnforcementPolicy) -> Self
pub fn with_policy(policy: EnforcementPolicy) -> Self
Create with custom policy
Sourcepub fn emit_warning_events_enabled(&self) -> bool
pub fn emit_warning_events_enabled(&self) -> bool
Whether warning events should be emitted when limits are near
Sourcepub async fn register_execution(
&self,
execution_id: ExecutionId,
tenant_id: TenantId,
) -> Arc<ExecutionUsage>
pub async fn register_execution( &self, execution_id: ExecutionId, tenant_id: TenantId, ) -> Arc<ExecutionUsage>
Register a new execution
Sourcepub async fn unregister_execution(&self, execution_id: &ExecutionId)
pub async fn unregister_execution(&self, execution_id: &ExecutionId)
Unregister an execution
Sourcepub async fn get_usage(
&self,
execution_id: &ExecutionId,
) -> Option<Arc<ExecutionUsage>>
pub async fn get_usage( &self, execution_id: &ExecutionId, ) -> Option<Arc<ExecutionUsage>>
Get usage for an execution
Sourcepub async fn get_usage_snapshot(
&self,
execution_id: &ExecutionId,
) -> Option<UsageSnapshot>
pub async fn get_usage_snapshot( &self, execution_id: &ExecutionId, ) -> Option<UsageSnapshot>
Get usage snapshot for an execution
Sourcepub async fn check_step_allowed(
&self,
execution_id: &ExecutionId,
limits: &ResourceLimits,
) -> EnforcementResult
pub async fn check_step_allowed( &self, execution_id: &ExecutionId, limits: &ResourceLimits, ) -> EnforcementResult
Check if a new step can be started
Sourcepub async fn check_tokens_allowed(
&self,
execution_id: &ExecutionId,
limits: &ResourceLimits,
additional_tokens: u32,
) -> EnforcementResult
pub async fn check_tokens_allowed( &self, execution_id: &ExecutionId, limits: &ResourceLimits, additional_tokens: u32, ) -> EnforcementResult
Check if token usage is within limits
Sourcepub async fn check_wall_time_allowed(
&self,
execution_id: &ExecutionId,
limits: &ResourceLimits,
) -> EnforcementResult
pub async fn check_wall_time_allowed( &self, execution_id: &ExecutionId, limits: &ResourceLimits, ) -> EnforcementResult
Check if wall time is within limits
Sourcepub async fn check_concurrency_allowed(
&self,
tenant_id: &TenantId,
limits: &ResourceLimits,
) -> EnforcementResult
pub async fn check_concurrency_allowed( &self, tenant_id: &TenantId, limits: &ResourceLimits, ) -> EnforcementResult
Check if concurrent execution limit is respected
Sourcepub async fn check_all_limits(
&self,
execution_id: &ExecutionId,
limits: &ResourceLimits,
) -> EnforcementResult
pub async fn check_all_limits( &self, execution_id: &ExecutionId, limits: &ResourceLimits, ) -> EnforcementResult
Perform all limit checks before starting a step
Sourcepub async fn record_step(&self, execution_id: &ExecutionId)
pub async fn record_step(&self, execution_id: &ExecutionId)
Record step completion and update usage
Sourcepub async fn record_tokens(
&self,
execution_id: &ExecutionId,
input: u32,
output: u32,
)
pub async fn record_tokens( &self, execution_id: &ExecutionId, input: u32, output: u32, )
Record token usage
Sourcepub async fn record_discovered_step(&self, execution_id: &ExecutionId)
pub async fn record_discovered_step(&self, execution_id: &ExecutionId)
Record a discovered step and update usage
Sourcepub async fn record_cost(&self, execution_id: &ExecutionId, cost_usd: f64)
pub async fn record_cost(&self, execution_id: &ExecutionId, cost_usd: f64)
Record cost in USD
Sourcepub async fn push_discovery_depth(&self, execution_id: &ExecutionId)
pub async fn push_discovery_depth(&self, execution_id: &ExecutionId)
Push discovery depth (entering a discovered step’s sub-execution)
Sourcepub async fn pop_discovery_depth(&self, execution_id: &ExecutionId)
pub async fn pop_discovery_depth(&self, execution_id: &ExecutionId)
Pop discovery depth (exiting a discovered step’s sub-execution)
Sourcepub async fn check_discovered_step_limit(
&self,
execution_id: &ExecutionId,
policy: &LongRunningExecutionPolicy,
) -> EnforcementResult
pub async fn check_discovered_step_limit( &self, execution_id: &ExecutionId, policy: &LongRunningExecutionPolicy, ) -> EnforcementResult
Check if discovered step limit is within bounds
Sourcepub async fn check_discovery_depth_limit(
&self,
execution_id: &ExecutionId,
policy: &LongRunningExecutionPolicy,
) -> EnforcementResult
pub async fn check_discovery_depth_limit( &self, execution_id: &ExecutionId, policy: &LongRunningExecutionPolicy, ) -> EnforcementResult
Check if discovery depth is within bounds
Sourcepub async fn check_cost_threshold(
&self,
execution_id: &ExecutionId,
policy: &LongRunningExecutionPolicy,
) -> EnforcementResult
pub async fn check_cost_threshold( &self, execution_id: &ExecutionId, policy: &LongRunningExecutionPolicy, ) -> EnforcementResult
Check if cost threshold has been exceeded
Sourcepub async fn check_idle_timeout(
&self,
execution_id: &ExecutionId,
policy: &LongRunningExecutionPolicy,
) -> EnforcementResult
pub async fn check_idle_timeout( &self, execution_id: &ExecutionId, policy: &LongRunningExecutionPolicy, ) -> EnforcementResult
Check if idle timeout has been exceeded
Sourcepub async fn check_long_running_limits(
&self,
execution_id: &ExecutionId,
policy: &LongRunningExecutionPolicy,
) -> EnforcementResult
pub async fn check_long_running_limits( &self, execution_id: &ExecutionId, policy: &LongRunningExecutionPolicy, ) -> EnforcementResult
Perform all long-running execution checks