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

AxOptimizer

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

Methods

cancel()?

optional cancel(): Promise<void>;

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

Cancel ongoing optimization gracefully

Returns

Promise<void>

Promise that resolves when cancellation is complete


compile()

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#L919

Optimize a program using the provided metric function

Type Parameters

Type Parameter
IN
OUT extends AxGenOut

Parameters

ParameterTypeDescription
programReadonly<AxGen<IN, OUT>>The program to optimize
examplesreadonly AxTypedExample<IN>[]Training examples (typed based on the program) - will be auto-split into train/validation
metricFnAxMetricFnEvaluation metric function to assess program performance
options?AxCompileOptionsOptional configuration options

Returns

Promise<AxOptimizerResult<OUT>>

Optimization result containing demos, stats, and configuration


compilePareto()?

optional 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#L949

Multi-objective optimization using Pareto frontier

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
options?AxCompileOptionsOptional configuration options

Returns

Promise<AxParetoResult<OUT>>

Pareto optimization result


compileStream()?

optional 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#L934

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


getConfiguration()?

optional getConfiguration(): Record<string, unknown>;

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

Get optimizer-specific configuration

Returns

Record<string, unknown>

Current optimizer configuration


getStats()

getStats(): AxOptimizationStats;

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

Get current optimization statistics

Returns

AxOptimizationStats

Current optimization statistics


reset()?

optional reset(): void;

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

Reset optimizer state for reuse with different programs

Returns

void


updateConfiguration()?

optional updateConfiguration(config: Readonly<Record<string, unknown>>): void;

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

Update optimizer configuration

Parameters

ParameterTypeDescription
configReadonly<Record<string, unknown>>New configuration to merge with existing

Returns

void


validateProgram()?

optional validateProgram<IN, OUT>(program: Readonly<AxGen<IN, OUT>>): object;

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

Validate that the optimizer can handle the given program

Type Parameters

Type Parameter
IN
OUT extends AxGenOut

Parameters

ParameterTypeDescription
programReadonly<AxGen<IN, OUT>>Program to validate

Returns

object

Validation result with any issues found

NameType
issuesstring[]
isValidboolean
suggestionsstring[]