Documentation
¶
Overview ¶
Package policy evaluates immutable, side-effect-free automation rules for semantic agent events. It deliberately does not encode or deliver a decision: callers must fall back to a human whenever an adapter cannot represent the proposed action or a delivery fails.
Package policy evaluates immutable, side-effect-free automation rules for semantic agent events. It deliberately does not encode or deliver a decision: callers must fall back to a human whenever an adapter cannot represent the proposed action or a delivery fails.
Index ¶
Constants ¶
const ( ReasonDefault = "default_action" ReasonRule = "rule_match" ReasonInvalidEvent = "invalid_event" ReasonNonActionable = "non_actionable" ReasonSensitive = "sensitive_event" ReasonRisk = "risk_not_low" ReasonDryRun = "dry_run" ReasonNoEngine = "engine_unavailable" ReasonConsecutiveLimit = "consecutive_auto_limit" ReasonRateLimit = "rate_limit_exceeded" ReasonDestructive = "destructive_command_blocked" ReasonExfiltration = "exfiltration_attempt_blocked" ReasonGuardrailBlocked = "guardrail_pattern_blocked" )
Static evaluation reasons are safe to expose in logs. They never contain event text, regex matches, metadata, or other terminal output.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DefaultAction Action
DryRun bool
MaxConsecutiveAutoDecisions int
RateLimitPerMinute int
Guardrails GuardrailsConfig
Rules []Rule
}
Config describes the ordered rules evaluated by an Engine.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig preserves Relayer's human-in-the-loop behavior.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is immutable after construction and safe for concurrent evaluation.
func New ¶
New validates and defensively copies a policy configuration. Regexes are compiled once so Evaluate remains deterministic and allocation-light.
type Evaluation ¶
type Evaluation struct {
Action Action
ProposedAction Action
RuleName string
Reason string
EventID string
Automatic bool
DryRun bool
}
Evaluation separates the configured proposal from the effective action. Sensitive events and dry-run configurations retain ProposedAction for a safe audit record while forcing ActionAsk and disabling automation.
type GuardrailsConfig ¶
type GuardrailsConfig struct {
BlockDestructive bool
BlockExfiltration bool
BlockedPatterns []string
}
GuardrailsConfig defines safety boundaries that prevent autonomous execution of high-risk actions even when a policy rule would otherwise allow them.
type Match ¶
type Match struct {
EventTypes []adapters.EventType
TextRegex string
AgentIDs []string
RiskLevels []adapters.RiskLevel
Sensitive *bool
}
Match combines fields with AND semantics. Values inside each list use OR semantics. TextRegex is evaluated against Summary + "\n" + Match but that text is never retained by Engine or copied into Evaluation.
type Rule ¶
Rule applies Action when every populated Match field accepts an event. Rules are evaluated in order and the first match wins.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker manages session-level execution history for policy guardrails, including consecutive automatic decisions and sliding-window rate limits. It is thread-safe and safe for concurrent calls across different sessions.
func NewTrackerWithClock ¶
NewTrackerWithClock creates a Tracker with a custom clock function, primarily for deterministic unit testing.
func (*Tracker) CheckLimits ¶
CheckLimits checks whether an automatic decision is allowed for the given sessionID against the configured MaxConsecutiveAutoDecisions and RateLimitPerMinute. If a limit is exceeded, it returns (ActionAsk, reason, false). If limits are respected, it returns (ActionAllow, "", true).
func (*Tracker) Consecutive ¶
Consecutive returns the current consecutive automatic decision count for the session.
func (*Tracker) RecordAutoDecision ¶
RecordAutoDecision registers that an automatic decision was delivered for the session. It increments the consecutive counter and appends the current timestamp to the history window.
func (*Tracker) RecordHumanDecision ¶
RecordHumanDecision registers that an operator intervened for the session. It resets the consecutive counter to 0. Rate limiting timestamps remain intact.