agent-inspect 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentInspect contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,339 @@
1
+ # agent-inspect
2
+
3
+ AgentInspect is a local-first execution-tree debugger for TypeScript AI agents.
4
+
5
+ ## Why
6
+
7
+ AI agents are multi-step. Console logs are flat.
8
+
9
+ AgentInspect turns runs into structured execution trees with JSONL traces and CLI inspection.
10
+
11
+ AgentInspect is designed for inner-loop debugging, not as a replacement for production observability platforms.
12
+
13
+ ## What you get
14
+
15
+ - Execution-tree tracing for TypeScript agent workflows
16
+ - Nested `step()` support with parent-child relationships
17
+ - `step.llm()` and `step.tool()` helpers for agent-aware traces
18
+ - Local JSONL trace files
19
+ - Real-time terminal output while the agent runs
20
+ - CLI commands to inspect previous runs
21
+ - No accounts, API keys, dashboards, or cloud ingestion
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install agent-inspect
27
+ ```
28
+
29
+ ## See your first trace
30
+
31
+ Run a traced workflow, then inspect it with the CLI.
32
+
33
+ ```ts
34
+ import { inspectRun, step } from "agent-inspect";
35
+
36
+ await inspectRun("hello-agent", async () => {
37
+ const plan = await step("plan", async () => "search hotels");
38
+ return step("finalize", async () => ({ plan, status: "done" }));
39
+ });
40
+ ```
41
+
42
+ ```bash
43
+ npx agent-inspect list
44
+ npx agent-inspect view run_abc123
45
+ ```
46
+
47
+ Replace `run_abc123` with the run id printed by `agent-inspect list`.
48
+
49
+ ## Minimal API
50
+
51
+ ```ts
52
+ import { inspectRun, step } from "agent-inspect";
53
+
54
+ await inspectRun("my-agent-run", async () => {
55
+ const plan = await step("plan", async () => ({ task: "research" }));
56
+ return step("act", async () => plan);
57
+ });
58
+ ```
59
+
60
+ ## LLM and tool helpers
61
+
62
+ ```ts
63
+ await step.llm("mock-gpt", async () => {
64
+ return planner.run();
65
+ });
66
+
67
+ await step.tool("searchHotels", async () => {
68
+ return searchHotels();
69
+ });
70
+ ```
71
+
72
+ Helpers only label steps in the trace.
73
+
74
+ They do not import or call vendor SDKs.
75
+
76
+ ## observe()
77
+
78
+ `observe()` wraps top-level `run`, `execute`, and `invoke`.
79
+
80
+ For internal detail, add manual `step()` calls inside the agent.
81
+
82
+ ```ts
83
+ import { observe } from "agent-inspect";
84
+
85
+ class MyAgent {
86
+ async run(input: string) {
87
+ return `ok: ${input}`;
88
+ }
89
+ }
90
+
91
+ const agent = observe(new MyAgent());
92
+ await agent.run("hello");
93
+ ```
94
+
95
+ See [examples/05-observe-wrapper](examples/05-observe-wrapper) for a top-level observed run with internal `step()`, `step.tool()`, and `step.llm()` calls.
96
+
97
+ ## Usage examples
98
+
99
+ ### Example 1: Basic workflow
100
+
101
+ ```ts
102
+ import { inspectRun, step } from "agent-inspect";
103
+
104
+ const result = await inspectRun("hotel-booking", async () => {
105
+ const hotels = await step("search-hotels", async () => {
106
+ return ["Tokyo Grand Hotel", "Tokyo Central Inn"];
107
+ });
108
+
109
+ const availability = await step("check-availability", async () => {
110
+ return { hotel: hotels[0], rooms: 2 };
111
+ });
112
+
113
+ return step("finalize-booking", async () => {
114
+ return `confirmed:${availability.hotel}`;
115
+ });
116
+ });
117
+
118
+ console.log(result);
119
+ ```
120
+
121
+ Expected tree:
122
+
123
+ ```text
124
+ hotel-booking
125
+ ✔ search-hotels
126
+ ✔ check-availability
127
+ ✔ finalize-booking
128
+ ```
129
+
130
+ ### Example 2: Nested LLM and tool steps
131
+
132
+ ```ts
133
+ import { inspectRun, step } from "agent-inspect";
134
+
135
+ await inspectRun("trip-planner", async () => {
136
+ const plan = await step("plan-trip", async () => {
137
+ const draft = await step.llm("mock-gpt", async () => {
138
+ return "Plan: museum, dinner, evening walk.";
139
+ });
140
+
141
+ return step("parse-plan", async () => {
142
+ return draft.replace("Plan: ", "").split(", ");
143
+ });
144
+ });
145
+
146
+ const hotels = await step.tool("searchHotels", async () => {
147
+ return [{ id: "h1", city: "Kyoto" }];
148
+ });
149
+
150
+ return step("finalize", async () => {
151
+ return { plan, hotel: hotels[0] };
152
+ });
153
+ });
154
+ ```
155
+
156
+ Expected tree:
157
+
158
+ ```text
159
+ trip-planner
160
+ ✔ plan-trip
161
+ ✔ llm:mock-gpt
162
+ ✔ parse-plan
163
+ ✔ tool:searchHotels
164
+ ✔ finalize
165
+ ```
166
+
167
+ ### Example 3: Error handling
168
+
169
+ ```ts
170
+ import { inspectRun, step } from "agent-inspect";
171
+
172
+ try {
173
+ await inspectRun("pricing-flow", async () => {
174
+ await step("load-catalog", async () => ["sku-a", "sku-b"]);
175
+
176
+ await step("fetch-dynamic-pricing", async () => {
177
+ throw new Error("Pricing API timeout");
178
+ });
179
+
180
+ await step("apply-discount", async () => {
181
+ return "this step will not run";
182
+ });
183
+ });
184
+ } catch (error) {
185
+ console.error("Original error still propagated:", error);
186
+ }
187
+ ```
188
+
189
+ AgentInspect records the failed step, writes it to the trace file, and still rethrows the original error.
190
+
191
+ ### Example 4: `observe()` wrapper
192
+
193
+ ```ts
194
+ import { observe, step } from "agent-inspect";
195
+
196
+ class CustomerSupportAgent {
197
+ async run(question: string): Promise<string> {
198
+ const category = await step("triage-question", async () => {
199
+ return question.toLowerCase().includes("password")
200
+ ? "account-access"
201
+ : "general";
202
+ });
203
+
204
+ const articles = await step.tool("retrieveArticles", async () => {
205
+ return ["Reset your password from the login page."];
206
+ });
207
+
208
+ return step.llm("mock-support-model", async () => {
209
+ return `Category: ${category}. ${articles[0]}`;
210
+ });
211
+ }
212
+ }
213
+
214
+ const agent = observe(new CustomerSupportAgent());
215
+ await agent.run("How do I reset my password?");
216
+ ```
217
+
218
+ `observe()` wraps top-level `run`, `execute`, and `invoke` methods. For internal detail, add manual `step()` calls inside the agent.
219
+
220
+ ## CLI
221
+
222
+ List recent runs:
223
+
224
+ ```bash
225
+ npx agent-inspect list
226
+ ```
227
+
228
+ View a run:
229
+
230
+ ```bash
231
+ npx agent-inspect view run_abc123
232
+ ```
233
+
234
+ Use a custom trace directory:
235
+
236
+ ```bash
237
+ npx agent-inspect list --dir ./traces
238
+ npx agent-inspect view run_abc123 --dir ./traces
239
+ ```
240
+
241
+ By default, traces are stored under `~/.agent-inspect/runs`.
242
+
243
+ For local repo development after `pnpm build`:
244
+
245
+ ```bash
246
+ node packages/cli/dist/index.cjs list
247
+ node packages/cli/dist/index.cjs view run_abc123
248
+ ```
249
+
250
+ ## Local traces
251
+
252
+ AgentInspect writes one JSONL file per run.
253
+
254
+ Default location:
255
+
256
+ ```text
257
+ ~/.agent-inspect/runs
258
+ ```
259
+
260
+ Example event shape:
261
+
262
+ ```json
263
+ {"schemaVersion":"0.1","event":"step_started","name":"search-hotels","type":"logic"}
264
+ ```
265
+
266
+ You can inspect traces with standard tools:
267
+
268
+ ```bash
269
+ cat ~/.agent-inspect/runs/run_abc123.jsonl
270
+ cat ~/.agent-inspect/runs/run_abc123.jsonl | jq
271
+ ```
272
+
273
+ ## Runnable examples
274
+
275
+ The repo includes five runnable MVP examples:
276
+
277
+ - `examples/01-basic` — `inspectRun()` + `step()`
278
+ - `examples/02-nested-steps` — nested execution tree hierarchy
279
+ - `examples/03-parallel-steps` — `Promise.all` sibling isolation
280
+ - `examples/04-error-handling` — failed steps and error traces
281
+ - `examples/05-observe-wrapper` — `observe()` wrapper with internal steps
282
+
283
+ Run one locally:
284
+
285
+ ```bash
286
+ pnpm build
287
+ cd examples/01-basic
288
+ pnpm install
289
+ pnpm start
290
+ ```
291
+
292
+ Then inspect traces:
293
+
294
+ ```bash
295
+ node ../../packages/cli/dist/index.cjs list
296
+ node ../../packages/cli/dist/index.cjs view run_abc123
297
+ ```
298
+
299
+ Do not commit `node_modules`. Example dependencies are installed locally when you run `pnpm install`.
300
+
301
+ Supporting material:
302
+
303
+ - [examples/README.md](examples/README.md)
304
+
305
+ ## MVP scope
306
+
307
+ Included:
308
+
309
+ - `inspectRun()`
310
+ - `step()`
311
+ - `step.llm()`
312
+ - `step.tool()`
313
+ - `observe()`
314
+ - JSONL traces
315
+ - CLI `list` and `view`
316
+
317
+ Not included:
318
+
319
+ - Framework adapters
320
+ - Token or cost tracking
321
+ - Replay
322
+ - SQLite
323
+ - Dashboards
324
+ - OpenTelemetry
325
+
326
+ ## Development
327
+
328
+ ```bash
329
+ pnpm install
330
+ pnpm build
331
+ pnpm test
332
+ pnpm test:all
333
+ ```
334
+
335
+ ## More context
336
+
337
+ - [Examples roadmap](docs/EXAMPLES_ROADMAP.md)
338
+ - [Console log case study](docs/CASE_STUDY_CONSOLE_LOG_TO_AGENT_INSPECT.md)
339
+ - [Product requirements](docs/AGENT_INSPECT_PRD_FINAL.md)
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "agent-inspect",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "description": "Local-first execution-tree debugger for TypeScript AI agents",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/rajudandigam/agent-inspect.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/rajudandigam/agent-inspect/issues"
13
+ },
14
+ "homepage": "https://github.com/rajudandigam/agent-inspect#readme",
15
+ "packageManager": "pnpm@9.15.0",
16
+ "main": "./packages/core/dist/index.cjs",
17
+ "module": "./packages/core/dist/index.mjs",
18
+ "types": "./packages/core/dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./packages/core/dist/index.d.ts",
22
+ "import": "./packages/core/dist/index.mjs",
23
+ "require": "./packages/core/dist/index.cjs"
24
+ }
25
+ },
26
+ "bin": {
27
+ "agent-inspect": "packages/cli/dist/index.cjs"
28
+ },
29
+ "files": [
30
+ "packages/core/dist",
31
+ "packages/cli/dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "keywords": [
37
+ "ai",
38
+ "agents",
39
+ "debugging",
40
+ "typescript",
41
+ "llm",
42
+ "devtools",
43
+ "jsonl",
44
+ "cli"
45
+ ],
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "dependencies": {
50
+ "chalk": "^5.3.0",
51
+ "nanoid": "^5.0.9",
52
+ "commander": "^12.1.0"
53
+ },
54
+ "scripts": {
55
+ "clean": "pnpm -r exec -- rm -rf dist",
56
+ "build": "pnpm exec tsup --config tsup.core.config.ts && pnpm exec tsup --config tsup.cli.config.ts",
57
+ "typecheck": "tsc --noEmit",
58
+ "test": "vitest run",
59
+ "test:watch": "vitest",
60
+ "test:coverage": "vitest run --coverage",
61
+ "size": "size-limit --config size-limit.config.mjs",
62
+ "test:all": "pnpm run typecheck && pnpm run test && pnpm run build && pnpm run size",
63
+ "prepublish:checks": "pnpm run typecheck && pnpm run test && pnpm run build && pnpm run size && pnpm run pack:smoke",
64
+ "prepublishOnly": "pnpm run prepublish:checks",
65
+ "prepack": "pnpm run clean && pnpm run build",
66
+ "pack:dry-run": "pnpm run build && npm pack --dry-run",
67
+ "pack:smoke": "pnpm run build && node scripts/package-smoke.mjs",
68
+ "examples:check": "pnpm install && pnpm --filter agent-inspect-example-01-basic run start",
69
+ "changeset": "changeset",
70
+ "release": "changeset publish"
71
+ },
72
+ "devDependencies": {
73
+ "@changesets/cli": "^2.27.10",
74
+ "@size-limit/preset-small-lib": "^11.1.6",
75
+ "@types/node": "^22.10.2",
76
+ "@vitest/coverage-v8": "^2.1.8",
77
+ "size-limit": "^11.1.6",
78
+ "tsup": "^8.3.5",
79
+ "typescript": "^5.7.2",
80
+ "vitest": "^2.1.8"
81
+ }
82
+ }