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

flow

function flow<TInput, TOutput>(options?: object): AxFlow<TInput, TOutput, {
}, TInput>;

Defined in: https://github.com/ax-llm/ax/blob/9a5a7060a48f9eef46efc680b0cdf6b42bff5df2/src/ax/flow/flow.ts#L2537

Creates a new AxFlow instance with required input type specification.

The input type must be specified upfront to enable proper type inference throughout the flow construction and execution.

Example

// ✅ Define input type upfront for better type safety
const workflow = flow<{ userInput: string, options?: any }>()
  .map(state => ({ ...state, processedInput: state.userInput.toUpperCase() }))
  .node('analyzer', 'processedInput:string -> result:string')

// ✅ Simple input types work too
const simpleFlow = flow<{ documentText: string }>()
  .node('summarizer', 'documentText:string -> summary:string')

Type Parameters

Type ParameterDefault type
TInput extends Record<string, any>-
TOutputobject

Parameters

ParameterType
options?{ autoParallel?: boolean; batchSize?: number; debug?: boolean; logger?: AxFlowLoggerFunction; }
options.autoParallel?boolean
options.batchSize?number
options.debug?boolean
options.logger?AxFlowLoggerFunction

Returns

AxFlow<TInput, TOutput, { }, TInput>