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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/dsp/optimizer.ts#L1195

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

Extended by

Type Parameters

Type ParameterDefault type
INany
OUT extends AxGenOutany

Implements

Constructors

Constructor

new AxBaseOptimizer<IN, OUT>(args: Readonly<AxOptimizerArgs>): AxBaseOptimizer<IN, OUT>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/dsp/optimizer.ts#L1240

Parameters

ParameterType
argsReadonly<AxOptimizerArgs>

Returns

AxBaseOptimizer<IN, OUT>

Methods

compile()

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

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/dsp/optimizer.ts#L1455

Abstract method that must be implemented by concrete optimizers

Parameters

ParameterType
programReadonly<AxGen<IN, OUT>>
metricFnAxMetricFn
options?AxCompileOptions

Returns

Promise<AxOptimizerResult<OUT>>

Implementation of

AxOptimizer.compile


compilePareto()

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

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/dsp/optimizer.ts#L1579

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

Parameters

ParameterTypeDescription
programReadonly<AxGen<IN, OUT>>The program to optimize
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(
   program: Readonly<AxGen<IN, OUT>>, 
   metricFn: AxMetricFn, 
options?: AxCompileOptions): AsyncIterableIterator<AxOptimizationProgress>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/dsp/optimizer.ts#L1468

Optimize a program with real-time streaming updates

Parameters

ParameterTypeDescription
programReadonly<AxGen<IN, OUT>>The program to optimize
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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/dsp/optimizer.ts#L2496

Reset optimizer state for reuse with different programs

Returns

void

Implementation of

AxOptimizer.reset