lemura 1.4.3 → 1.5.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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as IProviderAdapter, T as TranscriptionRequest, d as TranscriptionResponse, e as SynthesisRequest, A as AudioChunk, V as VisionRequest, f as VisionResponse, g as ImageGenRequest, h as ImageGenResponse, M as ModelInfo, C as ContextWindow, i as Turn, j as ContentBlock, I as IToolDefinition } from './adapters-BhTAnrOM.mjs';
2
- export { k as CompletionChunk, l as CompletionRequest, m as CompletionResponse, b as IContextStrategy, c as IScratchpadAdapter, n as IStorageAdapter, N as NormalizedMessage, o as STMItem, p as STMRegistryConfig, S as ShortTermMemoryRegistry, q as TokenUsage, r as ToolCall, s as ToolContext, t as ToolResult } from './adapters-BhTAnrOM.mjs';
3
- import { S as SessionConfig, I as IToolResponseProcessor, T as ToolResponseEvaluation, M as MCPServerConfig, a as MCPToolDefinition } from './agent-DfN5nNXc.mjs';
4
- export { b as MCPJsonRpcRequest, c as MCPJsonRpcResponse, d as MCPTransportType, e as MediaConfig, f as ToolDecision, g as ToolExecutionBudget, h as ToolFirewallConfig, i as ToolFirewallRule, j as TraceEvent } from './agent-DfN5nNXc.mjs';
1
+ import { a as IProviderAdapter, d as TranscriptionRequest, e as TranscriptionResponse, f as SynthesisRequest, A as AudioChunk, V as VisionRequest, g as VisionResponse, h as ImageGenRequest, i as ImageGenResponse, M as ModelInfo, C as ContextWindow, T as Turn, j as ContentBlock, I as IToolDefinition } from './adapters-S96Ka9wt.mjs';
2
+ export { k as CompletionChunk, l as CompletionRequest, m as CompletionResponse, b as IContextStrategy, c as IScratchpadAdapter, n as IStorageAdapter, N as NormalizedMessage, o as STMItem, p as STMRegistryConfig, S as ShortTermMemoryRegistry, q as TokenUsage, r as ToolCall, s as ToolContext, t as ToolResult } from './adapters-S96Ka9wt.mjs';
3
+ import { S as SessionConfig, G as Goal, I as IToolResponseProcessor, T as ToolResponseEvaluation, M as MCPServerConfig, a as MCPToolDefinition } from './agent-BefjpRHZ.mjs';
4
+ export { b as GoalInjector, c as GoalVerifierResult, d as MCPJsonRpcRequest, e as MCPJsonRpcResponse, f as MCPTransportType, g as MediaConfig, h as ToolDecision, i as ToolExecutionBudget, j as ToolFirewallConfig, k as ToolFirewallRule, l as TraceEvent } from './agent-BefjpRHZ.mjs';
5
5
  export { LemuraAdapterError, LemuraContextOverflowError, LemuraError, LemuraMCPConnectionError, LemuraMCPError, LemuraMCPTimeoutError, LemuraMaxIterationsError, LemuraSkillInjectionError, LemuraToolNotFoundError, LemuraToolTimeoutError, LemuraToolValidationError } from './types/index.mjs';
6
6
  import { I as ILogger } from './logger-DxvKliuk.mjs';
7
7
  export { L as LogLevel, a as LogMetadata, S as Severity } from './logger-DxvKliuk.mjs';
@@ -30,67 +30,6 @@ declare class MediaBridge {
30
30
  supportsVision(): boolean;
31
31
  }
32
32
 
33
- interface Goal {
34
- id: string;
35
- statement: string;
36
- /** High-level sub-goals decomposed from the main statement */
37
- decomposition: string[];
38
- successCriteria: string[];
39
- injectionFrequency: 'always' | 'every_N_turns' | 'on_compression';
40
- injectionPosition: 'system_prompt' | 'pre_turn';
41
- /** Sub-goals already completed — updated via `markSubGoalDone()` */
42
- completedSubGoals?: string[];
43
- }
44
- /**
45
- * GoalInjector keeps the original task objective visible throughout the ReAct loop,
46
- * preventing goal drift after many tool calls and context compressions.
47
- *
48
- * Usage in SessionManager:
49
- * - For `system_prompt` position: call `injectInto(prompt)` which appends the goal block.
50
- * - For `pre_turn` position: call `getFormattedBlock()` and push as a system message.
51
- */
52
- declare class GoalInjector {
53
- private goal;
54
- private turnsSinceInjection;
55
- constructor(goal: Goal);
56
- /**
57
- * Returns the formatted `[CURRENT GOAL]` block string — without caring about
58
- * where it will be placed. Callers decide whether to append to a system prompt
59
- * or push as a separate message.
60
- */
61
- getFormattedBlock(): string;
62
- /**
63
- * Appends the goal block to the given prompt string (for `system_prompt` position).
64
- * For `pre_turn` position, use `getFormattedBlock()` directly.
65
- *
66
- * @param prompt - The existing system prompt to append to.
67
- */
68
- injectInto(prompt: string): string;
69
- /**
70
- * Returns true when the goal should be re-injected this turn,
71
- * based on `injectionFrequency`.
72
- *
73
- * @param turnIndex - The current turn index in the ReAct loop (0-based)
74
- * @param compressionOccurred - Whether context was compressed this iteration
75
- * @param injectionN - The N for 'every_N_turns' frequency (default: 3)
76
- */
77
- shouldInjectThisTurn(turnIndex: number, compressionOccurred?: boolean, injectionN?: number): boolean;
78
- /**
79
- * Updates the goal with new sub-goal decomposition and success criteria,
80
- * typically populated by the mini-planning LLM call.
81
- */
82
- updateDecomposition(decomposition: string[], successCriteria?: string[]): void;
83
- /**
84
- * Marks a sub-goal as completed so it moves to the "completed" section
85
- * in subsequent injections.
86
- */
87
- markSubGoalDone(subGoal: string): void;
88
- /** Returns a snapshot of the current goal state (safe to store in context.metadata). */
89
- getGoal(): Goal;
90
- /** Increments the internal turn counter (used for `every_N_turns` frequency). */
91
- incrementTurn(): void;
92
- }
93
-
94
33
  /**
95
34
  * An optional condition that gates a step's execution on the output of a prior step.
96
35
  * When the condition is not met, the step is automatically marked `skipped`.
@@ -101,6 +40,44 @@ interface StepCondition {
101
40
  /** Substring that must be present in the prior step's output to allow this step to run */
102
41
  outputContains: string;
103
42
  }
43
+ /**
44
+ * Result returned by a `StepVerifier.check` function.
45
+ * - `pass` — the sub-goal is achieved; the step is marked `done`.
46
+ * - `fail` — the sub-goal failed; the step is marked `failed` and BFS propagates to dependants.
47
+ * - `retry` — the output is unsatisfactory but retriable; the step is reset to `pending`.
48
+ */
49
+ interface StepVerifierResult {
50
+ status: 'pass' | 'fail' | 'retry';
51
+ reason?: string;
52
+ }
53
+ /**
54
+ * Optional semantic verifier attached to a `ContinuationStep`.
55
+ * Called after the tool executes successfully to confirm the sub-goal is actually met.
56
+ *
57
+ * @example
58
+ * verify: {
59
+ * maxRetries: 2,
60
+ * check: (output) => {
61
+ * const data = JSON.parse(output);
62
+ * return data.rows?.length > 0
63
+ * ? { status: 'pass' }
64
+ * : { status: 'retry', reason: 'Empty result set' };
65
+ * }
66
+ * }
67
+ */
68
+ interface StepVerifier {
69
+ /**
70
+ * Inspects the tool output and decides whether the sub-goal is satisfied.
71
+ * @param output - Serialised tool result string
72
+ * @param args - The resolved arguments that were passed to the tool
73
+ */
74
+ check: (output: string, args: Record<string, unknown>) => Promise<StepVerifierResult> | StepVerifierResult;
75
+ /**
76
+ * Maximum number of `retry` verdicts allowed before the step is forced to `failed`.
77
+ * Defaults to 0 (no retries — a `retry` verdict immediately becomes `failed`).
78
+ */
79
+ maxRetries?: number;
80
+ }
104
81
  interface ContinuationStep {
105
82
  stepId: string;
106
83
  toolName: string;
@@ -124,6 +101,14 @@ interface ContinuationStep {
124
101
  * contains the given substring. When the condition is not met, the step is skipped.
125
102
  */
126
103
  condition?: StepCondition;
104
+ /**
105
+ * Optional semantic verifier: called after the tool executes to confirm the
106
+ * sub-goal is actually satisfied. Supports `pass / fail / retry` verdicts
107
+ * with a configurable `maxRetries` count.
108
+ *
109
+ * @since 1.4.4
110
+ */
111
+ verify?: StepVerifier;
127
112
  }
128
113
  interface ContinuationPlan {
129
114
  steps: ContinuationStep[];
@@ -152,7 +137,13 @@ interface ContinuationPlan {
152
137
  declare class ContinuationPlanner {
153
138
  private plan;
154
139
  private outputs;
155
- constructor(plan: ContinuationPlan);
140
+ private retryCount;
141
+ private onStepSkipped;
142
+ private onStepFailed;
143
+ constructor(plan: ContinuationPlan, callbacks?: {
144
+ onStepSkipped?: (stepId: string, reason: string) => void;
145
+ onStepFailed?: (stepId: string, reason: string) => void;
146
+ });
156
147
  /** Returns the current plan (deep copy) */
157
148
  getPlan(): ContinuationPlan;
158
149
  /** Returns a human-readable status string with icons (injected before each iteration) */
@@ -172,11 +163,18 @@ declare class ContinuationPlanner {
172
163
  /**
173
164
  * Marks a step as failed and propagates `skipped` to all transitively dependent steps.
174
165
  */
175
- markStepFailed(stepId: string): void;
166
+ markStepFailed(stepId: string, reason?: string): void;
176
167
  /**
177
168
  * Marks a step as skipped (e.g., condition not met) and propagates to its dependants.
178
169
  */
179
- markStepSkipped(stepId: string): void;
170
+ markStepSkipped(stepId: string, reason?: string): void;
171
+ /**
172
+ * Resets a step back to `pending` for a retry attempt.
173
+ * Increments the internal retry counter for the step.
174
+ */
175
+ markStepPending(stepId: string): void;
176
+ /** Returns how many times a step has been retried. */
177
+ getRetryCount(stepId: string): number;
180
178
  /** Retrieves an output stored by `outputKey` from a completed step */
181
179
  getOutput(key: string): string | undefined;
182
180
  /**
@@ -320,6 +318,22 @@ declare class SessionManager {
320
318
  * ```
321
319
  */
322
320
  setPlan(steps: ContinuationStep[], strategy?: ContinuationPlan['strategy']): void;
321
+ /**
322
+ * Returns a snapshot of the current continuation plan, or `null` if no plan
323
+ * has been set via `setPlan()`.
324
+ *
325
+ * Use this after `run()` to inspect which steps completed, failed, or were skipped.
326
+ *
327
+ * @since 1.4.4
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * await session.run('Run the pipeline');
332
+ * const plan = session.getPlan();
333
+ * const failed = plan?.steps.filter(s => s.status === 'failed');
334
+ * ```
335
+ */
336
+ getPlan(): ContinuationPlan | null;
323
337
  /**
324
338
  * Manually sets the agent's goal, bypassing the automatic mini-planning LLM call.
325
339
  *
@@ -374,9 +388,6 @@ declare class SessionManager {
374
388
  /**
375
389
  * Runs the full ReAct loop for a user message and returns the final assistant response.
376
390
  *
377
- * When `enableGoalPlanning` is true and no goal has been manually set, a mini-planning
378
- * LLM call is made before the first iteration to decompose the task into sub-goals.
379
- *
380
391
  * @param userMessage - The user's message (string or multimodal content blocks)
381
392
  * @returns The assistant's final response string
382
393
  * @throws {LemuraMaxIterationsError} When the loop exceeds `maxIterations`
@@ -385,8 +396,8 @@ declare class SessionManager {
385
396
  /**
386
397
  * Runs the ReAct loop and streams the final assistant response token-by-token.
387
398
  *
388
- * Tool calls within the loop are still executed synchronously (they must complete
389
- * before streaming the conclusion). Only the final LLM text output is streamed.
399
+ * All tool calls, goal verification, and corrections complete before any token
400
+ * is yielded the stream delivers only the clean final response.
390
401
  *
391
402
  * @param userMessage - The user's message (string or multimodal content blocks)
392
403
  * @returns An `AsyncIterable<string>` of delta tokens from the final response
@@ -399,6 +410,29 @@ declare class SessionManager {
399
410
  * ```
400
411
  */
401
412
  stream(userMessage: string | ContentBlock[]): AsyncIterable<string>;
413
+ /**
414
+ * Core ReAct execution loop shared by `run()` and `stream()`.
415
+ *
416
+ * Uses `adapter.complete()` exclusively — no streaming occurs here.
417
+ * Goal verification and silent corrections run inside this method,
418
+ * fully isolated from the caller's delivery path.
419
+ *
420
+ * @returns The final assistant response string
421
+ * @throws {LemuraMaxIterationsError} When the loop exceeds `maxIterations`
422
+ */
423
+ private _executeLoop;
424
+ /**
425
+ * Verifies whether the goal was achieved after a `stop` finish.
426
+ *
427
+ * Priority:
428
+ * 1. `config.goalVerifier` callback (Option A — user-supplied)
429
+ * 2. Built-in LLM check against `successCriteria` (Option C — fallback)
430
+ *
431
+ * Returns `null` when verification is skipped (no goal, planning disabled, etc.).
432
+ *
433
+ * @since 1.5.0
434
+ */
435
+ private _verifyGoal;
402
436
  /**
403
437
  * Resets the session: clears conversation history, resets iteration counters,
404
438
  * tool execution budget tallies, and goal/plan state.
@@ -612,4 +646,4 @@ declare class MCPClientRegistry {
612
646
  private _bridge;
613
647
  }
614
648
 
615
- export { AudioChunk, ContentBlock, ContextWindow, type ContinuationPlan, ContinuationPlanner, type ContinuationStep, FinalResponseFormatter, type Goal, GoalInjector, ILogger, IProviderAdapter, IToolDefinition, IToolResponseProcessor, ImageGenRequest, ImageGenResponse, MCPClient, MCPClientRegistry, MCPServerConfig, MCPToolDefinition, MediaBridge, ModelInfo, SessionConfig, SessionManager, SkillInjector, type StepCondition, StepCounter, SynthesisRequest, ToolRegistry, ToolResponseEvaluation, ToolResponseProcessor, type ToolResponseProcessorConfig, TranscriptionRequest, TranscriptionResponse, Turn, VisionRequest, VisionResponse };
649
+ export { AudioChunk, ContentBlock, ContextWindow, type ContinuationPlan, ContinuationPlanner, type ContinuationStep, FinalResponseFormatter, Goal, ILogger, IProviderAdapter, IToolDefinition, IToolResponseProcessor, ImageGenRequest, ImageGenResponse, MCPClient, MCPClientRegistry, MCPServerConfig, MCPToolDefinition, MediaBridge, ModelInfo, SessionConfig, SessionManager, SkillInjector, type StepCondition, StepCounter, type StepVerifier, type StepVerifierResult, SynthesisRequest, ToolRegistry, ToolResponseEvaluation, ToolResponseProcessor, type ToolResponseProcessorConfig, TranscriptionRequest, TranscriptionResponse, Turn, VisionRequest, VisionResponse };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as IProviderAdapter, T as TranscriptionRequest, d as TranscriptionResponse, e as SynthesisRequest, A as AudioChunk, V as VisionRequest, f as VisionResponse, g as ImageGenRequest, h as ImageGenResponse, M as ModelInfo, C as ContextWindow, i as Turn, j as ContentBlock, I as IToolDefinition } from './adapters-CVcfWf85.js';
2
- export { k as CompletionChunk, l as CompletionRequest, m as CompletionResponse, b as IContextStrategy, c as IScratchpadAdapter, n as IStorageAdapter, N as NormalizedMessage, o as STMItem, p as STMRegistryConfig, S as ShortTermMemoryRegistry, q as TokenUsage, r as ToolCall, s as ToolContext, t as ToolResult } from './adapters-CVcfWf85.js';
3
- import { S as SessionConfig, I as IToolResponseProcessor, T as ToolResponseEvaluation, M as MCPServerConfig, a as MCPToolDefinition } from './agent-DTcDIKIn.js';
4
- export { b as MCPJsonRpcRequest, c as MCPJsonRpcResponse, d as MCPTransportType, e as MediaConfig, f as ToolDecision, g as ToolExecutionBudget, h as ToolFirewallConfig, i as ToolFirewallRule, j as TraceEvent } from './agent-DTcDIKIn.js';
1
+ import { a as IProviderAdapter, d as TranscriptionRequest, e as TranscriptionResponse, f as SynthesisRequest, A as AudioChunk, V as VisionRequest, g as VisionResponse, h as ImageGenRequest, i as ImageGenResponse, M as ModelInfo, C as ContextWindow, T as Turn, j as ContentBlock, I as IToolDefinition } from './adapters-DHQOGl8Y.js';
2
+ export { k as CompletionChunk, l as CompletionRequest, m as CompletionResponse, b as IContextStrategy, c as IScratchpadAdapter, n as IStorageAdapter, N as NormalizedMessage, o as STMItem, p as STMRegistryConfig, S as ShortTermMemoryRegistry, q as TokenUsage, r as ToolCall, s as ToolContext, t as ToolResult } from './adapters-DHQOGl8Y.js';
3
+ import { S as SessionConfig, G as Goal, I as IToolResponseProcessor, T as ToolResponseEvaluation, M as MCPServerConfig, a as MCPToolDefinition } from './agent-CjoFQGlk.js';
4
+ export { b as GoalInjector, c as GoalVerifierResult, d as MCPJsonRpcRequest, e as MCPJsonRpcResponse, f as MCPTransportType, g as MediaConfig, h as ToolDecision, i as ToolExecutionBudget, j as ToolFirewallConfig, k as ToolFirewallRule, l as TraceEvent } from './agent-CjoFQGlk.js';
5
5
  export { LemuraAdapterError, LemuraContextOverflowError, LemuraError, LemuraMCPConnectionError, LemuraMCPError, LemuraMCPTimeoutError, LemuraMaxIterationsError, LemuraSkillInjectionError, LemuraToolNotFoundError, LemuraToolTimeoutError, LemuraToolValidationError } from './types/index.js';
6
6
  import { I as ILogger } from './logger-DxvKliuk.js';
7
7
  export { L as LogLevel, a as LogMetadata, S as Severity } from './logger-DxvKliuk.js';
@@ -30,67 +30,6 @@ declare class MediaBridge {
30
30
  supportsVision(): boolean;
31
31
  }
32
32
 
33
- interface Goal {
34
- id: string;
35
- statement: string;
36
- /** High-level sub-goals decomposed from the main statement */
37
- decomposition: string[];
38
- successCriteria: string[];
39
- injectionFrequency: 'always' | 'every_N_turns' | 'on_compression';
40
- injectionPosition: 'system_prompt' | 'pre_turn';
41
- /** Sub-goals already completed — updated via `markSubGoalDone()` */
42
- completedSubGoals?: string[];
43
- }
44
- /**
45
- * GoalInjector keeps the original task objective visible throughout the ReAct loop,
46
- * preventing goal drift after many tool calls and context compressions.
47
- *
48
- * Usage in SessionManager:
49
- * - For `system_prompt` position: call `injectInto(prompt)` which appends the goal block.
50
- * - For `pre_turn` position: call `getFormattedBlock()` and push as a system message.
51
- */
52
- declare class GoalInjector {
53
- private goal;
54
- private turnsSinceInjection;
55
- constructor(goal: Goal);
56
- /**
57
- * Returns the formatted `[CURRENT GOAL]` block string — without caring about
58
- * where it will be placed. Callers decide whether to append to a system prompt
59
- * or push as a separate message.
60
- */
61
- getFormattedBlock(): string;
62
- /**
63
- * Appends the goal block to the given prompt string (for `system_prompt` position).
64
- * For `pre_turn` position, use `getFormattedBlock()` directly.
65
- *
66
- * @param prompt - The existing system prompt to append to.
67
- */
68
- injectInto(prompt: string): string;
69
- /**
70
- * Returns true when the goal should be re-injected this turn,
71
- * based on `injectionFrequency`.
72
- *
73
- * @param turnIndex - The current turn index in the ReAct loop (0-based)
74
- * @param compressionOccurred - Whether context was compressed this iteration
75
- * @param injectionN - The N for 'every_N_turns' frequency (default: 3)
76
- */
77
- shouldInjectThisTurn(turnIndex: number, compressionOccurred?: boolean, injectionN?: number): boolean;
78
- /**
79
- * Updates the goal with new sub-goal decomposition and success criteria,
80
- * typically populated by the mini-planning LLM call.
81
- */
82
- updateDecomposition(decomposition: string[], successCriteria?: string[]): void;
83
- /**
84
- * Marks a sub-goal as completed so it moves to the "completed" section
85
- * in subsequent injections.
86
- */
87
- markSubGoalDone(subGoal: string): void;
88
- /** Returns a snapshot of the current goal state (safe to store in context.metadata). */
89
- getGoal(): Goal;
90
- /** Increments the internal turn counter (used for `every_N_turns` frequency). */
91
- incrementTurn(): void;
92
- }
93
-
94
33
  /**
95
34
  * An optional condition that gates a step's execution on the output of a prior step.
96
35
  * When the condition is not met, the step is automatically marked `skipped`.
@@ -101,6 +40,44 @@ interface StepCondition {
101
40
  /** Substring that must be present in the prior step's output to allow this step to run */
102
41
  outputContains: string;
103
42
  }
43
+ /**
44
+ * Result returned by a `StepVerifier.check` function.
45
+ * - `pass` — the sub-goal is achieved; the step is marked `done`.
46
+ * - `fail` — the sub-goal failed; the step is marked `failed` and BFS propagates to dependants.
47
+ * - `retry` — the output is unsatisfactory but retriable; the step is reset to `pending`.
48
+ */
49
+ interface StepVerifierResult {
50
+ status: 'pass' | 'fail' | 'retry';
51
+ reason?: string;
52
+ }
53
+ /**
54
+ * Optional semantic verifier attached to a `ContinuationStep`.
55
+ * Called after the tool executes successfully to confirm the sub-goal is actually met.
56
+ *
57
+ * @example
58
+ * verify: {
59
+ * maxRetries: 2,
60
+ * check: (output) => {
61
+ * const data = JSON.parse(output);
62
+ * return data.rows?.length > 0
63
+ * ? { status: 'pass' }
64
+ * : { status: 'retry', reason: 'Empty result set' };
65
+ * }
66
+ * }
67
+ */
68
+ interface StepVerifier {
69
+ /**
70
+ * Inspects the tool output and decides whether the sub-goal is satisfied.
71
+ * @param output - Serialised tool result string
72
+ * @param args - The resolved arguments that were passed to the tool
73
+ */
74
+ check: (output: string, args: Record<string, unknown>) => Promise<StepVerifierResult> | StepVerifierResult;
75
+ /**
76
+ * Maximum number of `retry` verdicts allowed before the step is forced to `failed`.
77
+ * Defaults to 0 (no retries — a `retry` verdict immediately becomes `failed`).
78
+ */
79
+ maxRetries?: number;
80
+ }
104
81
  interface ContinuationStep {
105
82
  stepId: string;
106
83
  toolName: string;
@@ -124,6 +101,14 @@ interface ContinuationStep {
124
101
  * contains the given substring. When the condition is not met, the step is skipped.
125
102
  */
126
103
  condition?: StepCondition;
104
+ /**
105
+ * Optional semantic verifier: called after the tool executes to confirm the
106
+ * sub-goal is actually satisfied. Supports `pass / fail / retry` verdicts
107
+ * with a configurable `maxRetries` count.
108
+ *
109
+ * @since 1.4.4
110
+ */
111
+ verify?: StepVerifier;
127
112
  }
128
113
  interface ContinuationPlan {
129
114
  steps: ContinuationStep[];
@@ -152,7 +137,13 @@ interface ContinuationPlan {
152
137
  declare class ContinuationPlanner {
153
138
  private plan;
154
139
  private outputs;
155
- constructor(plan: ContinuationPlan);
140
+ private retryCount;
141
+ private onStepSkipped;
142
+ private onStepFailed;
143
+ constructor(plan: ContinuationPlan, callbacks?: {
144
+ onStepSkipped?: (stepId: string, reason: string) => void;
145
+ onStepFailed?: (stepId: string, reason: string) => void;
146
+ });
156
147
  /** Returns the current plan (deep copy) */
157
148
  getPlan(): ContinuationPlan;
158
149
  /** Returns a human-readable status string with icons (injected before each iteration) */
@@ -172,11 +163,18 @@ declare class ContinuationPlanner {
172
163
  /**
173
164
  * Marks a step as failed and propagates `skipped` to all transitively dependent steps.
174
165
  */
175
- markStepFailed(stepId: string): void;
166
+ markStepFailed(stepId: string, reason?: string): void;
176
167
  /**
177
168
  * Marks a step as skipped (e.g., condition not met) and propagates to its dependants.
178
169
  */
179
- markStepSkipped(stepId: string): void;
170
+ markStepSkipped(stepId: string, reason?: string): void;
171
+ /**
172
+ * Resets a step back to `pending` for a retry attempt.
173
+ * Increments the internal retry counter for the step.
174
+ */
175
+ markStepPending(stepId: string): void;
176
+ /** Returns how many times a step has been retried. */
177
+ getRetryCount(stepId: string): number;
180
178
  /** Retrieves an output stored by `outputKey` from a completed step */
181
179
  getOutput(key: string): string | undefined;
182
180
  /**
@@ -320,6 +318,22 @@ declare class SessionManager {
320
318
  * ```
321
319
  */
322
320
  setPlan(steps: ContinuationStep[], strategy?: ContinuationPlan['strategy']): void;
321
+ /**
322
+ * Returns a snapshot of the current continuation plan, or `null` if no plan
323
+ * has been set via `setPlan()`.
324
+ *
325
+ * Use this after `run()` to inspect which steps completed, failed, or were skipped.
326
+ *
327
+ * @since 1.4.4
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * await session.run('Run the pipeline');
332
+ * const plan = session.getPlan();
333
+ * const failed = plan?.steps.filter(s => s.status === 'failed');
334
+ * ```
335
+ */
336
+ getPlan(): ContinuationPlan | null;
323
337
  /**
324
338
  * Manually sets the agent's goal, bypassing the automatic mini-planning LLM call.
325
339
  *
@@ -374,9 +388,6 @@ declare class SessionManager {
374
388
  /**
375
389
  * Runs the full ReAct loop for a user message and returns the final assistant response.
376
390
  *
377
- * When `enableGoalPlanning` is true and no goal has been manually set, a mini-planning
378
- * LLM call is made before the first iteration to decompose the task into sub-goals.
379
- *
380
391
  * @param userMessage - The user's message (string or multimodal content blocks)
381
392
  * @returns The assistant's final response string
382
393
  * @throws {LemuraMaxIterationsError} When the loop exceeds `maxIterations`
@@ -385,8 +396,8 @@ declare class SessionManager {
385
396
  /**
386
397
  * Runs the ReAct loop and streams the final assistant response token-by-token.
387
398
  *
388
- * Tool calls within the loop are still executed synchronously (they must complete
389
- * before streaming the conclusion). Only the final LLM text output is streamed.
399
+ * All tool calls, goal verification, and corrections complete before any token
400
+ * is yielded the stream delivers only the clean final response.
390
401
  *
391
402
  * @param userMessage - The user's message (string or multimodal content blocks)
392
403
  * @returns An `AsyncIterable<string>` of delta tokens from the final response
@@ -399,6 +410,29 @@ declare class SessionManager {
399
410
  * ```
400
411
  */
401
412
  stream(userMessage: string | ContentBlock[]): AsyncIterable<string>;
413
+ /**
414
+ * Core ReAct execution loop shared by `run()` and `stream()`.
415
+ *
416
+ * Uses `adapter.complete()` exclusively — no streaming occurs here.
417
+ * Goal verification and silent corrections run inside this method,
418
+ * fully isolated from the caller's delivery path.
419
+ *
420
+ * @returns The final assistant response string
421
+ * @throws {LemuraMaxIterationsError} When the loop exceeds `maxIterations`
422
+ */
423
+ private _executeLoop;
424
+ /**
425
+ * Verifies whether the goal was achieved after a `stop` finish.
426
+ *
427
+ * Priority:
428
+ * 1. `config.goalVerifier` callback (Option A — user-supplied)
429
+ * 2. Built-in LLM check against `successCriteria` (Option C — fallback)
430
+ *
431
+ * Returns `null` when verification is skipped (no goal, planning disabled, etc.).
432
+ *
433
+ * @since 1.5.0
434
+ */
435
+ private _verifyGoal;
402
436
  /**
403
437
  * Resets the session: clears conversation history, resets iteration counters,
404
438
  * tool execution budget tallies, and goal/plan state.
@@ -612,4 +646,4 @@ declare class MCPClientRegistry {
612
646
  private _bridge;
613
647
  }
614
648
 
615
- export { AudioChunk, ContentBlock, ContextWindow, type ContinuationPlan, ContinuationPlanner, type ContinuationStep, FinalResponseFormatter, type Goal, GoalInjector, ILogger, IProviderAdapter, IToolDefinition, IToolResponseProcessor, ImageGenRequest, ImageGenResponse, MCPClient, MCPClientRegistry, MCPServerConfig, MCPToolDefinition, MediaBridge, ModelInfo, SessionConfig, SessionManager, SkillInjector, type StepCondition, StepCounter, SynthesisRequest, ToolRegistry, ToolResponseEvaluation, ToolResponseProcessor, type ToolResponseProcessorConfig, TranscriptionRequest, TranscriptionResponse, Turn, VisionRequest, VisionResponse };
649
+ export { AudioChunk, ContentBlock, ContextWindow, type ContinuationPlan, ContinuationPlanner, type ContinuationStep, FinalResponseFormatter, Goal, ILogger, IProviderAdapter, IToolDefinition, IToolResponseProcessor, ImageGenRequest, ImageGenResponse, MCPClient, MCPClientRegistry, MCPServerConfig, MCPToolDefinition, MediaBridge, ModelInfo, SessionConfig, SessionManager, SkillInjector, type StepCondition, StepCounter, type StepVerifier, type StepVerifierResult, SynthesisRequest, ToolRegistry, ToolResponseEvaluation, ToolResponseProcessor, type ToolResponseProcessorConfig, TranscriptionRequest, TranscriptionResponse, Turn, VisionRequest, VisionResponse };