Interface: AgentStrategy
@providerprotocol/agents / index / AgentStrategy
Interface: AgentStrategy
Section titled “Interface: AgentStrategy”Defined in: src/execution/types.ts:56
Agent lifecycle hooks for execution control and observability.
Strategies allow fine-grained control over agent execution by providing callbacks at key points in the execution lifecycle. All hooks are optional and can be sync or async where indicated.
Remarks
Section titled “Remarks”Hooks are called in order: onStepStart -> onReason (if ReAct) -> onAct -> onObserve -> onStepEnd. The stopCondition is evaluated after each step to determine if execution should halt.
Example
Section titled “Example”const strategy: AgentStrategy = { stopCondition: (state) => state.currentStep >= 5, onStepStart: (step, state) => console.log(`Step ${step} starting`), onAct: (step, actions) => console.log(`${actions.length} tool calls`), onComplete: (result) => console.log(`Done: ${result.turn.response.text}`),};Properties
Section titled “Properties”onAct()?
Section titled “onAct()?”
optionalonAct: (step,actions) =>void
Defined in: src/execution/types.ts:83
Called during the action phase when tool calls are made.
Parameters
Section titled “Parameters”number
The current step number
actions
Section titled “actions”ToolCall[]
Array of tool calls the model wants to execute
Returns
Section titled “Returns”void
onComplete()?
Section titled “onComplete()?”
optionalonComplete: (result) =>void
Defined in: src/execution/types.ts:103
Called when execution completes successfully.
Parameters
Section titled “Parameters”result
Section titled “result”The final generation result
Returns
Section titled “Returns”void
onError()?
Section titled “onError()?”
optionalonError: (error,state) =>void|GenerateResult
Defined in: src/execution/types.ts:112
Called when an error occurs during execution. Can optionally return a fallback result to recover from the error.
Parameters
Section titled “Parameters”Error
The error that occurred
The agent state at the time of the error
Returns
Section titled “Returns”void | GenerateResult
Optional fallback result to use instead of throwing
onObserve()?
Section titled “onObserve()?”
optionalonObserve: (step,observations) =>void
Defined in: src/execution/types.ts:90
Called during the observation phase after tools execute.
Parameters
Section titled “Parameters”number
The current step number
observations
Section titled “observations”ToolExecution[]
Array of tool execution results
Returns
Section titled “Returns”void
onReason()?
Section titled “onReason()?”
optionalonReason: (step,reasoning) =>void
Defined in: src/execution/types.ts:76
Called during the reasoning phase (ReAct strategy only).
Parameters
Section titled “Parameters”number
The current step number
reasoning
Section titled “reasoning”string
The model’s reasoning output text
Returns
Section titled “Returns”void
onStepEnd()?
Section titled “onStepEnd()?”
optionalonStepEnd: (step,result) =>void
Defined in: src/execution/types.ts:97
Called when a step completes, after all tool executions.
Parameters
Section titled “Parameters”number
The completed step number
result
Section titled “result”Object containing the turn and updated state
Turn
Returns
Section titled “Returns”void
onStepStart()?
Section titled “onStepStart()?”
optionalonStepStart: (step,state) =>void
Defined in: src/execution/types.ts:69
Called when a step begins, before any LLM calls.
Parameters
Section titled “Parameters”number
The 1-indexed step number
The current agent state at step start
Returns
Section titled “Returns”void
stopCondition()?
Section titled “stopCondition()?”
optionalstopCondition: (state) =>boolean|Promise<boolean>
Defined in: src/execution/types.ts:62
Evaluate whether execution should stop after the current step.
Parameters
Section titled “Parameters”The current agent state after step completion
Returns
Section titled “Returns”boolean | Promise<boolean>
true to stop execution, false to continue