@lov3kaizen/agentsea-debugger 0.5.1

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) 2024 lovekaizen
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,364 @@
1
+ # @lov3kaizen/agentsea-debugger
2
+
3
+ AI Agent debugger with step-through execution, decision tree visualization, checkpoint replay, and what-if scenario testing.
4
+
5
+ ## Features
6
+
7
+ - **Step-through Debugging**: Pause execution at breakpoints and step through agent actions
8
+ - **Execution Recording**: Record complete agent sessions for later analysis
9
+ - **Checkpoint System**: Create and restore checkpoints at any point in execution
10
+ - **Replay Engine**: Replay recordings with modifications to explore alternatives
11
+ - **Failure Analysis**: Automatic root cause analysis with recommendations
12
+ - **What-If Scenarios**: Test alternative paths without re-running the agent
13
+ - **Decision Tree Visualization**: Visualize agent decision points as trees
14
+ - **Flow Graph Visualization**: See execution flow as a graph
15
+ - **Storage Adapters**: File-based and in-memory storage options
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pnpm add @lov3kaizen/agentsea-debugger
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import {
27
+ Debugger,
28
+ BreakpointHelpers,
29
+ } from '@lov3kaizen/agentsea-debugger';
30
+
31
+ // Create debugger
32
+ const debugger = new Debugger();
33
+
34
+ // Attach to agent
35
+ debugger.attach(agent);
36
+
37
+ // Set breakpoints
38
+ debugger.setBreakpoint(BreakpointHelpers.onTool('search'));
39
+ debugger.setBreakpoint(BreakpointHelpers.onError());
40
+
41
+ // Start session
42
+ const session = await debugger.startSession();
43
+
44
+ // Execute agent...
45
+ await agent.execute('Hello');
46
+
47
+ // Get recording
48
+ const recording = await debugger.endSession();
49
+ ```
50
+
51
+ ## Core Concepts
52
+
53
+ ### Debugger
54
+
55
+ The main entry point for debugging agents:
56
+
57
+ ```typescript
58
+ import { Debugger } from '@lov3kaizen/agentsea-debugger';
59
+
60
+ const debugger = new Debugger({
61
+ maxSteps: 1000,
62
+ recording: {
63
+ enabled: true,
64
+ includePrompts: true,
65
+ includeResponses: true,
66
+ },
67
+ });
68
+
69
+ // Attach to agent
70
+ debugger.attach({
71
+ id: 'my-agent',
72
+ name: 'My Agent',
73
+ model: 'gpt-4',
74
+ });
75
+
76
+ // Start debugging
77
+ const session = await debugger.startSession();
78
+ ```
79
+
80
+ ### Breakpoints
81
+
82
+ Set breakpoints to pause execution at specific points:
83
+
84
+ ```typescript
85
+ import { BreakpointHelpers } from '@lov3kaizen/agentsea-debugger';
86
+
87
+ // Break on specific tool
88
+ debugger.setBreakpoint(BreakpointHelpers.onTool('search'));
89
+
90
+ // Break on any error
91
+ debugger.setBreakpoint(BreakpointHelpers.onError());
92
+
93
+ // Break on decisions
94
+ debugger.setBreakpoint(BreakpointHelpers.onDecision());
95
+
96
+ // Break on low confidence
97
+ debugger.setBreakpoint(BreakpointHelpers.onLowConfidence(0.5));
98
+
99
+ // Custom breakpoint
100
+ debugger.setBreakpoint(BreakpointHelpers.custom(
101
+ (ctx) => ctx.step.type === 'tool-call' && ctx.step.toolCall?.name === 'delete',
102
+ 'Break on delete operations'
103
+ ));
104
+ ```
105
+
106
+ ### Recording
107
+
108
+ Record agent execution for later analysis:
109
+
110
+ ```typescript
111
+ import { Recorder } from '@lov3kaizen/agentsea-debugger';
112
+
113
+ const recorder = new Recorder({
114
+ includePrompts: true,
115
+ includeResponses: true,
116
+ autoSnapshot: true,
117
+ snapshotInterval: 10,
118
+ });
119
+
120
+ // Start recording
121
+ recorder.start('my-agent', initialState);
122
+
123
+ // Record steps
124
+ recorder.recordStep(step, state);
125
+
126
+ // Create checkpoint
127
+ recorder.createCheckpoint('Before API call');
128
+
129
+ // Stop and get recording
130
+ const recording = recorder.stop();
131
+ ```
132
+
133
+ ### Replay
134
+
135
+ Replay recordings with modifications:
136
+
137
+ ```typescript
138
+ import { ReplayEngine } from '@lov3kaizen/agentsea-debugger';
139
+
140
+ const replay = new ReplayEngine();
141
+
142
+ // Start replay
143
+ const session = await replay.start(recording, {
144
+ speed: 'normal',
145
+ modifications: [
146
+ { stepIndex: 5, type: 'modify', data: { output: 'alternative result' } },
147
+ ],
148
+ });
149
+
150
+ // Listen to events
151
+ replay.on('step:replayed', (step, state) => {
152
+ console.log(`Replayed step ${step.index}`);
153
+ });
154
+
155
+ // Control playback
156
+ replay.pause();
157
+ replay.resume();
158
+ replay.setSpeed('fast');
159
+ ```
160
+
161
+ ### Failure Analysis
162
+
163
+ Automatically analyze failed executions:
164
+
165
+ ```typescript
166
+ import { FailureAnalyzer } from '@lov3kaizen/agentsea-debugger';
167
+
168
+ const analyzer = new FailureAnalyzer();
169
+
170
+ // Analyze a failed recording
171
+ const analysis = analyzer.analyze(recording);
172
+
173
+ console.log('Root Cause:', analysis.rootCause);
174
+ console.log('Severity:', analysis.severity);
175
+ console.log('Recommendations:', analysis.recommendations);
176
+ ```
177
+
178
+ ### What-If Scenarios
179
+
180
+ Explore alternative execution paths:
181
+
182
+ ```typescript
183
+ import { WhatIfEngine } from '@lov3kaizen/agentsea-debugger';
184
+
185
+ const whatIf = new WhatIfEngine();
186
+
187
+ // Create scenario
188
+ const scenario = whatIf.createScenario({
189
+ name: 'What if search succeeded?',
190
+ recordingId: recording.id,
191
+ modifications: [
192
+ {
193
+ stepIndex: 3,
194
+ type: 'modify',
195
+ data: {
196
+ toolCall: {
197
+ id: 'tool_1',
198
+ name: 'search',
199
+ result: 'Success!',
200
+ success: true,
201
+ },
202
+ },
203
+ },
204
+ ],
205
+ });
206
+
207
+ // Run scenario
208
+ const result = await whatIf.runScenario(scenario.id, recording);
209
+
210
+ // Compare with original
211
+ const comparison = whatIf.compare(recording, result);
212
+ ```
213
+
214
+ ### Visualization
215
+
216
+ Generate decision trees and flow graphs:
217
+
218
+ ```typescript
219
+ import {
220
+ DecisionTreeBuilder,
221
+ FlowGraphBuilder,
222
+ } from '@lov3kaizen/agentsea-debugger';
223
+
224
+ // Build decision tree
225
+ const treeBuilder = new DecisionTreeBuilder();
226
+ const tree = treeBuilder.build(recording);
227
+
228
+ // Export as Mermaid
229
+ console.log(treeBuilder.toMermaid());
230
+
231
+ // Build flow graph
232
+ const graphBuilder = new FlowGraphBuilder();
233
+ const graph = graphBuilder.build(recording);
234
+
235
+ // Export as DOT (Graphviz)
236
+ console.log(graphBuilder.toDOT());
237
+ ```
238
+
239
+ ### Storage
240
+
241
+ Store and retrieve recordings:
242
+
243
+ ```typescript
244
+ import { FileStorage, MemoryStorage } from '@lov3kaizen/agentsea-debugger';
245
+
246
+ // File-based storage
247
+ const fileStorage = new FileStorage({
248
+ basePath: './debug-sessions',
249
+ fs: nodeFs, // Node.js fs/promises wrapper
250
+ });
251
+
252
+ // In-memory storage
253
+ const memoryStorage = new MemoryStorage({
254
+ maxRecordings: 100,
255
+ maxSizeBytes: 50 * 1024 * 1024, // 50MB
256
+ });
257
+
258
+ // Save recording
259
+ await storage.save(recording);
260
+
261
+ // Load recording
262
+ const loaded = await storage.load(recording.id);
263
+
264
+ // List recordings
265
+ const recordings = await storage.list();
266
+ ```
267
+
268
+ ## AgentSea Integration
269
+
270
+ Use the high-level `AgentDebugger` for seamless integration:
271
+
272
+ ```typescript
273
+ import { AgentDebugger, MemoryStorage } from '@lov3kaizen/agentsea-debugger';
274
+
275
+ const debugger = new AgentDebugger({
276
+ storage: new MemoryStorage(),
277
+ autoSave: true,
278
+ });
279
+
280
+ // Set breakpoints
281
+ debugger.breakOnTool('search');
282
+ debugger.breakOnError();
283
+
284
+ // Start session
285
+ await debugger.startSession({
286
+ agentId: 'my-agent',
287
+ agentName: 'My Agent',
288
+ model: 'gpt-4',
289
+ messages: [],
290
+ tools: ['search'],
291
+ });
292
+
293
+ // Get middleware for step tracking
294
+ const middleware = debugger.getMiddleware();
295
+
296
+ // Track steps
297
+ middleware.onInput('User question');
298
+ middleware.onToolCall({ name: 'search', arguments: { query: 'test' } });
299
+ middleware.onToolResult({ id: 'tool_1', name: 'search', result: 'Found!', success: true });
300
+ middleware.onResponse('Here is the answer');
301
+
302
+ // End session
303
+ const recording = await debugger.endSession();
304
+
305
+ // Analyze if failed
306
+ if (recording.status === 'failed') {
307
+ const analysis = debugger.analyzeFailure(recording);
308
+ console.log(analysis.recommendations);
309
+ }
310
+ ```
311
+
312
+ ## API Reference
313
+
314
+ ### Core
315
+
316
+ - `Debugger` - Main debugger class
317
+ - `DebugSessionManager` - Session management
318
+ - `BreakpointManager` - Breakpoint management
319
+ - `Inspector` - State inspection
320
+
321
+ ### Recording
322
+
323
+ - `Recorder` - Execution recording
324
+ - `SnapshotManager` - State snapshots
325
+ - `CheckpointManager` - Checkpoint management
326
+ - `Timeline` - Event timeline
327
+
328
+ ### Replay
329
+
330
+ - `ReplayEngine` - Replay execution
331
+ - `ReplayController` - Playback control
332
+ - `StateRestorer` - State restoration
333
+
334
+ ### Visualization
335
+
336
+ - `DecisionTreeBuilder` - Decision tree generation
337
+ - `FlowGraphBuilder` - Flow graph generation
338
+
339
+ ### Analysis
340
+
341
+ - `FailureAnalyzer` - Failure root cause analysis
342
+ - `WhatIfEngine` - What-if scenario testing
343
+
344
+ ### Storage
345
+
346
+ - `FileStorage` - File-based storage
347
+ - `MemoryStorage` - In-memory storage
348
+
349
+ ### Integration
350
+
351
+ - `AgentDebugger` - High-level debugger wrapper
352
+ - `DebugMiddleware` - Middleware for agents
353
+
354
+ ## Examples
355
+
356
+ See the `examples/` directory for complete examples:
357
+
358
+ - `basic-debugging.ts` - Core debugging functionality
359
+ - `replay-and-analysis.ts` - Replay and failure analysis
360
+ - `agentsea-integration.ts` - AgentSea integration
361
+
362
+ ## License
363
+
364
+ MIT
@@ -0,0 +1,138 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { q as TimelineEvent, m as Recording, E as ExecutionStep, p as Snapshot, C as Checkpoint, s as RecorderConfig, t as RecordingStorageAdapter, A as AgentState } from './recording.types-Ck7pbikw.js';
3
+
4
+ interface TimelineEventOptions {
5
+ id?: string;
6
+ type: string;
7
+ timestamp?: number;
8
+ stepIndex: number;
9
+ description: string;
10
+ durationMs?: number;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ interface TimelineMarker {
14
+ id: string;
15
+ name: string;
16
+ timestamp: number;
17
+ stepIndex: number;
18
+ color?: string;
19
+ description?: string;
20
+ }
21
+ interface TimelineSegment {
22
+ id: string;
23
+ startStep: number;
24
+ endStep: number;
25
+ startTime: number;
26
+ endTime: number;
27
+ name: string;
28
+ type: string;
29
+ }
30
+ interface TimelineFilterOptions {
31
+ types?: string[];
32
+ stepRange?: {
33
+ min?: number;
34
+ max?: number;
35
+ };
36
+ timeRange?: {
37
+ after?: number;
38
+ before?: number;
39
+ };
40
+ search?: string;
41
+ }
42
+ interface TimelineStats {
43
+ totalEvents: number;
44
+ eventsByType: Record<string, number>;
45
+ totalDurationMs: number;
46
+ avgEventDurationMs: number;
47
+ firstEventTime?: number;
48
+ lastEventTime?: number;
49
+ }
50
+ declare class Timeline {
51
+ private events;
52
+ private eventOrder;
53
+ private markers;
54
+ private segments;
55
+ addEvent(options: TimelineEventOptions): TimelineEvent;
56
+ getEvent(id: string): TimelineEvent | undefined;
57
+ getEvents(): TimelineEvent[];
58
+ filterEvents(options: TimelineFilterOptions): TimelineEvent[];
59
+ getEventsInRange(startStep: number, endStep: number): TimelineEvent[];
60
+ getEventsByType(type: string): TimelineEvent[];
61
+ getEventAtStep(stepIndex: number): TimelineEvent | undefined;
62
+ addMarker(options: Omit<TimelineMarker, 'id' | 'timestamp'> & {
63
+ timestamp?: number;
64
+ }): TimelineMarker;
65
+ getMarkers(): TimelineMarker[];
66
+ getMarkerAtStep(stepIndex: number): TimelineMarker | undefined;
67
+ removeMarker(id: string): boolean;
68
+ addSegment(options: Omit<TimelineSegment, 'id'>): TimelineSegment;
69
+ getSegments(): TimelineSegment[];
70
+ getSegmentForStep(stepIndex: number): TimelineSegment | undefined;
71
+ removeSegment(id: string): boolean;
72
+ getStats(): TimelineStats;
73
+ getDurationBetween(startStep: number, endStep: number): number;
74
+ format(): string;
75
+ clear(): void;
76
+ get count(): number;
77
+ export(): {
78
+ events: TimelineEvent[];
79
+ markers: TimelineMarker[];
80
+ segments: TimelineSegment[];
81
+ };
82
+ import(data: {
83
+ events?: TimelineEvent[];
84
+ markers?: TimelineMarker[];
85
+ segments?: TimelineSegment[];
86
+ }): void;
87
+ }
88
+ declare function createTimeline(): Timeline;
89
+
90
+ interface RecorderEvents {
91
+ 'recording:started': (recordingId: string) => void;
92
+ 'recording:stopped': (recording: Recording) => void;
93
+ 'recording:paused': () => void;
94
+ 'recording:resumed': () => void;
95
+ 'step:recorded': (step: ExecutionStep) => void;
96
+ 'snapshot:created': (snapshot: Snapshot) => void;
97
+ 'checkpoint:created': (checkpoint: Checkpoint) => void;
98
+ error: (error: Error) => void;
99
+ }
100
+ type RecordingState = 'idle' | 'recording' | 'paused' | 'stopped';
101
+ declare class Recorder extends EventEmitter<RecorderEvents> {
102
+ private config;
103
+ private state;
104
+ private recordingId?;
105
+ private agentId?;
106
+ private agentName?;
107
+ private steps;
108
+ private startedAt;
109
+ private initialState?;
110
+ private currentState?;
111
+ private snapshots;
112
+ private checkpoints;
113
+ private timeline;
114
+ private storage?;
115
+ private estimatedSize;
116
+ constructor(config?: Partial<RecorderConfig>, storage?: RecordingStorageAdapter);
117
+ start(agentId: string, initialState: AgentState, agentName?: string): string;
118
+ stop(): Recording;
119
+ pause(): void;
120
+ resume(): void;
121
+ recordStep(step: ExecutionStep, state: AgentState): boolean;
122
+ createCheckpoint(name: string, description?: string): Checkpoint | undefined;
123
+ getState(): RecordingState;
124
+ getRecordingId(): string | undefined;
125
+ getStepsCount(): number;
126
+ getEstimatedSize(): number;
127
+ getTimeline(): Timeline;
128
+ getSnapshots(): Snapshot[];
129
+ getCheckpoints(): Checkpoint[];
130
+ save(): Promise<void>;
131
+ private filterStep;
132
+ private getStepDescription;
133
+ private buildRecording;
134
+ private buildMetadata;
135
+ }
136
+ declare function createRecorder(config?: Partial<RecorderConfig>, storage?: RecordingStorageAdapter): Recorder;
137
+
138
+ export { Recorder as R, Timeline as T, type RecorderEvents as a, createTimeline as b, createRecorder as c, type TimelineEventOptions as d, type TimelineMarker as e, type TimelineSegment as f, type TimelineFilterOptions as g, type TimelineStats as h };
@@ -0,0 +1,54 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { E as ExecutionStep, A as AgentState, m as Recording } from './recording.types-Ck7pbikw.js';
3
+ import { b as ReplaySession, f as ReplayResult, g as ReplayDifference, c as ReplayConfig, a as ReplaySpeed, d as ReplayModification } from './replay.types-C9hJizI-.js';
4
+
5
+ interface ReplayEngineEvents {
6
+ 'replay:started': (session: ReplaySession) => void;
7
+ 'replay:paused': (session: ReplaySession) => void;
8
+ 'replay:resumed': (session: ReplaySession) => void;
9
+ 'replay:stopped': (session: ReplaySession) => void;
10
+ 'replay:completed': (result: ReplayResult) => void;
11
+ 'step:replayed': (step: ExecutionStep, state: AgentState) => void;
12
+ 'step:modified': (original: ExecutionStep, modified: ExecutionStep) => void;
13
+ 'divergence:detected': (differences: ReplayDifference[]) => void;
14
+ error: (error: Error) => void;
15
+ }
16
+ interface ReplayOptions {
17
+ speed?: ReplaySpeed;
18
+ startStep?: number;
19
+ endStep?: number;
20
+ modifications?: ReplayModification[];
21
+ executeTools?: boolean;
22
+ executeLLM?: boolean;
23
+ onToolCall?: (step: ExecutionStep) => Promise<unknown>;
24
+ onLLMCall?: (step: ExecutionStep) => Promise<string>;
25
+ }
26
+ declare class ReplayEngine extends EventEmitter<ReplayEngineEvents> {
27
+ private config;
28
+ private sessions;
29
+ private currentSession?;
30
+ private stateRestorer;
31
+ private controller?;
32
+ private isRunning;
33
+ constructor(config?: Partial<ReplayConfig>);
34
+ start(recording: Recording, options?: ReplayOptions): ReplaySession;
35
+ private runReplay;
36
+ private executeStep;
37
+ private updateState;
38
+ private applyModification;
39
+ private compareResults;
40
+ private shouldPause;
41
+ private getSpeedMultiplier;
42
+ private getStepDelay;
43
+ pause(): void;
44
+ resume(): void;
45
+ stop(): void;
46
+ setSpeed(speed: ReplaySpeed): void;
47
+ jumpToStep(stepIndex: number): void;
48
+ getSession(): ReplaySession | undefined;
49
+ getSessionById(id: string): ReplaySession | undefined;
50
+ getSessions(): ReplaySession[];
51
+ }
52
+ declare function createReplayEngine(config?: Partial<ReplayConfig>): ReplayEngine;
53
+
54
+ export { ReplayEngine as R, type ReplayEngineEvents as a, type ReplayOptions as b, createReplayEngine as c };
@@ -0,0 +1,4 @@
1
+ export { A as AnalysisOptions, B as BatchScenarioOptions, F as FailureAnalyzer, d as FailurePattern, S as ScenarioOptions, e as StepAnalysis, W as WhatIfEngine, a as WhatIfEngineEvents, b as createFailureAnalyzer, c as createWhatIfEngine } from '../index-DRrKPSo9.js';
2
+ import 'eventemitter3';
3
+ import '../recording.types-Ck7pbikw.js';
4
+ import '../replay.types-C9hJizI-.js';