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

AxFlowDependencyAnalyzer

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

Analyzes mapping functions to extract state dependencies.

This class is crucial for the automatic parallelization feature of AxFlow. It determines which fields in the state object a mapping function accesses, which allows the execution planner to understand dependencies between steps and optimize execution by running independent steps in parallel.

The analyzer uses two complementary approaches:

  1. Static analysis of the function source code
  2. Dynamic proxy-based tracking as a fallback

This dual approach ensures robust dependency detection even for complex mapping functions that might use destructuring, computed property access, or other advanced JavaScript patterns.

Constructors

Constructor

new AxFlowDependencyAnalyzer(): AxFlowDependencyAnalyzer;

Returns

AxFlowDependencyAnalyzer

Methods

analyzeMappingDependencies()

analyzeMappingDependencies(mapping: (state: any) => any, _nodeName: string): string[];

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

Analyzes a mapping function to determine which state fields it depends on.

This method is called for every execute step to understand what data the step needs from the current state. This information is used to:

The analysis process:

  1. First tries static analysis by parsing the function source
  2. Falls back to proxy-based tracking for complex cases
  3. Returns a list of field names that the mapping function accesses

Example

// For a mapping like: state => ({ query: state.userInput, context: state.previousResult })
// This would return: ['userInput', 'previousResult']

Parameters

ParameterTypeDescription
mapping(state: any) => anyThe mapping function that transforms state to node inputs
_nodeNamestringThe name of the node (currently unused but kept for future use)

Returns

string[]

Array of field names that the mapping function depends on


createTrackingProxy()

createTrackingProxy(target: any, accessed: string[]): any;

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

Creates a tracking proxy for dependency analysis.

This is a public method that creates a proxy to track property access patterns. It’s used for testing and advanced dependency analysis scenarios.

Parameters

ParameterTypeDescription
targetanyThe target object to wrap with a proxy
accessedstring[]Array to collect accessed property names

Returns

any

Proxy object that tracks property access


parseStaticDependencies()

parseStaticDependencies(functionSource: string): string[];

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

Parses function source code to extract state dependencies using static analysis.

This method analyzes the source code of a function to find patterns like state.fieldName and extracts the field names as dependencies.

Parameters

ParameterTypeDescription
functionSourcestringThe source code of the function to analyze

Returns

string[]

Array of field names found in the source code