Documentation

Build LLM-powered agents
with production-ready TypeScript

DSPy for TypeScript. Working with LLMs is complex—they don't always do what you want. DSPy makes it easier to build amazing things with LLMs. Just define your inputs and outputs (signature) and an efficient prompt is auto-generated and used. Connect together various signatures to build complex systems and workflows using LLMs.

15+ LLM Providers
End-to-end Streaming
Auto Prompt Tuning

AxStepContextImpl

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L14

Internal implementation of AxStepContext. Uses a pending mutations pattern: mutations are collected during a step and consumed/applied at the next step boundary.

Implements

Constructors

Constructor

new AxStepContextImpl(maxSteps: number): AxStepContextImpl;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L41

Parameters

ParameterType
maxStepsnumber

Returns

AxStepContextImpl

Properties

PropertyModifierType
maxStepsreadonlynumber
statereadonlyMap<string, unknown>

Accessors

_isStopRequested

Get Signature

get _isStopRequested(): boolean;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L176

Check if stop was requested.

Returns

boolean


_stopValues

Get Signature

get _stopValues(): undefined | Record<string, unknown>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L181

Get stop result values if any.

Returns

undefined | Record<string, unknown>


functionsExecuted

Get Signature

get functionsExecuted(): ReadonlySet<string>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L55

Returns

ReadonlySet<string>

Implementation of

AxStepContext.functionsExecuted


isFirstStep

Get Signature

get isFirstStep(): boolean;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L51

Returns

boolean

Implementation of

AxStepContext.isFirstStep


lastFunctionCalls

Get Signature

get lastFunctionCalls(): readonly AxFunctionCallRecord[];

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L59

Returns

readonly AxFunctionCallRecord[]

Implementation of

AxStepContext.lastFunctionCalls


stepIndex

Get Signature

get stepIndex(): number;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L47

Returns

number

Implementation of

AxStepContext.stepIndex


usage

Get Signature

get usage(): Readonly<AxStepUsage>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L63

Returns

Readonly<AxStepUsage>

Implementation of

AxStepContext.usage

Methods

_addUsage()

_addUsage(
   promptTokens: number, 
   completionTokens: number, 
   totalTokens: number): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L128

Accumulate token usage from a completed step.

Parameters

ParameterType
promptTokensnumber
completionTokensnumber
totalTokensnumber

Returns

void


_beginStep()

_beginStep(stepIndex: number): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L115

Reset per-step state at the beginning of a new step.

Parameters

ParameterType
stepIndexnumber

Returns

void


_consumeFunctionsToAdd()

_consumeFunctionsToAdd(): undefined | AxInputFunctionType;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L156

Consume and clear pending functions to add.

Returns

undefined | AxInputFunctionType


_consumeFunctionsToRemove()

_consumeFunctionsToRemove(): undefined | string[];

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L166

Consume and clear pending function names to remove.

Returns

undefined | string[]


_consumePendingOptions()

_consumePendingOptions(): 
  | undefined
| Partial<AxAIServiceOptions & object>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L139

Consume and clear pending options. Returns undefined if no pending options.

Returns

| undefined | Partial<AxAIServiceOptions & object>


_recordFunctionCall()

_recordFunctionCall(
   name: string, 
   args: unknown, 
   result: unknown): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L122

Record a function call that was executed during this step.

Parameters

ParameterType
namestring
argsunknown
resultunknown

Returns

void


addFunctions()

addFunctions(functions: AxInputFunctionType): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L99

Parameters

ParameterType
functionsAxInputFunctionType

Returns

void

Implementation of

AxStepContext.addFunctions


removeFunctions()

removeFunctions(...names: string[]): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L103

Parameters

ParameterType
namesstring[]

Returns

void

Implementation of

AxStepContext.removeFunctions


setMaxTokens()

setMaxTokens(maxTokens: number): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L84

Parameters

ParameterType
maxTokensnumber

Returns

void

Implementation of

AxStepContext.setMaxTokens


setModel()

setModel(model: string): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L69

Parameters

ParameterType
modelstring

Returns

void

Implementation of

AxStepContext.setModel


setOptions()

setOptions(options: Partial<AxAIServiceOptions & object>): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L91

Parameters

ParameterType
optionsPartial<AxAIServiceOptions & object>

Returns

void

Implementation of

AxStepContext.setOptions


setTemperature()

setTemperature(temperature: number): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L77

Parameters

ParameterType
temperaturenumber

Returns

void

Implementation of

AxStepContext.setTemperature


setThinkingBudget()

setThinkingBudget(budget: undefined | "high" | "low" | "minimal" | "medium" | "highest" | "none"): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L73

Parameters

ParameterType
budgetundefined | "high" | "low" | "minimal" | "medium" | "highest" | "none"

Returns

void

Implementation of

AxStepContext.setThinkingBudget


stop()

stop(resultValues?: Record<string, unknown>): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/dsp/stepContext.ts#L107

Parameters

ParameterType
resultValues?Record<string, unknown>

Returns

void

Implementation of

AxStepContext.stop