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

AxProgram

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

Extended by

Type Parameters

Type ParameterDefault type
INany
OUTany

Implements

Constructors

Constructor

new AxProgram<IN, OUT>(signature: 
  | undefined
  | string
  | Readonly<AxSignature<Record<string, any>, Record<string, any>>>
| Readonly<AxSignatureConfig>, options?: Readonly<AxProgramOptions>): AxProgram<IN, OUT>;

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

Parameters

ParameterType
signature| undefined | string | Readonly<AxSignature<Record<string, any>, Record<string, any>>> | Readonly<AxSignatureConfig>
options?Readonly<AxProgramOptions>

Returns

AxProgram<IN, OUT>

Methods

applyOptimization()

applyOptimization(optimizedProgram: AxOptimizedProgram<OUT>): void;

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

Parameters

ParameterType
optimizedProgramAxOptimizedProgram<OUT>

Returns

void

Implementation of

AxTunable.applyOptimization


getId()

getId(): string;

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

Returns

string

Implementation of

AxTunable.getId


getSignature()

getSignature(): AxSignature;

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

Returns

AxSignature


getTraces()

getTraces(): AxProgramTrace<IN, OUT>[];

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

Returns

AxProgramTrace<IN, OUT>[]

Implementation of

AxTunable.getTraces


getUsage()

getUsage(): AxModelUsage & object[];

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

Returns

AxModelUsage & object[]

Implementation of

AxUsable.getUsage


namedPrograms()

namedPrograms(): object[];

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

Returns all programs in the hierarchy with their IDs and signatures. Use this to discover the IDs needed for setDemos().

Equivalent to DSPy’s named_parameters().

Example

agent.setId('qa');
console.log(agent.namedPrograms());
// [
//   { id: 'qa.actor', signature: '... -> javascriptCode' },
//   { id: 'qa.responder', signature: '... -> answer' },
// ]

Returns

object[]


register()

register(prog: Readonly<AxTunable<IN, OUT> & AxUsable>, name?: string): void;

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

Parameters

ParameterType
progReadonly<AxTunable<IN, OUT> & AxUsable>
name?string

Returns

void


resetUsage()

resetUsage(): void;

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

Returns

void

Implementation of

AxUsable.resetUsage


setDemos()

setDemos(demos: readonly AxProgramDemos<IN, OUT>[], options?: object): void;

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

Parameters

ParameterType
demosreadonly AxProgramDemos<IN, OUT>[]
options?{ modelConfig?: Record<string, unknown>; }
options.modelConfig?Record<string, unknown>

Returns

void

Implementation of

AxTunable.setDemos


setDescription()

setDescription(description: string): void;

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

Parameters

ParameterType
descriptionstring

Returns

void


setExamples()

setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;

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

Parameters

ParameterType
examplesReadonly<AxProgramExamples<IN, OUT>>
options?Readonly<AxSetExamplesOptions>

Returns

void


setId()

setId(id: string): void;

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

Parameters

ParameterType
idstring

Returns

void

Implementation of

AxTunable.setId


setSignature()

setSignature(signature: 
  | string
  | Readonly<AxSignature<Record<string, any>, Record<string, any>>>
  | Readonly<AxSignatureConfig>): void;

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

Parameters

ParameterType
signature| string | Readonly<AxSignature<Record<string, any>, Record<string, any>>> | Readonly<AxSignatureConfig>

Returns

void