Expand description
Policy primitive for AgentStateGraph.
Fourth-primitive sibling crate, parallel to agentstategraph-tasks.
Implements the authorization + change-cost primitive of the Policy v1
design (§§2-7 and §22; user guide: docs/POLICY_GUIDE.md). Ships the engine
surface only — MCP tools, CLI, and Lens UI live in their respective
consumer crates.
§What this crate is
Policyschema (situation-matching rules + procedure + change-cost gating fields)PolicyStore— a handle bound to aRepository+ prefix withpropose/ratify/supersede/evaluate/evaluate_changeSelector— a tagged-enum boolean expression over aSituationDecision— the evaluator’s result, includingRequireApprovalwith aFallbackAction(“what to do while it waits”)
§What this crate is NOT
- Not an enforcement layer (soft model — see POLICY_V1.md §11)
- Not a Rego/Cedar clone (the selector is a minimal DSL; external policy engines are a future escape hatch)
- Not an MCP tool or CLI — those belong to consumers
§Example
use agentstategraph::Repository;
use agentstategraph_storage::SqliteStorage;
use agentstategraph_policy::{PolicyStore, Situation, Selector};
use std::sync::Arc;
let repo = Arc::new(Repository::new(Box::new(SqliteStorage::in_memory().expect("in-memory sqlite"))));
repo.init().unwrap();
let store = PolicyStore::new(repo, "/policies", "claude-code");
// propose, ratify, evaluate ...
let _ = store.evaluate("main", &Situation::new(), "restart_pod", "agent-1");Re-exports§
pub use error::PolicyError;pub use external::ExternalError;pub use external::ExternalEvaluator;pub use external::ExternalEvaluatorRegistry;pub use selector::Selector;pub use selector::Situation;pub use store::PolicyStore;pub use types::ApprovalRule;pub use types::AuthorizedAction;pub use types::ChangeProposal;pub use types::Decision;pub use types::EvaluatorSource;pub use types::ExternalEvaluatorRef;pub use types::FallbackAction;pub use types::Policy;pub use types::PolicySignature;pub use types::ProcedureStep;pub use types::Severity;pub use verifier::SignatureVerificationError;pub use verifier::SignatureVerifier;
Modules§
- error
- Error type for
PolicyStoreoperations. - evaluator
- Pure evaluation logic. Operates on an already-loaded slice of
policies, so it can be exercised in unit tests without touching
storage. The
PolicyStoredefault impl is the production caller. - external
- External-evaluator dispatcher (0.7.5 §4a).
- paths
- Path construction helpers for the policy store.
- selector
- Situation selector grammar.
- store
PolicyStore— handle bound to aRepository+ path prefix.- types
- Public data types for policies, change proposals, and decisions.
- verifier
- Signature verifier trait for
PolicyStore.