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

AxBaseOptimizer

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L1116

Abstract base class for optimizers that provides common functionality and standardized handling of AxOptimizerArgs

Extended by

Implements

Constructors

Constructor

new AxBaseOptimizer(args: Readonly<AxOptimizerArgs>): AxBaseOptimizer;

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L1161

Parameters

ParameterType
argsReadonly<AxOptimizerArgs>

Returns

AxBaseOptimizer

Methods

compile()

abstract compile<IN, OUT>(
   program: Readonly<AxGen<IN, OUT>>, 
   examples: readonly AxTypedExample<IN>[], 
   metricFn: AxMetricFn, 
options?: AxCompileOptions): Promise<AxOptimizerResult<OUT>>;

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L1431

Abstract method that must be implemented by concrete optimizers

Type Parameters

Type Parameter
IN
OUT extends AxGenOut

Parameters

ParameterType
programReadonly<AxGen<IN, OUT>>
examplesreadonly AxTypedExample<IN>[]
metricFnAxMetricFn
options?AxCompileOptions

Returns

Promise<AxOptimizerResult<OUT>>

Implementation of

AxOptimizer.compile


compilePareto()

compilePareto<IN, OUT>(
   program: Readonly<AxGen<IN, OUT>>, 
   examples: readonly AxTypedExample<IN>[], 
   metricFn: AxMultiMetricFn, 
options?: AxCompileOptions): Promise<AxParetoResult<OUT>>;

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L1559

Multi-objective optimization using Pareto frontier Default implementation that leverages the single-objective compile method

Type Parameters

Type Parameter
IN
OUT extends AxGenOut

Parameters

ParameterTypeDescription
programReadonly<AxGen<IN, OUT>>The program to optimize
examplesreadonly AxTypedExample<IN>[]Training examples
metricFnAxMultiMetricFnMulti-objective metric function that returns multiple scores
options?AxCompileOptionsOptional configuration options

Returns

Promise<AxParetoResult<OUT>>

Pareto optimization result with frontier of non-dominated solutions

Implementation of

AxOptimizer.compilePareto


compileStream()

compileStream<IN, OUT>(
   program: Readonly<AxGen<IN, OUT>>, 
   examples: readonly AxTypedExample<IN>[], 
   metricFn: AxMetricFn, 
options?: AxCompileOptions): AsyncIterableIterator<AxOptimizationProgress>;

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L1446

Optimize a program with real-time streaming updates

Type Parameters

Type Parameter
IN
OUT extends AxGenOut

Parameters

ParameterTypeDescription
programReadonly<AxGen<IN, OUT>>The program to optimize
examplesreadonly AxTypedExample<IN>[]Training examples
metricFnAxMetricFnEvaluation metric function
options?AxCompileOptionsOptional configuration options

Returns

AsyncIterableIterator<AxOptimizationProgress>

Async iterator yielding optimization progress

Implementation of

AxOptimizer.compileStream


getStats()

getStats(): AxOptimizationStats;

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L2492

Get current optimization statistics

Returns

AxOptimizationStats

Current optimization statistics

Implementation of

AxOptimizer.getStats


reset()

reset(): void;

Defined in: https://github.com/ax-llm/ax/blob/8dfd0ce02b8cb386fb2c93fa280a2ec0da2d6011/src/ax/dsp/optimizer.ts#L2605

Reset optimizer state for reuse with different programs

Returns

void

Implementation of

AxOptimizer.reset