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

AxTraceLogger

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L68

AxTraceLogger wraps an AxGen instance to automatically log all forward() calls.

Example

const gen = ax(`query -> response`);
const storage = new AxMemoryStorage();

const tracedGen = new AxTraceLogger(gen, {
  agentId: 'my-agent',
  storage,
});

// Use exactly like AxGen
const result = await tracedGen.forward(ai, { query: 'Hello' });

// Traces are automatically saved to storage
const traces = await storage.getTraces('my-agent');

Type Parameters

Type Parameter
IN extends AxGenIn
OUT extends AxGenOut

Constructors

Constructor

new AxTraceLogger<IN, OUT>(gen: AxGen<IN, OUT>, options: AxTraceLoggerOptions): AxTraceLogger<IN, OUT>;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L78

Parameters

ParameterType
genAxGen<IN, OUT>
optionsAxTraceLoggerOptions

Returns

AxTraceLogger<IN, OUT>

Methods

clone()

clone(newGen?: AxGen<IN, OUT>): AxTraceLogger<IN, OUT>;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L246

Clone the logger with a new underlying AxGen.

Parameters

ParameterType
newGen?AxGen<IN, OUT>

Returns

AxTraceLogger<IN, OUT>


forward()

forward(
   ai: AxAIService, 
   values: IN | AxMessage<IN>[], 
options?: Readonly<AxProgramForwardOptions<string>>): Promise<OUT>;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L151

Forward call to the underlying AxGen with trace logging.

Parameters

ParameterType
aiAxAIService
valuesIN | AxMessage<IN>[]
options?Readonly<AxProgramForwardOptions<string>>

Returns

Promise<OUT>


getGen()

getGen(): AxGen<IN, OUT>;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L218

Get the underlying AxGen instance.

Returns

AxGen<IN, OUT>


getName()

getName(): string;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L225

Get the agent ID.

Returns

string


getStorage()

getStorage(): AxStorage;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L232

Get the storage backend.

Returns

AxStorage


setMetadata()

setMetadata(metadata: Record<string, unknown>): void;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L239

Update the metadata for future traces.

Parameters

ParameterType
metadataRecord<string, unknown>

Returns

void


streamingForward()

streamingForward(
   ai: AxAIService, 
   values: IN | AxMessage<IN>[], 
options?: Readonly<AxProgramForwardOptions<string>>): AxGenStreamingOut<OUT>;

Defined in: https://github.com/ax-llm/ax/blob/a8847bd2906efff202fde10d776fddd20fd2ff57/src/ax/trace/logger.ts#L94

Streaming forward call to the underlying AxGen with trace logging.

Parameters

ParameterType
aiAxAIService
valuesIN | AxMessage<IN>[]
options?Readonly<AxProgramForwardOptions<string>>

Returns

AxGenStreamingOut<OUT>