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

agent

Call Signature

function agent<T, CF>(signature: T, config: Omit<AxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>, "contextFields"> & object): AxAgent<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>;

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

Creates a strongly-typed AI agent from a signature. This is the recommended way to create agents, providing better type inference and cleaner syntax.

Example

const myAgent = agent('context:string, query:string -> answer:string', {
  contextFields: ['context'],
  runtime: new AxJSRuntime(),
});

Type Parameters

Type Parameter
T extends string
CF extends readonly string[]

Parameters

ParameterTypeDescription
signatureTThe input/output signature as a string or AxSignature object
configOmit<AxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>, "contextFields"> & objectConfiguration options for the agent (contextFields is required)

Returns

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

A typed agent instance

Call Signature

function agent<TInput, TOutput, CF>(signature: AxSignature<TInput, TOutput>, config: Omit<AxAgentConfig<TInput, TOutput>, "contextFields"> & object): AxAgent<TInput, TOutput>;

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

Creates a strongly-typed AI agent from a signature. This is the recommended way to create agents, providing better type inference and cleaner syntax.

Example

const myAgent = agent('context:string, query:string -> answer:string', {
  contextFields: ['context'],
  runtime: new AxJSRuntime(),
});

Type Parameters

Type Parameter
TInput extends Record<string, any>
TOutput extends Record<string, any>
CF extends readonly string[]

Parameters

ParameterTypeDescription
signatureAxSignature<TInput, TOutput>The input/output signature as a string or AxSignature object
configOmit<AxAgentConfig<TInput, TOutput>, "contextFields"> & objectConfiguration options for the agent (contextFields is required)

Returns

AxAgent<TInput, TOutput>

A typed agent instance