agentctrl 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentctrl-0.2.2/CHANGELOG.md +74 -0
- agentctrl-0.2.2/CONTRIBUTING.md +91 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/PKG-INFO +8 -7
- {agentctrl-0.2.0 → agentctrl-0.2.2}/README.md +6 -5
- agentctrl-0.2.2/SECURITY.md +46 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/examples/inbound_governance.py +14 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/pyproject.toml +2 -2
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/__main__.py +1 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/cli.py +1 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/decorator.py +2 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/risk_engine.py +13 -2
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/runtime_gateway.py +45 -6
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/types.py +1 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_decorator.py +3 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_parity_features.py +8 -4
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_pipeline.py +62 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_risk_engine.py +39 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_v02_features.py +2 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/uv.lock +1 -1
- {agentctrl-0.2.0 → agentctrl-0.2.2}/.gitignore +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/examples/bare_python.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/examples/langchain_tool.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/examples/openai_function_call.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/__init__.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/adapters/__init__.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/adapters/crewai.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/adapters/langchain.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/adapters/openai_agents.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/authority_graph.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/conflict_detector.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/policy_engine.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/src/agentctrl/py.typed +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_authority_graph.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_boundary.py +0 -0
- {agentctrl-0.2.0 → agentctrl-0.2.2}/tests/test_policy_engine.py +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `agentctrl` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## [0.2.2] — 2026-04-12
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- **Advisory context on early exit.** When a pipeline stage short-circuits with ESCALATE or BLOCK, remaining stages (risk, conflict) still run as `ADVISORY` — their results are appended to the decision record for reviewer visibility but do not change the decision.
|
|
13
|
+
- New `ADVISORY` status for `PipelineStageResult` (non-decision, informational).
|
|
14
|
+
- 3 new tests: `test_advisory_context_on_autonomy_escalate`, `test_advisory_context_on_early_exit`, `test_allow_has_no_advisory_stages`.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- `_run_pipeline()` early-exit paths now call `_collect_advisory_context()` instead of returning immediately.
|
|
18
|
+
- Test count updated to 8 (was 5 before advisory context tests).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## [0.2.1] — 2026-04-11
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- **Bidirectional trust calibration.** New agents (< 5 governed actions) receive a +0.35 risk surcharge, pushing routine actions into ESCALATE territory. Proven agents (50+ actions, >90% success rate) receive up to 15% risk discount.
|
|
26
|
+
- `trust_context` parameter on the `@governed` decorator — pass `{"total_actions": N, "success_rate": R}` to influence trust calibration.
|
|
27
|
+
- 2 new tests: `test_new_agent_premium`, `test_new_agent_premium_bypassed_after_threshold`.
|
|
28
|
+
- Apache-2.0 license header on `examples/inbound_governance.py`.
|
|
29
|
+
- `CONTRIBUTING.md` — library-scoped contribution guide.
|
|
30
|
+
- `SECURITY.md` — vulnerability reporting and security model.
|
|
31
|
+
- This `CHANGELOG.md`.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- Risk scoring dimensions documented as 13 (was incorrectly stated as 9 in README).
|
|
35
|
+
- Test count updated to 76 (was 74 before trust calibration tests).
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
- README: "nine factors" corrected to "13 dimensions" to match actual `score()` implementation.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## [0.2.0] — 2026-04-10
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
- CLI: `agentctrl demo`, `agentctrl validate`, `agentctrl init`.
|
|
46
|
+
- JSONL audit logging via `PipelineHooks`.
|
|
47
|
+
- `RuntimeDecisionRecord` — subscriptable (`record["decision"]`) and attribute-accessible (`record.decision`).
|
|
48
|
+
- Inbound governance example (`examples/inbound_governance.py`).
|
|
49
|
+
- Instance isolation — multiple `RuntimeGateway` instances with independent config.
|
|
50
|
+
- 76 tests (up from initial release).
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
- Core pipeline tightened: fail-closed invariant enforced at three levels.
|
|
54
|
+
- Trust calibration discount for proven agents (50+ actions, >90% success).
|
|
55
|
+
- Consequence class floors (irreversible actions never score LOW).
|
|
56
|
+
- Factor interaction multiplier (3+ concurrent factors trigger compounding).
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## [0.1.0] — 2026-04-07
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
- Initial release.
|
|
64
|
+
- 5-stage governance pipeline: Kill Switch → Rate Limiter → Policy Engine → Authority Graph → Risk Engine.
|
|
65
|
+
- `RuntimeGateway` — the main entry point.
|
|
66
|
+
- `PolicyEngine` — AND/OR groups, 14 operators, temporal conditions.
|
|
67
|
+
- `AuthorityGraphEngine` — NetworkX delegation, SoD, decay, time-bound edges.
|
|
68
|
+
- `RiskEngine` — factor-based scoring with configurable weights.
|
|
69
|
+
- `ConflictDetector` — resource contention checking.
|
|
70
|
+
- `@governed` decorator for enforcement.
|
|
71
|
+
- SDK adapters: LangChain, OpenAI Agents SDK, CrewAI.
|
|
72
|
+
- 4 runnable examples.
|
|
73
|
+
- Zero required dependencies.
|
|
74
|
+
- Apache-2.0 license.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Contributing to agentctrl
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing to `agentctrl` — the institutional governance layer for AI agents.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/moeintel/AgentCTRL.git
|
|
11
|
+
cd AgentCTRL
|
|
12
|
+
pip install -e ".[dev,all]"
|
|
13
|
+
python -m pytest tests/ -v
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Development Setup
|
|
19
|
+
|
|
20
|
+
**Requirements:** Python 3.11+
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install -e ".[dev,all]"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This installs the library in editable mode with all optional dependencies (networkx, langchain-core, openai-agents, crewai) and dev tools (pytest, pytest-asyncio, ruff).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Running Tests
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python -m pytest tests/ -v
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
79 tests total (78 pass, 1 skipped). No external services required — everything runs in-process.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Linting
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
ruff check src/ tests/
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Making Changes
|
|
49
|
+
|
|
50
|
+
### Before you start
|
|
51
|
+
|
|
52
|
+
1. Check existing issues and discussions to avoid duplicate work.
|
|
53
|
+
2. For larger changes, open an issue first to discuss the approach.
|
|
54
|
+
|
|
55
|
+
### Guidelines
|
|
56
|
+
|
|
57
|
+
- **Keep the library self-contained.** Zero required dependencies. No imports from external packages in the core library (adapters are the exception — they use lazy imports).
|
|
58
|
+
- **Write tests.** Every new feature or bug fix should include tests.
|
|
59
|
+
- **Preserve the fail-closed invariant.** Any error in the governance pipeline must produce BLOCK, never silent ALLOW.
|
|
60
|
+
- **Type hints everywhere.** The library is PEP 561 typed.
|
|
61
|
+
|
|
62
|
+
### Pull request process
|
|
63
|
+
|
|
64
|
+
1. Fork the repository
|
|
65
|
+
2. Create a feature branch (`git checkout -b my-feature`)
|
|
66
|
+
3. Make your changes
|
|
67
|
+
4. Ensure all tests pass
|
|
68
|
+
5. Ensure linting passes
|
|
69
|
+
6. Submit a pull request with a clear description of what and why
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Areas Where Contributions Are Welcome
|
|
74
|
+
|
|
75
|
+
- **More tests** — edge cases for policy engine, authority graph, risk scoring
|
|
76
|
+
- **Integration examples** — additional `examples/` scripts showing `agentctrl` with different agent frameworks
|
|
77
|
+
- **Documentation** — usage guides, tutorials, integration walkthroughs
|
|
78
|
+
- **Bug reports** — especially around edge cases in policy evaluation or authority resolution
|
|
79
|
+
- **Adapter coverage** — new framework adapters in `src/agentctrl/adapters/`
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Code of Conduct
|
|
84
|
+
|
|
85
|
+
Be respectful, constructive, and professional. We're building governance infrastructure — the bar for quality and honesty is high.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Questions?
|
|
90
|
+
|
|
91
|
+
Open an issue on [GitHub](https://github.com/moeintel/AgentCTRL/issues).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agentctrl
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Institutional control layer for AI agent actions — authority, policy, risk, and audit before execution.
|
|
5
|
-
Project-URL: Homepage, https://moeintel.
|
|
5
|
+
Project-URL: Homepage, https://moeintel.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/moeintel/AgentCTRL
|
|
7
7
|
Project-URL: Issues, https://github.com/moeintel/AgentCTRL/issues
|
|
8
8
|
Author: MoeIntel
|
|
@@ -116,7 +116,7 @@ Those are institutional controls. They existed for human employees. They need to
|
|
|
116
116
|
- **Fail-closed.** Any pipeline error produces BLOCK, never silent approval.
|
|
117
117
|
- **Structural enforcement.** Policies are operator-based rule matching, not prompt instructions. Authority is graph traversal. Risk is weighted factor scoring. None of this is prompt engineering.
|
|
118
118
|
|
|
119
|
-
> **Status:**
|
|
119
|
+
> **Status:** 79 tests passing. Published on [PyPI](https://pypi.org/project/agentctrl/).
|
|
120
120
|
|
|
121
121
|
---
|
|
122
122
|
|
|
@@ -333,7 +333,7 @@ agent = Agent(role="analyst", tools=[governed_tool])
|
|
|
333
333
|
|
|
334
334
|
## Decision Pipeline
|
|
335
335
|
|
|
336
|
-
Every action passes through 5 stages in order. Each can short-circuit.
|
|
336
|
+
Every action passes through 5 stages in order. Each can short-circuit with BLOCK or ESCALATE. When a stage short-circuits, remaining stages still run as **ADVISORY** — their results are appended to the decision record for reviewer visibility but do not change the decision.
|
|
337
337
|
|
|
338
338
|
```
|
|
339
339
|
Agent proposes action
|
|
@@ -345,6 +345,7 @@ Agent proposes action
|
|
|
345
345
|
→ Risk Scoring (how risky is this action in context?)
|
|
346
346
|
→ Conflict Detection (does this clash with other active workflows?)
|
|
347
347
|
→ Decision: ALLOW / ESCALATE / BLOCK
|
|
348
|
+
(+ ADVISORY stages from remaining pipeline on early exit)
|
|
348
349
|
```
|
|
349
350
|
|
|
350
351
|
### Policy Engine
|
|
@@ -359,7 +360,7 @@ Authority is opt-in. When no graph is configured, the authority check passes. Co
|
|
|
359
360
|
|
|
360
361
|
### Risk Scoring
|
|
361
362
|
|
|
362
|
-
Deterministic factor-based scoring
|
|
363
|
+
Deterministic factor-based scoring across 13 dimensions: base action risk, high-value transaction, novel vendor, off-hours activity, data sensitivity, rate pressure, velocity, behavioral anomaly, cumulative exposure, input confidence, trust calibration (agents with 50+ governed actions and >90% success rate earn up to 15% reduction), factor interaction (3+ concurrent factors trigger compounding), and consequence class floors (irreversible actions never score LOW).
|
|
363
364
|
|
|
364
365
|
### Conflict Detection
|
|
365
366
|
|
|
@@ -440,7 +441,7 @@ result = await gateway.validate(proposal)
|
|
|
440
441
|
python -m pytest tests/ -v
|
|
441
442
|
```
|
|
442
443
|
|
|
443
|
-
|
|
444
|
+
79 tests covering: pipeline stages, advisory context, fail-closed behavior, policy evaluation (AND/OR groups, 14 operators, temporal conditions), authority graph (delegation, SoD, limits, decay), risk scoring (13 dimensions, trust calibration, consequence class), conflict detection, `@governed` decorator, CLI, demo, audit logging, subscriptable record, empty authority default, instance isolation, and library boundary.
|
|
444
445
|
|
|
445
446
|
## Requirements
|
|
446
447
|
|
|
@@ -455,4 +456,4 @@ python -m pytest tests/ -v
|
|
|
455
456
|
|
|
456
457
|
---
|
|
457
458
|
|
|
458
|
-
Built by [MoeIntel](https://moeintel.
|
|
459
|
+
Built by [MoeIntel](https://moeintel.ai). Created by [Mohammad Abu Jafar](https://github.com/moeadnan). [GitHub](https://github.com/moeintel/AgentCTRL)
|
|
@@ -76,7 +76,7 @@ Those are institutional controls. They existed for human employees. They need to
|
|
|
76
76
|
- **Fail-closed.** Any pipeline error produces BLOCK, never silent approval.
|
|
77
77
|
- **Structural enforcement.** Policies are operator-based rule matching, not prompt instructions. Authority is graph traversal. Risk is weighted factor scoring. None of this is prompt engineering.
|
|
78
78
|
|
|
79
|
-
> **Status:**
|
|
79
|
+
> **Status:** 79 tests passing. Published on [PyPI](https://pypi.org/project/agentctrl/).
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
@@ -293,7 +293,7 @@ agent = Agent(role="analyst", tools=[governed_tool])
|
|
|
293
293
|
|
|
294
294
|
## Decision Pipeline
|
|
295
295
|
|
|
296
|
-
Every action passes through 5 stages in order. Each can short-circuit.
|
|
296
|
+
Every action passes through 5 stages in order. Each can short-circuit with BLOCK or ESCALATE. When a stage short-circuits, remaining stages still run as **ADVISORY** — their results are appended to the decision record for reviewer visibility but do not change the decision.
|
|
297
297
|
|
|
298
298
|
```
|
|
299
299
|
Agent proposes action
|
|
@@ -305,6 +305,7 @@ Agent proposes action
|
|
|
305
305
|
→ Risk Scoring (how risky is this action in context?)
|
|
306
306
|
→ Conflict Detection (does this clash with other active workflows?)
|
|
307
307
|
→ Decision: ALLOW / ESCALATE / BLOCK
|
|
308
|
+
(+ ADVISORY stages from remaining pipeline on early exit)
|
|
308
309
|
```
|
|
309
310
|
|
|
310
311
|
### Policy Engine
|
|
@@ -319,7 +320,7 @@ Authority is opt-in. When no graph is configured, the authority check passes. Co
|
|
|
319
320
|
|
|
320
321
|
### Risk Scoring
|
|
321
322
|
|
|
322
|
-
Deterministic factor-based scoring
|
|
323
|
+
Deterministic factor-based scoring across 13 dimensions: base action risk, high-value transaction, novel vendor, off-hours activity, data sensitivity, rate pressure, velocity, behavioral anomaly, cumulative exposure, input confidence, trust calibration (agents with 50+ governed actions and >90% success rate earn up to 15% reduction), factor interaction (3+ concurrent factors trigger compounding), and consequence class floors (irreversible actions never score LOW).
|
|
323
324
|
|
|
324
325
|
### Conflict Detection
|
|
325
326
|
|
|
@@ -400,7 +401,7 @@ result = await gateway.validate(proposal)
|
|
|
400
401
|
python -m pytest tests/ -v
|
|
401
402
|
```
|
|
402
403
|
|
|
403
|
-
|
|
404
|
+
79 tests covering: pipeline stages, advisory context, fail-closed behavior, policy evaluation (AND/OR groups, 14 operators, temporal conditions), authority graph (delegation, SoD, limits, decay), risk scoring (13 dimensions, trust calibration, consequence class), conflict detection, `@governed` decorator, CLI, demo, audit logging, subscriptable record, empty authority default, instance isolation, and library boundary.
|
|
404
405
|
|
|
405
406
|
## Requirements
|
|
406
407
|
|
|
@@ -415,4 +416,4 @@ python -m pytest tests/ -v
|
|
|
415
416
|
|
|
416
417
|
---
|
|
417
418
|
|
|
418
|
-
Built by [MoeIntel](https://moeintel.
|
|
419
|
+
Built by [MoeIntel](https://moeintel.ai). Created by [Mohammad Abu Jafar](https://github.com/moeadnan). [GitHub](https://github.com/moeintel/AgentCTRL)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
If you discover a security vulnerability in `agentctrl`, please report it responsibly.
|
|
6
|
+
|
|
7
|
+
**Do not open a public GitHub issue for security vulnerabilities.**
|
|
8
|
+
|
|
9
|
+
Instead, use [GitHub's private security advisory feature](https://github.com/moeintel/AgentCTRL/security/advisories/new) or email **security@moeintel.ai**.
|
|
10
|
+
|
|
11
|
+
Include:
|
|
12
|
+
- Description of the vulnerability
|
|
13
|
+
- Steps to reproduce
|
|
14
|
+
- Potential impact
|
|
15
|
+
- Suggested fix (if you have one)
|
|
16
|
+
|
|
17
|
+
We will acknowledge receipt within 48 hours and provide a fix or mitigation plan within 7 days for critical issues.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Security Model
|
|
22
|
+
|
|
23
|
+
`agentctrl` is a governance enforcement library. It evaluates agent actions against policies, authority graphs, and risk scores, then returns ALLOW / ESCALATE / BLOCK decisions.
|
|
24
|
+
|
|
25
|
+
### What agentctrl enforces
|
|
26
|
+
|
|
27
|
+
- **Fail-closed design.** Any error in the governance pipeline produces BLOCK, never ALLOW. Three independent layers enforce this (gateway catch, stage-level catch, top-level catch).
|
|
28
|
+
- **Deterministic evaluation.** Policy matching, authority resolution, and risk scoring are all deterministic — no LLM calls, no prompt engineering, no probabilistic behavior.
|
|
29
|
+
- **Structural enforcement.** Policies use operator-based rule matching. Authority is graph traversal. Risk is weighted factor scoring. None of this is prompt-based.
|
|
30
|
+
|
|
31
|
+
### What agentctrl does NOT enforce
|
|
32
|
+
|
|
33
|
+
- **Caller identity verification.** `agent_id` is a self-declared string. The library does not verify that the caller actually is that agent. Your application is responsible for identity.
|
|
34
|
+
- **Bypass prevention.** If a tool is called directly without going through `RuntimeGateway` or `@governed`, agentctrl has no visibility. Governance only covers actions routed through the library.
|
|
35
|
+
- **Persistence.** The library is stateless by default. Rate limiting uses in-memory counters that reset on restart. For durable state, integrate with your own storage.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Supported Versions
|
|
40
|
+
|
|
41
|
+
| Version | Supported |
|
|
42
|
+
|---------|-----------|
|
|
43
|
+
| 0.2.x | Yes |
|
|
44
|
+
| < 0.2 | No |
|
|
45
|
+
|
|
46
|
+
Security fixes will be applied to the latest release.
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# Copyright 2026 MoeIntel
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
1
15
|
"""Inbound governance — controlling what external agents can do in YOUR system.
|
|
2
16
|
|
|
3
17
|
This example shows how to use agentctrl to govern actions initiated by external
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "agentctrl"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "Institutional control layer for AI agent actions — authority, policy, risk, and audit before execution."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -40,7 +40,7 @@ classifiers = [
|
|
|
40
40
|
agentctrl = "agentctrl.cli:main"
|
|
41
41
|
|
|
42
42
|
[project.urls]
|
|
43
|
-
Homepage = "https://moeintel.
|
|
43
|
+
Homepage = "https://moeintel.ai"
|
|
44
44
|
Repository = "https://github.com/moeintel/AgentCTRL"
|
|
45
45
|
Issues = "https://github.com/moeintel/AgentCTRL/issues"
|
|
46
46
|
|
|
@@ -233,7 +233,7 @@ def _print_footer(results: list):
|
|
|
233
233
|
print(f" {DIM}5 stages × {len(results)} proposals = every action evaluated through:{RESET}")
|
|
234
234
|
print(f" {DIM}autonomy → policy → authority → risk → conflict{RESET}")
|
|
235
235
|
print()
|
|
236
|
-
print(f" {WHITE}pip install agentctrl{RESET} {DIM}·{RESET} {WHITE}github.com/moeintel/
|
|
236
|
+
print(f" {WHITE}pip install agentctrl{RESET} {DIM}·{RESET} {WHITE}github.com/moeintel/AgentCTRL{RESET}")
|
|
237
237
|
print()
|
|
238
238
|
|
|
239
239
|
|
|
@@ -155,7 +155,7 @@ def cmd_init(args):
|
|
|
155
155
|
print()
|
|
156
156
|
print("Quick start:")
|
|
157
157
|
print(f' agentctrl validate --policies {target / "policies.json"} \\')
|
|
158
|
-
print(
|
|
158
|
+
print(' \'{"agent_id": "analyst", "action_type": "invoice.approve", "action_params": {"amount": 6000}}\'')
|
|
159
159
|
else:
|
|
160
160
|
print("No files created (all already exist).")
|
|
161
161
|
|
|
@@ -27,6 +27,7 @@ def governed(
|
|
|
27
27
|
agent_id: str,
|
|
28
28
|
autonomy_level: int = 2,
|
|
29
29
|
action_type: str | None = None,
|
|
30
|
+
trust_context: dict | None = None,
|
|
30
31
|
):
|
|
31
32
|
"""Decorator that wraps an async function with governance evaluation.
|
|
32
33
|
|
|
@@ -53,6 +54,7 @@ def governed(
|
|
|
53
54
|
action_type=resolved_action_type,
|
|
54
55
|
action_params=action_params,
|
|
55
56
|
autonomy_level=autonomy_level,
|
|
57
|
+
trust_context=trust_context,
|
|
56
58
|
)
|
|
57
59
|
|
|
58
60
|
result = await gateway.validate(proposal)
|
|
@@ -198,11 +198,22 @@ class RiskEngine:
|
|
|
198
198
|
"value": f"Daily exposure: ${daily_exposure:,.0f} (threshold: ${exp_threshold:,.0f})",
|
|
199
199
|
})
|
|
200
200
|
|
|
201
|
-
# Trust calibration —
|
|
201
|
+
# Trust calibration — bidirectional risk adjustment based on agent track record.
|
|
202
|
+
# New agents (< new_agent_threshold actions) receive a risk surcharge.
|
|
203
|
+
# Proven agents (50+ actions, >90% success) receive a risk discount.
|
|
202
204
|
trust_ctx = getattr(proposal, "trust_context", None) or {}
|
|
203
205
|
trust_total_actions = trust_ctx.get("total_actions", 0)
|
|
204
206
|
trust_success_rate = trust_ctx.get("success_rate", 0.0)
|
|
205
|
-
|
|
207
|
+
new_agent_threshold = self._factors.get("new_agent_premium", {}).get("threshold", 5)
|
|
208
|
+
new_agent_weight = self._factors.get("new_agent_premium", {}).get("weight", 0.35)
|
|
209
|
+
if trust_total_actions < new_agent_threshold:
|
|
210
|
+
total += new_agent_weight
|
|
211
|
+
factors.append({
|
|
212
|
+
"factor": "trust_calibration",
|
|
213
|
+
"contribution": round(new_agent_weight, 3),
|
|
214
|
+
"value": f"New agent — {trust_total_actions} prior actions (threshold: {new_agent_threshold})",
|
|
215
|
+
})
|
|
216
|
+
elif trust_total_actions >= 50 and trust_success_rate > 0.90:
|
|
206
217
|
trust_discount = min(0.15, (trust_success_rate - 0.90) * 1.5)
|
|
207
218
|
total = max(0.01, total - trust_discount)
|
|
208
219
|
factors.append({
|
|
@@ -19,7 +19,9 @@ Runtime Governance Model — Layer 1
|
|
|
19
19
|
The pipeline evaluates every ActionProposal through 5 sequential decision
|
|
20
20
|
stages (autonomy → policy → authority → risk → conflict). Each stage can
|
|
21
21
|
short-circuit with BLOCK or ESCALATE. If all stages pass, the decision
|
|
22
|
-
is ALLOW.
|
|
22
|
+
is ALLOW. On early ESCALATE/BLOCK, remaining stages still run as ADVISORY
|
|
23
|
+
context — their results are appended to the decision record for reviewer
|
|
24
|
+
visibility but do not change the decision.
|
|
23
25
|
|
|
24
26
|
The kill switch is an optional pre-gate callback (`kill_switch_fn`) so
|
|
25
27
|
the library works without platform dependencies. Fail-closed: any
|
|
@@ -154,9 +156,8 @@ class RuntimeGateway:
|
|
|
154
156
|
if stage1.status == "BLOCK":
|
|
155
157
|
return self._make_decision(proposal, stages, "BLOCK", stage1.reason, 0.0, "LOW")
|
|
156
158
|
if stage1.status == "ESCALATE":
|
|
157
|
-
risk = await self.
|
|
158
|
-
stages.
|
|
159
|
-
{"risk_score": risk.score, "risk_level": risk.level}))
|
|
159
|
+
risk, advisory = await self._collect_advisory_context(proposal, from_stage=1)
|
|
160
|
+
stages.extend(advisory)
|
|
160
161
|
return self._make_decision(proposal, stages, "ESCALATE", stage1.reason,
|
|
161
162
|
risk.score, risk.level, escalated_to="approver_required")
|
|
162
163
|
|
|
@@ -164,7 +165,8 @@ class RuntimeGateway:
|
|
|
164
165
|
stage2 = await self.policy_engine.validate(proposal)
|
|
165
166
|
stages.append(stage2)
|
|
166
167
|
if stage2.status in ("BLOCK", "ESCALATE"):
|
|
167
|
-
risk = await self.
|
|
168
|
+
risk, advisory = await self._collect_advisory_context(proposal, from_stage=2)
|
|
169
|
+
stages.extend(advisory)
|
|
168
170
|
return self._make_decision(proposal, stages, stage2.status, stage2.reason,
|
|
169
171
|
risk.score, risk.level)
|
|
170
172
|
|
|
@@ -172,7 +174,8 @@ class RuntimeGateway:
|
|
|
172
174
|
stage3 = await self.authority_engine.resolve(proposal)
|
|
173
175
|
stages.append(stage3)
|
|
174
176
|
if stage3.status in ("BLOCK", "ESCALATE"):
|
|
175
|
-
risk = await self.
|
|
177
|
+
risk, advisory = await self._collect_advisory_context(proposal, from_stage=3)
|
|
178
|
+
stages.extend(advisory)
|
|
176
179
|
escalated_to = stage3.details.get("escalate_to")
|
|
177
180
|
return self._make_decision(proposal, stages, stage3.status, stage3.reason,
|
|
178
181
|
risk.score, risk.level, escalated_to=escalated_to)
|
|
@@ -187,6 +190,8 @@ class RuntimeGateway:
|
|
|
187
190
|
)
|
|
188
191
|
stages.append(stage4)
|
|
189
192
|
if stage4.status == "ESCALATE":
|
|
193
|
+
_risk, advisory = await self._collect_advisory_context(proposal, from_stage=4)
|
|
194
|
+
stages.extend(advisory)
|
|
190
195
|
return self._make_decision(proposal, stages, "ESCALATE", stage4.reason,
|
|
191
196
|
risk.score, risk.level)
|
|
192
197
|
|
|
@@ -202,6 +207,40 @@ class RuntimeGateway:
|
|
|
202
207
|
reason = f"All validation stages passed. Action '{proposal.action_type}' approved for execution."
|
|
203
208
|
return self._make_decision(proposal, stages, "ALLOW", reason, risk.score, risk.level)
|
|
204
209
|
|
|
210
|
+
async def _collect_advisory_context(
|
|
211
|
+
self, proposal: ActionProposal, from_stage: int,
|
|
212
|
+
) -> tuple:
|
|
213
|
+
"""Run remaining pipeline stages as non-decision ADVISORY context.
|
|
214
|
+
|
|
215
|
+
Gives the human reviewer visibility into what risk and conflict
|
|
216
|
+
would have said, even though an earlier stage already decided.
|
|
217
|
+
Returns (risk_result, list_of_advisory_stages).
|
|
218
|
+
``from_stage`` is the stage number that triggered the early exit
|
|
219
|
+
(1=autonomy, 2=policy, 3=authority, 4=risk).
|
|
220
|
+
"""
|
|
221
|
+
advisory_stages: list[PipelineStageResult] = []
|
|
222
|
+
if from_stage < 4:
|
|
223
|
+
risk = await self.risk_engine.score(proposal)
|
|
224
|
+
advisory_stages.append(
|
|
225
|
+
PipelineStageResult(
|
|
226
|
+
"risk_scoring", "ADVISORY",
|
|
227
|
+
{"risk_score": risk.score, "risk_level": risk.level, "factors": risk.factors},
|
|
228
|
+
f"Advisory: Risk level {risk.level} (score: {risk.score:.2f})",
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
else:
|
|
232
|
+
risk = None
|
|
233
|
+
if from_stage < 5:
|
|
234
|
+
conflict = await self.conflict_detector.check(proposal)
|
|
235
|
+
advisory_stages.append(
|
|
236
|
+
PipelineStageResult(
|
|
237
|
+
"conflict_detection", "ADVISORY",
|
|
238
|
+
{"original_status": conflict.status, **(conflict.details or {})},
|
|
239
|
+
f"Advisory: {conflict.reason}",
|
|
240
|
+
)
|
|
241
|
+
)
|
|
242
|
+
return risk, advisory_stages
|
|
243
|
+
|
|
205
244
|
async def _check_autonomy(self, proposal: ActionProposal) -> PipelineStageResult:
|
|
206
245
|
level = proposal.autonomy_level
|
|
207
246
|
action = proposal.action_type.split(".")[0] if "." in proposal.action_type else proposal.action_type
|
|
@@ -51,7 +51,7 @@ class ActionProposal:
|
|
|
51
51
|
class PipelineStageResult:
|
|
52
52
|
"""Result from a single pipeline stage."""
|
|
53
53
|
stage: str
|
|
54
|
-
status: str # PASS | FAIL | ESCALATE | BLOCK
|
|
54
|
+
status: str # PASS | FAIL | ESCALATE | BLOCK | ADVISORY
|
|
55
55
|
details: dict = field(default_factory=dict)
|
|
56
56
|
reason: str = ""
|
|
57
57
|
|
|
@@ -26,7 +26,9 @@ async def test_governed_execute_happy_path():
|
|
|
26
26
|
|
|
27
27
|
gateway = RuntimeGateway()
|
|
28
28
|
|
|
29
|
-
@governed(gateway=gateway, agent_id="ap_analyst", autonomy_level=2,
|
|
29
|
+
@governed(gateway=gateway, agent_id="ap_analyst", autonomy_level=2,
|
|
30
|
+
action_type="invoice.approve",
|
|
31
|
+
trust_context={"total_actions": 10, "success_rate": 0.95})
|
|
30
32
|
async def approve_invoice(amount: float):
|
|
31
33
|
return {"ok": True, "amount": amount}
|
|
32
34
|
|
|
@@ -91,7 +91,8 @@ class TestRiskEngineNewFactors:
|
|
|
91
91
|
from agentctrl import RiskEngine, ActionProposal
|
|
92
92
|
engine = RiskEngine()
|
|
93
93
|
p = ActionProposal(agent_id="a", action_type="search",
|
|
94
|
-
action_params={}, consequence_class="reversible"
|
|
94
|
+
action_params={}, consequence_class="reversible",
|
|
95
|
+
trust_context={"total_actions": 10, "success_rate": 0.95})
|
|
95
96
|
score = await engine.score(p)
|
|
96
97
|
assert score.score < 0.30
|
|
97
98
|
|
|
@@ -458,12 +459,14 @@ class TestGatewayNewFeatures:
|
|
|
458
459
|
for _ in range(2):
|
|
459
460
|
r = await gw.validate(ActionProposal(
|
|
460
461
|
agent_id="ap_analyst", action_type="invoice.approve",
|
|
461
|
-
action_params={"amount": 100}, autonomy_level=2
|
|
462
|
+
action_params={"amount": 100}, autonomy_level=2,
|
|
463
|
+
trust_context={"total_actions": 10, "success_rate": 0.95}))
|
|
462
464
|
assert r["decision"] == "ALLOW"
|
|
463
465
|
|
|
464
466
|
r = await gw.validate(ActionProposal(
|
|
465
467
|
agent_id="ap_analyst", action_type="invoice.approve",
|
|
466
|
-
action_params={"amount": 100}, autonomy_level=2
|
|
468
|
+
action_params={"amount": 100}, autonomy_level=2,
|
|
469
|
+
trust_context={"total_actions": 10, "success_rate": 0.95}))
|
|
467
470
|
assert r["decision"] == "BLOCK"
|
|
468
471
|
assert "rate_limit" in r["pipeline"][0]["stage"]
|
|
469
472
|
|
|
@@ -476,7 +479,8 @@ class TestGatewayNewFeatures:
|
|
|
476
479
|
gw = RuntimeGateway(autonomy_scopes=scopes)
|
|
477
480
|
r = await gw.validate(ActionProposal(
|
|
478
481
|
agent_id="ap_analyst", action_type="invoice.approve",
|
|
479
|
-
action_params={"amount": 3000}, autonomy_level=2
|
|
482
|
+
action_params={"amount": 3000}, autonomy_level=2,
|
|
483
|
+
trust_context={"total_actions": 10, "success_rate": 0.95}))
|
|
480
484
|
assert r["decision"] == "ALLOW"
|
|
481
485
|
|
|
482
486
|
@pytest.mark.asyncio
|
|
@@ -30,6 +30,7 @@ async def test_low_risk_action_executes():
|
|
|
30
30
|
action_type="invoice.approve",
|
|
31
31
|
action_params={"amount": 1000},
|
|
32
32
|
autonomy_level=2,
|
|
33
|
+
trust_context={"total_actions": 10, "success_rate": 0.95},
|
|
33
34
|
))
|
|
34
35
|
assert result["decision"] == "ALLOW"
|
|
35
36
|
|
|
@@ -83,7 +84,7 @@ async def test_hooks_called():
|
|
|
83
84
|
|
|
84
85
|
decisions = []
|
|
85
86
|
hooks = PipelineHooks(
|
|
86
|
-
on_decision=lambda d, p, s,
|
|
87
|
+
on_decision=lambda d, p, s, log: decisions.append(d),
|
|
87
88
|
)
|
|
88
89
|
gateway = RuntimeGateway(hooks=hooks)
|
|
89
90
|
await gateway.validate(ActionProposal(
|
|
@@ -93,3 +94,63 @@ async def test_hooks_called():
|
|
|
93
94
|
autonomy_level=2,
|
|
94
95
|
))
|
|
95
96
|
assert len(decisions) == 1
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@pytest.mark.asyncio
|
|
100
|
+
async def test_advisory_context_on_autonomy_escalate():
|
|
101
|
+
"""Level 1 agent escalates at autonomy; risk + conflict run as ADVISORY."""
|
|
102
|
+
from agentctrl import RuntimeGateway, ActionProposal
|
|
103
|
+
|
|
104
|
+
gateway = RuntimeGateway()
|
|
105
|
+
result = await gateway.validate(ActionProposal(
|
|
106
|
+
agent_id="junior-agent",
|
|
107
|
+
action_type="email.send",
|
|
108
|
+
action_params={"to": "user@example.com"},
|
|
109
|
+
autonomy_level=1,
|
|
110
|
+
))
|
|
111
|
+
assert result["decision"] == "ESCALATE"
|
|
112
|
+
stages = result["pipeline"]
|
|
113
|
+
advisory_stages = [s for s in stages if s["status"] == "ADVISORY"]
|
|
114
|
+
assert len(advisory_stages) == 2, f"Expected 2 advisory stages, got {len(advisory_stages)}"
|
|
115
|
+
advisory_names = {s["stage"] for s in advisory_stages}
|
|
116
|
+
assert "risk_scoring" in advisory_names
|
|
117
|
+
assert "conflict_detection" in advisory_names
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@pytest.mark.asyncio
|
|
121
|
+
async def test_advisory_context_on_early_exit():
|
|
122
|
+
"""Early BLOCK/ESCALATE still collects advisory risk + conflict stages."""
|
|
123
|
+
from agentctrl import RuntimeGateway, ActionProposal
|
|
124
|
+
from agentctrl.policy_engine import PolicyEngine
|
|
125
|
+
|
|
126
|
+
policies = [{"action_type": "delete.*", "effect": "BLOCK", "reason": "Deletes are forbidden"}]
|
|
127
|
+
gateway = RuntimeGateway(policy_engine=PolicyEngine(policies=policies))
|
|
128
|
+
result = await gateway.validate(ActionProposal(
|
|
129
|
+
agent_id="analyst",
|
|
130
|
+
action_type="delete.records",
|
|
131
|
+
action_params={},
|
|
132
|
+
autonomy_level=3,
|
|
133
|
+
))
|
|
134
|
+
assert result["decision"] in ("BLOCK", "ESCALATE")
|
|
135
|
+
advisory_stages = [s for s in result["pipeline"] if s["status"] == "ADVISORY"]
|
|
136
|
+
assert len(advisory_stages) >= 1, "At least one ADVISORY stage expected"
|
|
137
|
+
advisory_names = {s["stage"] for s in advisory_stages}
|
|
138
|
+
assert "risk_scoring" in advisory_names or "conflict_detection" in advisory_names
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@pytest.mark.asyncio
|
|
142
|
+
async def test_allow_has_no_advisory_stages():
|
|
143
|
+
"""Normal ALLOW path has no ADVISORY stages — all stages run as real decisions."""
|
|
144
|
+
from agentctrl import RuntimeGateway, ActionProposal
|
|
145
|
+
|
|
146
|
+
gateway = RuntimeGateway()
|
|
147
|
+
result = await gateway.validate(ActionProposal(
|
|
148
|
+
agent_id="ap_analyst",
|
|
149
|
+
action_type="invoice.approve",
|
|
150
|
+
action_params={"amount": 1000},
|
|
151
|
+
autonomy_level=2,
|
|
152
|
+
trust_context={"total_actions": 10, "success_rate": 0.95},
|
|
153
|
+
))
|
|
154
|
+
assert result["decision"] == "ALLOW"
|
|
155
|
+
advisory_stages = [s for s in result["pipeline"] if s["status"] == "ADVISORY"]
|
|
156
|
+
assert len(advisory_stages) == 0
|
|
@@ -141,3 +141,42 @@ async def test_configurable_base_risks():
|
|
|
141
141
|
score = await engine.score(proposal)
|
|
142
142
|
base_factors = [f for f in score.factors if f.get("factor") == "base_action_risk"]
|
|
143
143
|
assert base_factors[0]["contribution"] == 0.99
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@pytest.mark.asyncio
|
|
147
|
+
async def test_new_agent_premium():
|
|
148
|
+
"""New agents (< 5 actions) receive a risk surcharge via trust_calibration."""
|
|
149
|
+
from agentctrl import RiskEngine, ActionProposal
|
|
150
|
+
|
|
151
|
+
engine = RiskEngine()
|
|
152
|
+
proposal = ActionProposal(
|
|
153
|
+
agent_id="brand-new-agent",
|
|
154
|
+
action_type="invoice.approve",
|
|
155
|
+
action_params={"amount": 1000},
|
|
156
|
+
autonomy_level=2,
|
|
157
|
+
trust_context={"total_actions": 0, "success_rate": 0.0},
|
|
158
|
+
)
|
|
159
|
+
score = await engine.score(proposal)
|
|
160
|
+
trust = [f for f in score.factors if f.get("factor") == "trust_calibration"]
|
|
161
|
+
assert trust
|
|
162
|
+
assert trust[0]["contribution"] > 0
|
|
163
|
+
assert score.level in ("HIGH", "CRITICAL")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@pytest.mark.asyncio
|
|
167
|
+
async def test_new_agent_premium_bypassed_after_threshold():
|
|
168
|
+
"""Agents above the new-agent threshold do not receive the surcharge."""
|
|
169
|
+
from agentctrl import RiskEngine, ActionProposal
|
|
170
|
+
|
|
171
|
+
engine = RiskEngine()
|
|
172
|
+
proposal = ActionProposal(
|
|
173
|
+
agent_id="established-agent",
|
|
174
|
+
action_type="invoice.approve",
|
|
175
|
+
action_params={"amount": 1000},
|
|
176
|
+
autonomy_level=2,
|
|
177
|
+
trust_context={"total_actions": 10, "success_rate": 0.90},
|
|
178
|
+
)
|
|
179
|
+
score = await engine.score(proposal)
|
|
180
|
+
trust = [f for f in score.factors if f.get("factor") == "trust_calibration"]
|
|
181
|
+
assert not trust
|
|
182
|
+
assert score.level in ("LOW", "MEDIUM")
|
|
@@ -132,7 +132,8 @@ class TestEmptyAuthorityDefault:
|
|
|
132
132
|
gw = RuntimeGateway()
|
|
133
133
|
r = await gw.validate(ActionProposal(
|
|
134
134
|
agent_id="agent-1", action_type="invoice.approve",
|
|
135
|
-
action_params={"amount": 100}, autonomy_level=2
|
|
135
|
+
action_params={"amount": 100}, autonomy_level=2,
|
|
136
|
+
trust_context={"total_actions": 10, "success_rate": 0.95}))
|
|
136
137
|
assert r.decision == "ALLOW"
|
|
137
138
|
|
|
138
139
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|