Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/agents/planner-executor/planner-executor-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ export interface PlannerExecutorAgentOptions {
resolvedProfile?: ResolvedAgentProfile;
/** Callback invoked after each step with structured outcome (for learning extraction) */
onStepOutcome?: (outcome: StepOutcome, snapshotElements?: SnapshotElement[]) => void;
/** Callback invoked at the start of each step with progress info (step number, token usage) */
onProgress?: (progress: {
step: number;
maxSteps: number;
totalTokens: number;
action?: string;
}) => void;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -516,6 +523,12 @@ export class PlannerExecutorAgent {
private recoveryState: RecoveryState | null = null;
private resolvedProfile?: ResolvedAgentProfile;
private onStepOutcome?: (outcome: StepOutcome, snapshotElements?: SnapshotElement[]) => void;
private onProgress?: (progress: {
step: number;
maxSteps: number;
totalTokens: number;
action?: string;
}) => void;

// Run state
private runId: string | null = null;
Expand All @@ -538,6 +551,7 @@ export class PlannerExecutorAgent {
});
this.resolvedProfile = options.resolvedProfile;
this.onStepOutcome = options.onStepOutcome;
this.onProgress = options.onProgress;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -761,6 +775,18 @@ export class PlannerExecutorAgent {
console.log(`${'='.repeat(60)}`);
}

// Emit progress callback
try {
const tokenSummary = this.tokenCollector.summary();
this.onProgress?.({
step: stepNum,
maxSteps,
totalTokens: tokenSummary.total.totalTokens,
});
} catch {
// Don't fail the run on progress callback errors
}

// Take snapshot with escalation
const ctx = await this.snapshotWithEscalation(runtime, task);
currentUrl = ctx.snapshot?.url || currentUrl;
Expand Down
Loading