AxLearn
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L147
AxLearn wraps an AxGen with automatic trace logging and self-improvement capabilities.
Example
const gen = ax(`question -> answer`);
// Create the learner with all configuration
const learner = new AxLearn(gen, {
name: 'math-bot',
teacher: gpt4o,
storage: new AxMemoryStorage(),
budget: 20
});
// Use in production
await learner.forward(ai, { question: 'What is 2+2?' });
// Run optimization (uses config from constructor)
await learner.optimize();
Type Parameters
| Type Parameter |
|---|
IN extends AxGenIn |
OUT extends AxGenOut |
Implements
AxForwardable<IN,OUT,string>AxUsable
Constructors
Constructor
new AxLearn<IN, OUT>(gen: AxGen<IN, OUT>, options: AxLearnOptions): AxLearn<IN, OUT>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L155
Parameters
| Parameter | Type |
|---|---|
gen | AxGen<IN, OUT> |
options | AxLearnOptions |
Returns
AxLearn<IN, OUT>
Methods
addAssert()
addAssert(fn: (values: OUT) =>
| undefined
| string
| boolean
| Promise<undefined | string | boolean>, message?: string): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L224
Parameters
| Parameter | Type |
|---|---|
fn | (values: OUT) => | undefined | string | boolean | Promise<undefined | string | boolean> |
message? | string |
Returns
void
addFeedback()
addFeedback(traceId: string, feedback: object): Promise<void>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L464
Add feedback to a specific trace.
Parameters
| Parameter | Type |
|---|---|
traceId | string |
feedback | { comment?: string; label?: string; score?: number; } |
feedback.comment? | string |
feedback.label? | string |
feedback.score? | number |
Returns
Promise<void>
addFieldProcessor()
addFieldProcessor(fieldName: keyof OUT, fn: (value: OUT[keyof OUT], context?: object) => unknown): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L236
Parameters
| Parameter | Type |
|---|---|
fieldName | keyof OUT |
fn | (value: OUT[keyof OUT], context?: object) => unknown |
Returns
void
addStreamingAssert()
addStreamingAssert(
fieldName: keyof OUT,
fn: (content: string, done?: boolean) => undefined | string | boolean,
message?: string): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L228
Parameters
| Parameter | Type |
|---|---|
fieldName | keyof OUT |
fn | (content: string, done?: boolean) => undefined | string | boolean |
message? | string |
Returns
void
addStreamingFieldProcessor()
addStreamingFieldProcessor(fieldName: keyof OUT, fn: (value: string, context?: object) => unknown): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L246
Parameters
| Parameter | Type |
|---|---|
fieldName | keyof OUT |
fn | (value: string, context?: object) => unknown |
Returns
void
clone()
clone(): AxLearn<IN, OUT>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L256
Returns
AxLearn<IN, OUT>
forward()
forward(
ai: AxAIService,
values: IN | AxMessage<IN>[],
options?: Readonly<AxProgramForwardOptions<string>>): Promise<OUT>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L174
Forward call - behaves exactly like AxGen.forward() but logs traces.
Parameters
| Parameter | Type |
|---|---|
ai | AxAIService |
values | IN | AxMessage<IN>[] |
options? | Readonly<AxProgramForwardOptions<string>> |
Returns
Promise<OUT>
Implementation of
getGen()
getGen(): AxGen<IN, OUT>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L437
Get the underlying AxGen instance.
Returns
AxGen<IN, OUT>
getInstruction()
getInstruction(): undefined | string;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L216
Returns
undefined | string
getSignature()
getSignature(): AxSignature;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L208
Returns
getStorage()
getStorage(): AxStorage;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L444
Get the storage backend.
Returns
getTraces()
getTraces(options?: object): Promise<AxTrace[]>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L451
Get recent traces for this agent.
Parameters
| Parameter | Type |
|---|---|
options? | { limit?: number; since?: Date; } |
options.limit? | number |
options.since? | Date |
Returns
Promise<AxTrace[]>
getUsage()
getUsage(): AxModelUsage & object[];
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L200
Returns
AxModelUsage & object[]
Implementation of
optimize()
optimize(overrides: Partial<Omit<AxLearnOptions, "id" | "storage" | "teacher">>): Promise<AxLearnResult<IN, OUT>>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L266
Optimize the agent using the configuration provided in constructor. Can optionally override options.
Parameters
| Parameter | Type |
|---|---|
overrides | Partial<Omit<AxLearnOptions, "id" | "storage" | "teacher">> |
Returns
Promise<AxLearnResult<IN, OUT>>
resetUsage()
resetUsage(): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L204
Returns
void
Implementation of
setInstruction()
setInstruction(instruction: string): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L212
Parameters
| Parameter | Type |
|---|---|
instruction | string |
Returns
void
streamingForward()
streamingForward(
ai: AxAIService,
values: IN | AxMessage<IN>[],
options?: Readonly<AxProgramForwardOptions<string>>): AxGenStreamingOut<OUT>;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L188
Streaming forward call - behaves exactly like AxGen.streamingForward() but logs traces.
Parameters
| Parameter | Type |
|---|---|
ai | AxAIService |
values | IN | AxMessage<IN>[] |
options? | Readonly<AxProgramForwardOptions<string>> |
Returns
AxGenStreamingOut<OUT>
Implementation of
AxForwardable.streamingForward
updateMeter()
updateMeter(meter?: Meter): void;
Defined in: https://github.com/ax-llm/ax/blob/242cf18d21de9f9d58c7c82f53305f0605497473/src/ax/dsp/learn.ts#L220
Parameters
| Parameter | Type |
|---|---|
meter? | Meter |
Returns
void