authority-layer 0.1.3 → 0.1.5
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.
- package/README.md +155 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# AuthorityLayer
|
|
2
|
+
|
|
3
|
+
[](https://github.com/032383justin/authority-layer/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/authority-layer)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
|
|
8
|
+
Hard execution and budget limits for autonomous agents — enforced locally.
|
|
9
|
+
|
|
10
|
+
✔ No telemetry
|
|
11
|
+
✔ Works fully offline
|
|
12
|
+
✔ Fail-closed by default
|
|
13
|
+
✔ Zero runtime dependencies
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Why AuthorityLayer Exists
|
|
18
|
+
|
|
19
|
+
Autonomous AI agents can fail in expensive, hard-to-detect ways:
|
|
20
|
+
|
|
21
|
+
- **Runaway token spend** — a looping agent burns thousands of dollars before anyone notices
|
|
22
|
+
- **Infinite tool loops** — agents retry the same failing call indefinitely
|
|
23
|
+
- **Retry storms** — cascading failures hammer external APIs with no ceiling
|
|
24
|
+
- **Cascading tool call explosions** — one agent spawns sub-calls that spawn more
|
|
25
|
+
|
|
26
|
+
Most tooling detects these problems after they happen — in dashboards, alerts, or post-run analytics.
|
|
27
|
+
|
|
28
|
+
AuthorityLayer prevents them inside the runtime, before cost or damage accumulates.
|
|
29
|
+
|
|
30
|
+
It helps developers:
|
|
31
|
+
|
|
32
|
+
- prevent runaway LLM costs
|
|
33
|
+
- stop infinite agent loops
|
|
34
|
+
- limit AI agent tool calls per run and per minute
|
|
35
|
+
- enforce runtime safety for autonomous agents
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Live Enforcement Demo (10-second example)
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install authority-layer
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Verify the install:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx authority-layer doctor
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
AuthorityLayer Doctor authority-layer@0.1.2
|
|
59
|
+
|
|
60
|
+
✔ Node.js version >= 18 pass
|
|
61
|
+
✔ crypto module (sha256) pass
|
|
62
|
+
✔ AUTHORITY_LAYER_DISABLE not set pass
|
|
63
|
+
✔ core module loads offline pass
|
|
64
|
+
✔ AuthorityLayer instantiates pass
|
|
65
|
+
|
|
66
|
+
All checks passed. AuthorityLayer is ready.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## CLI Tools
|
|
70
|
+
|
|
71
|
+
| Command | What it does |
|
|
72
|
+
|---------|-------------|
|
|
73
|
+
| `npx authority-layer doctor` | Verify your installation passes all environment checks |
|
|
74
|
+
| `npx authority-layer simulate` | Run a live enforcement simulation — see a halt in action without writing any code |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Minimal Integration
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { AuthorityLayer, EnforcementHalt } from "authority-layer";
|
|
82
|
+
|
|
83
|
+
const authority = new AuthorityLayer({
|
|
84
|
+
budget: { dailyUSD: 50 }, // Hard USD spend cap
|
|
85
|
+
loopGuard: { maxToolCallsPerRun: 25 }, // Max tool calls per run
|
|
86
|
+
toolThrottle: { maxCallsPerMinute: 60 }, // Sliding-window rate cap
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await authority.wrap(async () => {
|
|
91
|
+
const result = await authority.tool("llm.chat", () =>
|
|
92
|
+
callYourModel(prompt)
|
|
93
|
+
);
|
|
94
|
+
authority.recordSpend(calculateCostUSD(result));
|
|
95
|
+
});
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (err instanceof EnforcementHalt) {
|
|
98
|
+
console.error(err.enforcement);
|
|
99
|
+
// { status: "halted", reason: "budget_exceeded", limit: 50, spent: 52.14, event_id: "evt_..." }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Enforcement Primitives
|
|
107
|
+
|
|
108
|
+
AuthorityLayer V1 provides three composable enforcement primitives. Each is opt-in — omit a config key to disable it.
|
|
109
|
+
|
|
110
|
+
These primitives enforce boundaries directly inside the execution loop — not in dashboards or external monitoring.
|
|
111
|
+
|
|
112
|
+
| Primitive | Config key | What it enforces |
|
|
113
|
+
|-----------|------------|------------------|
|
|
114
|
+
| **Budget cap** | `budget.dailyUSD` | Cumulative USD spend across the process lifetime. Halts when spend exceeds the cap. → [docs](./docs/enforcement.md#1-budget-cap) |
|
|
115
|
+
| **Loop guard** | `loopGuard.maxToolCallsPerRun` | Total tool calls per `wrap()` invocation. Counter resets each run. → [docs](./docs/enforcement.md#2-loop-guard) |
|
|
116
|
+
| **Tool throttle** | `toolThrottle.maxCallsPerMinute` | Rate of tool calls using a sliding 60-second window — no fixed buckets. → [docs](./docs/enforcement.md#3-tool-throttle) |
|
|
117
|
+
|
|
118
|
+
When a primitive breaches, AuthorityLayer throws a typed `EnforcementHalt` error with a structured `.enforcement` object. Execution never crashes silently.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## How AuthorityLayer Is Different
|
|
123
|
+
|
|
124
|
+
Most AI guardrail tools focus on moderation or observability. AuthorityLayer focuses on **runtime enforcement**.
|
|
125
|
+
|
|
126
|
+
| Tool type | What it does |
|
|
127
|
+
|-----------|-------------|
|
|
128
|
+
| Prompt guardrails | Filter or rewrite prompts and outputs |
|
|
129
|
+
| Observability platforms | Analyze agent behavior after execution |
|
|
130
|
+
| Cost analytics | Track and report token usage |
|
|
131
|
+
| **AuthorityLayer** | Enforces hard limits **during** execution — halts immediately when a boundary is crossed |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Documentation
|
|
136
|
+
|
|
137
|
+
| Topic | File |
|
|
138
|
+
|------|------|
|
|
139
|
+
| Concepts & philosophy | [docs/concepts.md](./docs/concepts.md) |
|
|
140
|
+
| Enforcement primitives | [docs/enforcement.md](./docs/enforcement.md) |
|
|
141
|
+
| API reference | [docs/api.md](./docs/api.md) |
|
|
142
|
+
| Integrity chain | [docs/integrity.md](./docs/integrity.md) |
|
|
143
|
+
| Example run | `npm run example` |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
AuthorityLayer is designed as a minimal enforcement primitive — not a platform, dashboard, or governance system.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT © 2025 AuthorityLayer Contributors
|
|
154
|
+
|
|
155
|
+
[GitHub](https://github.com/032383justin/authority-layer) · [npm](https://www.npmjs.com/package/authority-layer) · [Issues](https://github.com/032383justin/authority-layer/issues)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "authority-layer",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Runtime guardrails for AI agents that enforce token budgets, loop limits, and tool rate limits locally.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|