Skip to content

Commit ea168bc

Browse files
authored
Merge pull request #209 from PredicateSystems/step_number
feat: add onProgress callback to PlannerExecutorAgent for live step/t…
2 parents 65e156f + f85a3c2 commit ea168bc

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/agents/planner-executor/planner-executor-agent.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ export interface PlannerExecutorAgentOptions {
470470
resolvedProfile?: ResolvedAgentProfile;
471471
/** Callback invoked after each step with structured outcome (for learning extraction) */
472472
onStepOutcome?: (outcome: StepOutcome, snapshotElements?: SnapshotElement[]) => void;
473+
/** Callback invoked at the start of each step with progress info (step number, token usage) */
474+
onProgress?: (progress: {
475+
step: number;
476+
maxSteps: number;
477+
totalTokens: number;
478+
action?: string;
479+
}) => void;
473480
}
474481

475482
// ---------------------------------------------------------------------------
@@ -516,6 +523,12 @@ export class PlannerExecutorAgent {
516523
private recoveryState: RecoveryState | null = null;
517524
private resolvedProfile?: ResolvedAgentProfile;
518525
private onStepOutcome?: (outcome: StepOutcome, snapshotElements?: SnapshotElement[]) => void;
526+
private onProgress?: (progress: {
527+
step: number;
528+
maxSteps: number;
529+
totalTokens: number;
530+
action?: string;
531+
}) => void;
519532

520533
// Run state
521534
private runId: string | null = null;
@@ -538,6 +551,7 @@ export class PlannerExecutorAgent {
538551
});
539552
this.resolvedProfile = options.resolvedProfile;
540553
this.onStepOutcome = options.onStepOutcome;
554+
this.onProgress = options.onProgress;
541555
}
542556

543557
// ---------------------------------------------------------------------------
@@ -761,6 +775,18 @@ export class PlannerExecutorAgent {
761775
console.log(`${'='.repeat(60)}`);
762776
}
763777

778+
// Emit progress callback
779+
try {
780+
const tokenSummary = this.tokenCollector.summary();
781+
this.onProgress?.({
782+
step: stepNum,
783+
maxSteps,
784+
totalTokens: tokenSummary.total.totalTokens,
785+
});
786+
} catch {
787+
// Don't fail the run on progress callback errors
788+
}
789+
764790
// Take snapshot with escalation
765791
const ctx = await this.snapshotWithEscalation(runtime, task);
766792
currentUrl = ctx.snapshot?.url || currentUrl;

0 commit comments

Comments
 (0)