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

function agent<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#L661

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

Example

const myAgent = agent('userInput:string -> responseText:string', {
  name: 'myAgent',
  description: 'An agent that processes user input and returns a response',
  definition: 'You are a helpful assistant that responds to user queries...'
});

// With child agents
const parentAgent = agent('taskDescription:string -> completedTask:string', {
  name: 'parentAgent',
  description: 'Coordinates child agents to complete tasks',
  agents: [childAgent1, childAgent2]
});

// Type-safe usage
const result = await myAgent.forward(ai, { userInput: 'Hello!' });
console.log(result.responseText); // TypeScript knows this exists

Type Parameters

Type Parameter
T extends string

Parameters

ParameterTypeDescription
signatureTThe input/output signature as a string (e.g., “userInput:string -> responseText:string”)
configAxAgentConfig<ParseSignature<T>["inputs"], ParseSignature<T>["outputs"]>Configuration options for the agent

Returns

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

A typed agent instance