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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L178

An AI agent that can process inputs using an AI service and coordinate with child agents. Supports features like smart model routing and automatic input field passing to child agents.

Deprecated

Use the agent() factory function instead of instantiating this class directly. The factory function provides better type inference and cleaner syntax. This class will be removed in v15.0.0.

Migration timeline:

Example

// Old (deprecated):
const myAgent = new AxAgent({
  name: 'myAgent',
  description: 'An agent that does something',
  signature: 'userInput:string -> responseText:string'
});

// New (recommended):
const myAgent = agent('userInput:string -> responseText:string', {
  name: 'myAgent',
  description: 'An agent that does something'
});

Type Parameters

Type Parameter
IN extends AxGenIn
OUT extends AxGenOut

Implements

Constructors

Constructor

new AxAgent<IN, OUT>(__namedParameters: Readonly<{
  agents?: AxAgentic<IN, OUT>[];
  ai?: Readonly<AxAIService>;
  definition?: string;
  description: string;
  functions?: AxInputFunctionType;
  name: string;
  signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>;
}>, options?: Readonly<AxAgentOptions>): AxAgent<IN, OUT>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L193

Parameters

ParameterType
__namedParametersReadonly<{ agents?: AxAgentic<IN, OUT>[]; ai?: Readonly<AxAIService>; definition?: string; description: string; functions?: AxInputFunctionType; name: string; signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>; }>
options?Readonly<AxAgentOptions>

Returns

AxAgent<IN, OUT>

Methods

forward()

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

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L434

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


getFeatures()

getFeatures(): AxAgentFeatures;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L382

Returns

AxAgentFeatures

Implementation of

AxAgentic.getFeatures


getFunction()

getFunction(): AxFunction;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L342

Returns

AxFunction

Implementation of

AxAgentic.getFunction


getSignature()

getSignature(): AxSignature;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L485

Returns

AxSignature

Implementation of

AxAgentic.getSignature


getTraces()

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

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L326

Returns

AxProgramTrace<IN, OUT>[]

Implementation of

AxAgentic.getTraces


getUsage()

getUsage(): AxModelUsage & object[];

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L334

Returns

AxModelUsage & object[]

Implementation of

AxAgentic.getUsage


resetUsage()

resetUsage(): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L338

Returns

void

Implementation of

AxAgentic.resetUsage


setDefinition()

setDefinition(definition: string): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L476

Parameters

ParameterType
definitionstring

Returns

void


setDemos()

setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L330

Parameters

ParameterType
demosreadonly AxProgramDemos<IN, OUT>[]

Returns

void

Implementation of

AxAgentic.setDemos


setDescription()

setDescription(description: string): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L467

Updates the agent’s description. This updates both the stored description and the function’s description.

Parameters

ParameterTypeDescription
descriptionstringNew description for the agent (must be at least 20 characters)

Returns

void

Throws

Error if description is too short


setExamples()

setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L311

Parameters

ParameterType
examplesReadonly<AxProgramExamples<IN, OUT>>
options?Readonly<AxSetExamplesOptions>

Returns

void

Implementation of

AxAgentic.setExamples


setId()

setId(id: string): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L318

Parameters

ParameterType
idstring

Returns

void

Implementation of

AxAgentic.setId


setParentId()

setParentId(parentId: string): void;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L322

Parameters

ParameterType
parentIdstring

Returns

void

Implementation of

AxAgentic.setParentId


setSignature()

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

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L489

Parameters

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

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/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L447

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


create()

static create<T>(signature: T, config: AxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>): AxAgent<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/prompts/agent.ts#L286

Creates a new AxAgent instance with type-safe signature parsing. This is the recommended way to create agents with string-based signatures.

Example

const agent = AxAgent.create(
  'userInput:string "User question" -> responseText:string "Agent response"',
  {
    name: 'helpfulAgent',
    description: 'An agent that provides helpful responses to user questions',
    definition: 'You are a helpful assistant that provides clear, accurate responses to user questions.',
    ai: llm
  }
);

Type Parameters

Type Parameter
T extends string

Parameters

ParameterTypeDescription
signatureTThe signature string defining input/output fields
configAxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>Agent configuration including name, description, etc.

Returns

AxAgent<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>

A new AxAgent instance with inferred types