Skip to content

Interface: AgentStrategy

@providerprotocol/agents


@providerprotocol/agents / index / 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.

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.

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}`),
};

optional onAct: (step, actions) => void

Defined in: src/execution/types.ts:83

Called during the action phase when tool calls are made.

number

The current step number

ToolCall[]

Array of tool calls the model wants to execute

void


optional onComplete: (result) => void

Defined in: src/execution/types.ts:103

Called when execution completes successfully.

GenerateResult

The final generation result

void


optional onError: (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.

Error

The error that occurred

AgentState

The agent state at the time of the error

void | GenerateResult

Optional fallback result to use instead of throwing


optional onObserve: (step, observations) => void

Defined in: src/execution/types.ts:90

Called during the observation phase after tools execute.

number

The current step number

ToolExecution[]

Array of tool execution results

void


optional onReason: (step, reasoning) => void

Defined in: src/execution/types.ts:76

Called during the reasoning phase (ReAct strategy only).

number

The current step number

string

The model’s reasoning output text

void


optional onStepEnd: (step, result) => void

Defined in: src/execution/types.ts:97

Called when a step completes, after all tool executions.

number

The completed step number

Object containing the turn and updated state

AgentState

Turn

void


optional onStepStart: (step, state) => void

Defined in: src/execution/types.ts:69

Called when a step begins, before any LLM calls.

number

The 1-indexed step number

AgentState

The current agent state at step start

void


optional stopCondition: (state) => boolean | Promise<boolean>

Defined in: src/execution/types.ts:62

Evaluate whether execution should stop after the current step.

AgentState

The current agent state after step completion

boolean | Promise<boolean>

true to stop execution, false to continue