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

AxAgent

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L139

A split-architecture AI agent that uses two AxGen programs:

The execution loop is managed by TypeScript, not the LLM:

  1. Actor generates code → executed in runtime → result appended to actionLog
  2. Loop until Actor calls final(…) / ask_clarification(…) or maxTurns reached
  3. Responder synthesizes final answer from actorResult payload

Type Parameters

Type Parameter
IN extends AxGenIn
OUT extends AxGenOut

Implements

Constructors

Constructor

new AxAgent<IN, OUT>(__namedParameters: Readonly<{
  agentIdentity?: Readonly<{
     description: string;
     name: string;
  }>;
  agents?: AxAnyAgentic[];
  ai?: Readonly<AxAIService>;
  functions?: AxInputFunctionType;
  signature:   | string
     | Readonly<AxSignatureConfig>
     | Readonly<AxSignature<IN, OUT>>;
}>, options: Readonly<AxAgentOptions>): AxAgent<IN, OUT>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L164

Parameters

ParameterType
__namedParametersReadonly<{ agentIdentity?: Readonly<{ description: string; name: string; }>; agents?: AxAnyAgentic[]; ai?: Readonly<AxAIService>; functions?: AxInputFunctionType; signature: | string | Readonly<AxSignatureConfig> | Readonly<AxSignature<IN, OUT>>; }>
optionsReadonly<AxAgentOptions>

Returns

AxAgent<IN, OUT>

Methods

applyOptimization()

applyOptimization(optimizedProgram: any): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L502

Parameters

ParameterType
optimizedProgramany

Returns

void

Implementation of

AxAgentic.applyOptimization


forward()

forward<T>(
   parentAi: T, 
   values: IN | AxMessage<IN>[], 
options?: Readonly<AxProgramForwardOptionsWithModels<T>>): Promise<OUT>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L1120

Type Parameters

Type Parameter
T extends Readonly<AxAIService<unknown, unknown, string>>

Parameters

ParameterType
parentAiT
valuesIN | AxMessage<IN>[]
options?Readonly<AxProgramForwardOptionsWithModels<T>>

Returns

Promise<OUT>

Implementation of

AxAgentic.forward


getFunction()

getFunction(): AxFunction;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L451

Returns

AxFunction

Implementation of

AxAgentic.getFunction


getId()

getId(): string;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L420

Returns

string

Implementation of

AxAgentic.getId


getSignature()

getSignature(): AxSignature;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L492

Returns

AxSignature

Implementation of

AxAgentic.getSignature


getTraces()

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

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L432

Returns

AxProgramTrace<IN, OUT>[]

Implementation of

AxAgentic.getTraces


getUsage()

getUsage(): AxModelUsage & object[];

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L443

Returns

AxModelUsage & object[]

Implementation of

AxAgentic.getUsage


namedPrograms()

namedPrograms(): object[];

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L428

Returns

object[]


resetUsage()

resetUsage(): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L447

Returns

void

Implementation of

AxAgentic.resetUsage


setDemos()

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

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L436

Parameters

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

Returns

void

Implementation of

AxAgentic.setDemos


setId()

setId(id: string): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L424

Parameters

ParameterType
idstring

Returns

void

Implementation of

AxAgentic.setId


setSignature()

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

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L496

Parameters

ParameterType
signatureNonNullable< | undefined | Readonly< | string | AxSignatureConfig | AxSignature<Record<string, any>, Record<string, any>>>>

Returns

void


stop()

stop(): void;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L410

Stops an in-flight forward/streamingForward call. Causes the call to throw AxAIServiceAbortedError.

Returns

void


streamingForward()

streamingForward<T>(
   parentAi: T, 
   values: IN | AxMessage<IN>[], 
options?: Readonly<AxProgramStreamingForwardOptionsWithModels<T>>): AxGenStreamingOut<OUT>;

Defined in: https://github.com/ax-llm/ax/blob/71ea5064d766efdc031d375243a8e525911833e7/src/ax/prompts/agent.ts#L1169

Type Parameters

Type Parameter
T extends Readonly<AxAIService<unknown, unknown, string>>

Parameters

ParameterType
parentAiT
valuesIN | AxMessage<IN>[]
options?Readonly<AxProgramStreamingForwardOptionsWithModels<T>>

Returns

AxGenStreamingOut<OUT>

Implementation of

AxAgentic.streamingForward