@@ -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