Skip to content

Commit ff7af18

Browse files
feat: OPA/Rego and Cedar policy portability
Add pluggable policy backend support to both Agent OS and AgentMesh: Agent OS (PolicyEvaluator): - ExternalPolicyBackend protocol for pluggable backends - OPABackend: remote OPA server, local opa CLI, built-in Rego evaluator - CedarBackend: cedarpy bindings, cedar CLI, built-in permit/forbid parser - load_rego() and load_cedar() convenience methods - YAML rules checked first, then external backends in registration order - Fail-closed on errors, audit entries include backend metadata AgentMesh (PolicyEngine): - CedarEvaluator mirroring existing OPAEvaluator pattern - load_cedar() method on PolicyEngine - Cedar evaluated after YAML and Rego, before defaults - CedarDecision dataclass with evaluation_ms tracking Both backends support three modes: 1. Embedded engine (cedarpy / opa CLI) - fastest 2. Remote server (OPA REST API) 3. Built-in fallback - zero external deps, common patterns only Tests: 29 Agent OS + 21 AgentMesh = 50 new tests, all passing Existing 39 policy tests unaffected Also: - Optional deps: pip install agent-governance-toolkit[cedar] - README: OPA/Cedar usage examples - Comparison doc: OPA/Cedar marked as shipped (was 'planned') Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f8f6a1d commit ff7af18

File tree

11 files changed

+1841
-5
lines changed

11 files changed

+1841
-5
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,56 @@ if (result.Allowed) { /* proceed */ }
144144
- **[Tutorial 5: Agent Reliability](docs/tutorials/05-agent-reliability.md)** — SLOs, error budgets, chaos testing
145145
- **[Tutorial 6: Execution Sandboxing](docs/tutorials/06-execution-sandboxing.md)** — Privilege rings and termination
146146

147+
## OPA/Rego & Cedar Policy Support
148+
149+
Bring your existing infrastructure policies to agent governance — no new policy DSL required.
150+
151+
### OPA/Rego (Agent OS)
152+
153+
```python
154+
from agent_os.policies import PolicyEvaluator
155+
156+
evaluator = PolicyEvaluator()
157+
evaluator.load_rego(rego_content="""
158+
package agentos
159+
default allow = false
160+
allow { input.tool_name == "web_search" }
161+
allow { input.role == "admin" }
162+
""")
163+
164+
decision = evaluator.evaluate({"tool_name": "web_search", "role": "analyst"})
165+
# decision.allowed == True
166+
```
167+
168+
### Cedar (Agent OS)
169+
170+
```python
171+
from agent_os.policies import PolicyEvaluator
172+
173+
evaluator = PolicyEvaluator()
174+
evaluator.load_cedar(policy_content="""
175+
permit(principal, action == Action::"ReadData", resource);
176+
forbid(principal, action == Action::"DeleteFile", resource);
177+
""")
178+
179+
decision = evaluator.evaluate({"tool_name": "read_data", "agent_id": "agent-1"})
180+
# decision.allowed == True
181+
```
182+
183+
### AgentMesh OPA/Cedar
184+
185+
```python
186+
from agentmesh.governance import PolicyEngine
187+
188+
engine = PolicyEngine()
189+
engine.load_rego("policies/mesh.rego", package="agentmesh")
190+
engine.load_cedar(cedar_content='permit(principal, action == Action::"Analyze", resource);')
191+
192+
decision = engine.evaluate("did:mesh:agent-1", {"tool_name": "analyze"})
193+
```
194+
195+
Three evaluation modes per backend: **embedded engine** (cedarpy/opa CLI), **remote server**, or **built-in fallback** (zero external deps).
196+
147197
## SDKs & Packages
148198

149199
### Multi-Language SDKs

packages/agent-compliance/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ dependencies = [
3838
[project.optional-dependencies]
3939
runtime = ["agent-runtime>=2.0.0"]
4040
sre = ["agent-sre>=1.0.0"]
41+
opa = []
42+
cedar = ["cedarpy>=4.0.0"]
4143
full = [
4244
"agent-runtime>=2.0.0",
4345
"agent-sre>=1.0.0",

packages/agent-mesh/src/agentmesh/governance/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from .shadow import ShadowMode, ShadowResult
2727
from .opa import OPAEvaluator, OPADecision, load_rego_into_engine
28+
from .cedar import CedarEvaluator, CedarDecision, load_cedar_into_engine
2829
from .trust_policy import (
2930
TrustPolicy,
3031
TrustRule,
@@ -64,6 +65,9 @@
6465
"OPAEvaluator",
6566
"OPADecision",
6667
"load_rego_into_engine",
68+
"CedarEvaluator",
69+
"CedarDecision",
70+
"load_cedar_into_engine",
6771
"TrustPolicy",
6872
"TrustRule",
6973
"TrustCondition",

0 commit comments

Comments
 (0)