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.
Files changed (2) hide show
  1. package/README.md +71 -68
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # AgentLedger
1
+ # agentledger
2
2
 
3
- **See everything your AI agents do.** Track actions, monitor costs, and kill agents when things go wrong.
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
- Your agents send emails, create tickets, charge credit cards, and call APIs. AgentLedger logs every action, tracks every cost, and lets you kill agents instantly when things go sideways.
5
+ [![npm](https://img.shields.io/npm/v/agentledger)](https://www.npmjs.com/package/agentledger)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](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 { AgentLedger } from 'agentledger';
17
+ import AgentLedger from 'agentledger';
17
18
 
18
19
  const ledger = new AgentLedger({
19
- apiKey: process.env.AGENTLEDGER_KEY, // Get this from agentledger.co
20
+ apiKey: process.env.AGENTLEDGER_KEY!, // Get from agentledger.co
20
21
  });
21
22
 
22
- // Wrap any async function — it's logged, timed, and budget-checked
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
- Open your dashboard at [agentledger.co](https://agentledger.co) and watch your agents in real-time.
33
+ That's it. Open [agentledger.co/dashboard](https://agentledger.co/dashboard) and watch your agent in real-time.
33
34
 
34
- ## Features
35
+ ## What You Get
35
36
 
36
- - **Zero dependencies** — just this package, nothing else
37
- - **Fail-open by default** — if AgentLedger is down, your agents keep running
38
- - **Pre-flight checks** — block actions before they happen if agent is over budget
39
- - **Kill switches** — pause or kill any agent instantly
40
- - **Cost tracking** — know exactly what each agent costs
41
- - **5ms overhead** — async logging, doesn't slow your agents down
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, agents run even if AgentLedger is unreachable
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. Called on communication errors
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
- Wrap an async function. Runs a pre-flight budget check, executes the function, logs the result.
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: 'stripe',
65
- action: 'charge',
66
- costCents: 50,
67
- metadata: { customerId: '123' },
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 stripe.charges.create({ amount: 5000 });
70
+ return await openai.chat.completions.create({ ... });
70
71
  });
71
72
  ```
72
73
 
73
- ### `ledger.check(options)`
74
+ Throws if the agent is paused/killed or budget is exceeded.
75
+
76
+ ### `ledger.check(options)` — Pre-flight check
74
77
 
75
- Pre-flight check without executing. Use before expensive operations.
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: 'openai',
81
- action: 'completion',
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
- Manual logging without wrapping a function.
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: 'sendgrid',
97
- action: 'send_email',
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
- ### `ledger.pauseAgent(name)` / `resumeAgent(name)` / `killAgent(name)`
104
-
105
- Control agents programmatically.
107
+ ### Agent Controls
106
108
 
107
109
  ```typescript
108
- await ledger.pauseAgent('runaway-bot'); // All future actions blocked
109
- await ledger.resumeAgent('runaway-bot'); // Back in action
110
- await ledger.killAgent('runaway-bot'); // Permanently stopped
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 { AgentLedger } from 'agentledger';
119
- import { AgentLedgerCallbackHandler } from 'agentledger/integrations/langchain';
120
+ import { AgentLedgerCallback } from 'agentledger/integrations/langchain';
120
121
 
121
- const handler = new AgentLedgerCallbackHandler(ledger, {
122
- agent: 'research-bot',
123
- serviceMap: { 'tavily_search': { service: 'tavily', action: 'search' } },
122
+ const callback = new AgentLedgerCallback({
123
+ apiKey: process.env.AGENTLEDGER_KEY!,
124
+ agent: 'langchain-bot',
124
125
  });
125
126
 
126
- const agent = createReactAgent({ llm, tools, callbacks: [handler] });
127
+ const chain = new LLMChain({ llm, prompt, callbacks: [callback] });
127
128
  ```
128
129
 
129
130
  ### OpenAI
130
131
 
131
132
  ```typescript
132
- import { createToolExecutor } from 'agentledger/integrations/openai';
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
- const execute = createToolExecutor(ledger, 'my-agent', tools, serviceMap);
140
+ // All calls are automatically tracked
141
+ await openai.chat.completions.create({ model: 'gpt-4', messages: [...] });
135
142
  ```
136
143
 
137
- ### MCP Servers
144
+ ### Express Middleware
138
145
 
139
146
  ```typescript
140
- import { wrapMCPServer } from 'agentledger/integrations/mcp';
147
+ import { agentLedgerMiddleware } from 'agentledger/integrations/express';
141
148
 
142
- wrapMCPServer(ledger, server, { agent: 'my-mcp-server' });
149
+ app.use('/api/agent', agentLedgerMiddleware({
150
+ apiKey: process.env.AGENTLEDGER_KEY!,
151
+ agent: 'api-agent',
152
+ }));
143
153
  ```
144
154
 
145
- ### Express
155
+ ### MCP (Model Context Protocol)
146
156
 
147
157
  ```typescript
148
- import { agentLedgerMiddleware } from 'agentledger/integrations/express';
158
+ import { wrapMCPServer } from 'agentledger/integrations/mcp';
149
159
 
150
- app.post('/api/action', agentLedgerMiddleware(ledger, {
151
- agent: 'api-bot', service: 'internal', action: 'process',
152
- }), handler);
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
- Point your SDK to your own instance:
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentledger",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Track, monitor, and control AI agent actions. The missing observability layer for AI agents. Zero dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",