agentledger 0.3.1 → 0.4.0
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 +71 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# agentledger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The missing observability layer for AI agents. Track every action, set budgets, get alerts, and kill misbehaving agents — with one line of code.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/agentledger)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
|
|
@@ -10,17 +11,17 @@ Your agents send emails, create tickets, charge credit cards, and call APIs. Age
|
|
|
10
11
|
npm install agentledger
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
## Quick Start
|
|
14
|
+
## Quick Start (60 seconds)
|
|
14
15
|
|
|
15
16
|
```typescript
|
|
16
|
-
import
|
|
17
|
+
import AgentLedger from 'agentledger';
|
|
17
18
|
|
|
18
19
|
const ledger = new AgentLedger({
|
|
19
|
-
apiKey: process.env.AGENTLEDGER_KEY
|
|
20
|
+
apiKey: process.env.AGENTLEDGER_KEY!, // Get from agentledger.co
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
// Wrap any async
|
|
23
|
-
const result = await ledger.track({
|
|
23
|
+
// Wrap any async action — it gets logged, timed, and budget-checked automatically
|
|
24
|
+
const { result } = await ledger.track({
|
|
24
25
|
agent: 'support-bot',
|
|
25
26
|
service: 'slack',
|
|
26
27
|
action: 'send_message',
|
|
@@ -29,16 +30,16 @@ const result = await ledger.track({
|
|
|
29
30
|
});
|
|
30
31
|
```
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
That's it. Open [agentledger.co/dashboard](https://agentledger.co/dashboard) and watch your agent in real-time.
|
|
33
34
|
|
|
34
|
-
##
|
|
35
|
+
## What You Get
|
|
35
36
|
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
- **
|
|
37
|
+
- **Live dashboard** — see every action, cost, and error in real-time
|
|
38
|
+
- **Budget controls** — set hourly/daily/weekly/monthly spend limits per agent
|
|
39
|
+
- **Kill switch** — pause or kill any agent instantly from the dashboard or SDK
|
|
40
|
+
- **Alerts** — get notified when agents exceed budgets or behave unexpectedly
|
|
41
|
+
- **Webhooks** — HTTP callbacks for action.logged, budget.exceeded, agent.killed, etc.
|
|
42
|
+
- **Pre-flight checks** — ask "is this agent allowed to act?" before expensive operations
|
|
42
43
|
|
|
43
44
|
## API
|
|
44
45
|
|
|
@@ -48,37 +49,39 @@ Open your dashboard at [agentledger.co](https://agentledger.co) and watch your a
|
|
|
48
49
|
const ledger = new AgentLedger({
|
|
49
50
|
apiKey: 'al_...', // Required. Get from agentledger.co
|
|
50
51
|
baseUrl: 'https://...', // Optional. Default: https://agentledger.co
|
|
51
|
-
failOpen: true, // Optional. If true,
|
|
52
|
+
failOpen: true, // Optional. If true (default), actions proceed when AgentLedger is unreachable
|
|
52
53
|
timeout: 5000, // Optional. API timeout in ms
|
|
53
|
-
onError: (err) => {}, // Optional.
|
|
54
|
+
onError: (err) => {}, // Optional. Error callback
|
|
54
55
|
});
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
### `ledger.track(options, fn)`
|
|
58
|
+
### `ledger.track(options, fn)` — Track an action
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
Wraps an async function with logging, timing, and budget checks.
|
|
60
61
|
|
|
61
62
|
```typescript
|
|
62
|
-
const { result, allowed, durationMs } = await ledger.track({
|
|
63
|
+
const { result, allowed, durationMs, actionId } = await ledger.track({
|
|
63
64
|
agent: 'my-bot',
|
|
64
|
-
service: '
|
|
65
|
-
action: '
|
|
66
|
-
costCents:
|
|
67
|
-
metadata: {
|
|
65
|
+
service: 'openai',
|
|
66
|
+
action: 'completion',
|
|
67
|
+
costCents: 5, // Optional estimated cost
|
|
68
|
+
metadata: { model: 'gpt-4' }, // Optional metadata
|
|
68
69
|
}, async () => {
|
|
69
|
-
return await
|
|
70
|
+
return await openai.chat.completions.create({ ... });
|
|
70
71
|
});
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
Throws if the agent is paused/killed or budget is exceeded.
|
|
75
|
+
|
|
76
|
+
### `ledger.check(options)` — Pre-flight check
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
Check if an action is allowed without executing it.
|
|
76
79
|
|
|
77
80
|
```typescript
|
|
78
|
-
const { allowed, blockReason } = await ledger.check({
|
|
81
|
+
const { allowed, blockReason, remainingBudget } = await ledger.check({
|
|
79
82
|
agent: 'my-bot',
|
|
80
|
-
service: '
|
|
81
|
-
action: '
|
|
83
|
+
service: 'stripe',
|
|
84
|
+
action: 'charge',
|
|
82
85
|
});
|
|
83
86
|
|
|
84
87
|
if (!allowed) {
|
|
@@ -86,28 +89,27 @@ if (!allowed) {
|
|
|
86
89
|
}
|
|
87
90
|
```
|
|
88
91
|
|
|
89
|
-
### `ledger.log(options)`
|
|
92
|
+
### `ledger.log(options)` — Manual logging
|
|
90
93
|
|
|
91
|
-
|
|
94
|
+
Log an action without wrapping a function.
|
|
92
95
|
|
|
93
96
|
```typescript
|
|
94
97
|
await ledger.log({
|
|
95
98
|
agent: 'my-bot',
|
|
96
|
-
service: '
|
|
97
|
-
action: '
|
|
99
|
+
service: 'email',
|
|
100
|
+
action: 'send',
|
|
101
|
+
status: 'success',
|
|
102
|
+
durationMs: 230,
|
|
98
103
|
costCents: 1,
|
|
99
|
-
durationMs: 340,
|
|
100
104
|
});
|
|
101
105
|
```
|
|
102
106
|
|
|
103
|
-
###
|
|
104
|
-
|
|
105
|
-
Control agents programmatically.
|
|
107
|
+
### Agent Controls
|
|
106
108
|
|
|
107
109
|
```typescript
|
|
108
|
-
await ledger.pauseAgent('
|
|
109
|
-
await ledger.resumeAgent('
|
|
110
|
-
await ledger.killAgent('
|
|
110
|
+
await ledger.pauseAgent('my-bot'); // Pause — blocks all future actions
|
|
111
|
+
await ledger.resumeAgent('my-bot'); // Resume a paused agent
|
|
112
|
+
await ledger.killAgent('my-bot'); // Kill — permanently blocks (can be resumed from dashboard)
|
|
111
113
|
```
|
|
112
114
|
|
|
113
115
|
## Framework Integrations
|
|
@@ -115,61 +117,62 @@ await ledger.killAgent('runaway-bot'); // Permanently stopped
|
|
|
115
117
|
### LangChain
|
|
116
118
|
|
|
117
119
|
```typescript
|
|
118
|
-
import {
|
|
119
|
-
import { AgentLedgerCallbackHandler } from 'agentledger/integrations/langchain';
|
|
120
|
+
import { AgentLedgerCallback } from 'agentledger/integrations/langchain';
|
|
120
121
|
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const callback = new AgentLedgerCallback({
|
|
123
|
+
apiKey: process.env.AGENTLEDGER_KEY!,
|
|
124
|
+
agent: 'langchain-bot',
|
|
124
125
|
});
|
|
125
126
|
|
|
126
|
-
const
|
|
127
|
+
const chain = new LLMChain({ llm, prompt, callbacks: [callback] });
|
|
127
128
|
```
|
|
128
129
|
|
|
129
130
|
### OpenAI
|
|
130
131
|
|
|
131
132
|
```typescript
|
|
132
|
-
import {
|
|
133
|
+
import { wrapOpenAI } from 'agentledger/integrations/openai';
|
|
134
|
+
|
|
135
|
+
const openai = wrapOpenAI(new OpenAI(), {
|
|
136
|
+
apiKey: process.env.AGENTLEDGER_KEY!,
|
|
137
|
+
agent: 'openai-bot',
|
|
138
|
+
});
|
|
133
139
|
|
|
134
|
-
|
|
140
|
+
// All calls are automatically tracked
|
|
141
|
+
await openai.chat.completions.create({ model: 'gpt-4', messages: [...] });
|
|
135
142
|
```
|
|
136
143
|
|
|
137
|
-
###
|
|
144
|
+
### Express Middleware
|
|
138
145
|
|
|
139
146
|
```typescript
|
|
140
|
-
import {
|
|
147
|
+
import { agentLedgerMiddleware } from 'agentledger/integrations/express';
|
|
141
148
|
|
|
142
|
-
|
|
149
|
+
app.use('/api/agent', agentLedgerMiddleware({
|
|
150
|
+
apiKey: process.env.AGENTLEDGER_KEY!,
|
|
151
|
+
agent: 'api-agent',
|
|
152
|
+
}));
|
|
143
153
|
```
|
|
144
154
|
|
|
145
|
-
###
|
|
155
|
+
### MCP (Model Context Protocol)
|
|
146
156
|
|
|
147
157
|
```typescript
|
|
148
|
-
import {
|
|
158
|
+
import { wrapMCPServer } from 'agentledger/integrations/mcp';
|
|
149
159
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
const server = wrapMCPServer(mcpServer, {
|
|
161
|
+
apiKey: process.env.AGENTLEDGER_KEY!,
|
|
162
|
+
agent: 'mcp-agent',
|
|
163
|
+
});
|
|
153
164
|
```
|
|
154
165
|
|
|
155
166
|
## Self-Hosting
|
|
156
167
|
|
|
157
|
-
AgentLedger is open source. You can self-host the dashboard:
|
|
158
|
-
|
|
159
168
|
```bash
|
|
160
169
|
git clone https://github.com/miken1988/agentledger.git
|
|
161
170
|
cd agentledger
|
|
171
|
+
cp .env.example .env.local # Add your Supabase credentials
|
|
162
172
|
npm install && npm run dev
|
|
163
173
|
```
|
|
164
174
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
const ledger = new AgentLedger({
|
|
169
|
-
apiKey: 'al_...',
|
|
170
|
-
baseUrl: 'https://your-instance.com',
|
|
171
|
-
});
|
|
172
|
-
```
|
|
175
|
+
See [docs/SUPABASE_AUTH_SETUP.md](docs/SUPABASE_AUTH_SETUP.md) for full setup guide.
|
|
173
176
|
|
|
174
177
|
## License
|
|
175
178
|
|
package/package.json
CHANGED