@launchdarkly/server-sdk-ai 0.20.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -21,6 +21,20 @@ interface LDJudgeResult {
21
21
  reasoning?: string;
22
22
  }
23
23
 
24
+ /**
25
+ * Feedback about the generated content.
26
+ */
27
+ declare enum LDFeedbackKind {
28
+ /**
29
+ * The sentiment was positive.
30
+ */
31
+ Positive = "positive",
32
+ /**
33
+ * The sentiment is negative.
34
+ */
35
+ Negative = "negative"
36
+ }
37
+
24
38
  /**
25
39
  * Information about token usage.
26
40
  */
@@ -39,32 +53,6 @@ interface LDTokenUsage {
39
53
  output: number;
40
54
  }
41
55
 
42
- declare function createBedrockTokenUsage(data: {
43
- totalTokens?: number;
44
- inputTokens?: number;
45
- outputTokens?: number;
46
- }): LDTokenUsage;
47
-
48
- declare function createOpenAiUsage(data: {
49
- total_tokens?: number;
50
- prompt_tokens?: number;
51
- completion_tokens?: number;
52
- }): LDTokenUsage;
53
-
54
- /**
55
- * Feedback about the generated content.
56
- */
57
- declare enum LDFeedbackKind {
58
- /**
59
- * The sentiment was positive.
60
- */
61
- Positive = "positive",
62
- /**
63
- * The sentiment is negative.
64
- */
65
- Negative = "negative"
66
- }
67
-
68
56
  /**
69
57
  * Metrics information for AI operations that includes success status and token usage.
70
58
  * This class combines success/failure tracking with token usage metrics.
@@ -91,14 +79,6 @@ interface LDAIMetrics {
91
79
  durationMs?: number;
92
80
  }
93
81
 
94
- declare function createVercelAISDKTokenUsage(data: {
95
- totalTokens?: number;
96
- inputTokens?: number;
97
- promptTokens?: number;
98
- outputTokens?: number;
99
- completionTokens?: number;
100
- }): LDTokenUsage;
101
-
102
82
  /**
103
83
  * Summary metrics returned in a ManagedResult or from LDAIConfigTracker.getSummary().
104
84
  * Provides a flat view of the key metrics for the completed operation.
@@ -189,7 +169,13 @@ interface ManagedResult {
189
169
  }
190
170
 
191
171
  /**
192
- * The LDAIConfigTracker is used to track various details about AI operations.
172
+ * The LDAIConfigTracker records metrics for a single AI run.
173
+ *
174
+ * All events a tracker emits share a runId (a UUIDv4) so LaunchDarkly can
175
+ * correlate them in metrics views. See individual track methods for their
176
+ * specific semantics. Call `createTracker` on the AI Config to start a new
177
+ * run. A resumption token preserves the runId, so events emitted by a
178
+ * tracker reconstructed in another process correlate with the original run.
193
179
  */
194
180
  interface LDAIConfigTracker {
195
181
  /**
@@ -208,51 +194,49 @@ interface LDAIConfigTracker {
208
194
  * A URL-safe Base64-encoded token that encodes the tracker's runId, configKey,
209
195
  * variationKey, and version. Pass this to AIClient.createTracker() to reconstruct
210
196
  * the tracker across process boundaries (e.g. for associating deferred feedback
211
- * with the original invocation).
197
+ * with the original AI run).
212
198
  */
213
199
  readonly resumptionToken: string;
214
200
  /**
215
201
  * Track the duration of generation.
216
202
  *
217
- * At-most-once per execution: subsequent calls on the same tracker are dropped
218
- * with a warning. Use createTracker() on the config result to obtain a fresh
219
- * tracker for a new execution.
220
- *
221
203
  * Ideally this would not include overhead time such as network communication.
222
204
  *
223
205
  * @param durationMs The duration in milliseconds.
206
+ *
207
+ * @remarks Records at most once per Tracker; further calls are ignored.
224
208
  */
225
209
  trackDuration(durationMs: number): void;
226
210
  /**
227
211
  * Track information about token usage.
228
212
  *
229
- * At-most-once per execution: subsequent calls on the same tracker are dropped
230
- * with a warning.
231
- *
232
213
  * @param tokens Token usage information.
214
+ *
215
+ * @remarks Records at most once per Tracker; further calls are ignored.
233
216
  */
234
217
  trackTokens(tokens: LDTokenUsage): void;
235
218
  /**
236
219
  * Generation was successful.
237
220
  *
238
- * At-most-once per execution: subsequent calls (including trackError) on the
239
- * same tracker are dropped with a warning.
221
+ * @remarks Records at most once per Tracker. trackSuccess and trackError share
222
+ * state; only one of the two can record per Tracker, and subsequent calls are
223
+ * ignored.
240
224
  */
241
225
  trackSuccess(): void;
242
226
  /**
243
227
  * An error was encountered during generation.
244
228
  *
245
- * At-most-once per execution: subsequent calls (including trackSuccess) on the
246
- * same tracker are dropped with a warning.
229
+ * @remarks Records at most once per Tracker. trackSuccess and trackError share
230
+ * state; only one of the two can record per Tracker, and subsequent calls are
231
+ * ignored.
247
232
  */
248
233
  trackError(): void;
249
234
  /**
250
235
  * Track sentiment about the generation.
251
236
  *
252
- * At-most-once per execution: subsequent calls on the same tracker are dropped
253
- * with a warning.
254
- *
255
237
  * @param feedback Feedback about the generation.
238
+ *
239
+ * @remarks Records at most once per Tracker; further calls are ignored.
256
240
  */
257
241
  trackFeedback(feedback: {
258
242
  kind: LDFeedbackKind;
@@ -260,10 +244,9 @@ interface LDAIConfigTracker {
260
244
  /**
261
245
  * Track the time to first token for this generation.
262
246
  *
263
- * At-most-once per execution: subsequent calls on the same tracker are dropped
264
- * with a warning.
265
- *
266
247
  * @param timeToFirstTokenMs The duration in milliseconds.
248
+ *
249
+ * @remarks Records at most once per Tracker; further calls are ignored.
267
250
  */
268
251
  trackTimeToFirstToken(timeToFirstTokenMs: number): void;
269
252
  /**
@@ -272,22 +255,31 @@ interface LDAIConfigTracker {
272
255
  * No event is emitted when the result was not sampled (result.sampled is false).
273
256
  *
274
257
  * @param result Judge result containing score, reasoning, and metadata
258
+ *
259
+ * @remarks May be called multiple times per Tracker; each call records the
260
+ * scores from the given response.
275
261
  */
276
262
  trackJudgeResult(result: LDJudgeResult): void;
277
263
  /**
278
264
  * Track a single tool invocation.
279
265
  *
280
266
  * @param toolKey The identifier of the tool that was invoked.
267
+ *
268
+ * @remarks May be called multiple times per Tracker; each call records the
269
+ * given tool call.
281
270
  */
282
271
  trackToolCall(toolKey: string): void;
283
272
  /**
284
273
  * Track multiple tool invocations.
285
274
  *
286
275
  * @param toolKeys The identifiers of the tools that were invoked.
276
+ *
277
+ * @remarks May be called multiple times per Tracker; each call records the
278
+ * given tool calls.
287
279
  */
288
280
  trackToolCalls(toolKeys: string[]): void;
289
281
  /**
290
- * Track the duration of execution of the provided function.
282
+ * Track the duration of the provided function.
291
283
  *
292
284
  * If the provided function throws, then this method will also throw.
293
285
  * In the case the provided function throws, this function will still record the duration.
@@ -296,30 +288,38 @@ interface LDAIConfigTracker {
296
288
  *
297
289
  * @param func The function to track the duration of.
298
290
  * @returns The result of the function.
291
+ *
292
+ * @remarks Because each inner metric is at-most-once per Tracker, calling
293
+ * this twice on the same Tracker will run the inner function again but
294
+ * produce no additional metric events.
299
295
  */
300
296
  trackDurationOf(func: () => Promise<any>): Promise<any>;
301
297
  /**
302
298
  * Track metrics for a generic AI operation.
303
299
  *
304
- * This function will track the duration of the operation, extract metrics using the provided
300
+ * This function will track the duration of the AI run, extract metrics using the provided
305
301
  * metrics extractor function, and track success or error status accordingly.
306
302
  *
307
303
  * If the provided function throws, then this method will also throw.
308
304
  * In the case the provided function throws, this function will record the duration and an error.
309
- * A failed operation will not have any token usage data.
305
+ * A failed AI run will not have any token usage data.
306
+ *
307
+ * @param metricsExtractor Function that extracts LDAIMetrics from the AI run result
308
+ * @param func Function which executes the AI run
309
+ * @returns The result of the AI run
310
310
  *
311
- * @param metricsExtractor Function that extracts LDAIMetrics from the operation result
312
- * @param func Function which executes the operation
313
- * @returns The result of the operation
311
+ * @remarks Subsequent calls re-run the inner function but emit only metrics
312
+ * not already recorded on this Tracker. Call createTracker on the AI Config
313
+ * to start a new run.
314
314
  */
315
315
  trackMetricsOf<TRes>(metricsExtractor: (result: TRes) => LDAIMetrics, func: () => Promise<TRes>): Promise<TRes>;
316
316
  /**
317
317
  * Track metrics for a streaming AI operation.
318
318
  *
319
- * This function will track the duration of the operation, extract metrics using the provided
319
+ * This function will track the duration of the AI run, extract metrics using the provided
320
320
  * metrics extractor function, and track success or error status accordingly.
321
321
  *
322
- * Unlike trackMetricsOf, this method is designed for streaming operations where:
322
+ * Unlike trackMetricsOf, this method is designed for streaming AI runs where:
323
323
  * - The stream is created and returned immediately (synchronously)
324
324
  * - Metrics are extracted asynchronously in the background once the stream completes
325
325
  * - Duration is tracked from stream creation to metrics extraction completion
@@ -333,69 +333,12 @@ interface LDAIConfigTracker {
333
333
  * @param streamCreator Function that creates and returns the stream (synchronous)
334
334
  * @param metricsExtractor Function that asynchronously extracts metrics from the stream
335
335
  * @returns The stream result (returned immediately, not a Promise)
336
- */
337
- trackStreamMetricsOf<TStream>(streamCreator: () => TStream, metricsExtractor: (stream: TStream) => Promise<LDAIMetrics>): TStream;
338
- /**
339
- * Track an OpenAI operation.
340
- *
341
- * This function will track the duration of the operation, the token usage, and the success or error status.
342
336
  *
343
- * If the provided function throws, then this method will also throw.
344
- * In the case the provided function throws, this function will record the duration and an error.
345
- * A failed operation will not have any token usage data.
346
- *
347
- * @param func Function which executes the operation.
348
- * @returns The result of the operation.
337
+ * @remarks Subsequent calls re-run the inner function but emit only metrics
338
+ * not already recorded on this Tracker. Call createTracker on the AI Config
339
+ * to start a new run.
349
340
  */
350
- trackOpenAIMetrics<TRes extends {
351
- usage?: {
352
- total_tokens?: number;
353
- prompt_tokens?: number;
354
- completion_tokens?: number;
355
- };
356
- }>(func: () => Promise<TRes>): Promise<TRes>;
357
- /**
358
- * Track an operation which uses Bedrock.
359
- *
360
- * This function will track the duration of the operation, the token usage, and the success or error status.
361
- *
362
- * @param res The result of the Bedrock operation.
363
- * @returns The input operation.
364
- */
365
- trackBedrockConverseMetrics<TRes extends {
366
- $metadata: {
367
- httpStatusCode?: number;
368
- };
369
- metrics?: {
370
- latencyMs?: number;
371
- };
372
- usage?: {
373
- inputTokens?: number;
374
- outputTokens?: number;
375
- totalTokens?: number;
376
- };
377
- }>(res: TRes): TRes;
378
- /**
379
- * Track a Vercel AI SDK generateText operation.
380
- *
381
- * This function will track the duration of the operation, the token usage, and the success or error status.
382
- *
383
- * If the provided function throws, then this method will also throw.
384
- * In the case the provided function throws, this function will record the duration and an error.
385
- * A failed operation will not have any token usage data.
386
- *
387
- * @param func Function which executes the operation.
388
- * @returns The result of the operation.
389
- */
390
- trackVercelAISDKGenerateTextMetrics<TRes extends {
391
- usage?: {
392
- totalTokens?: number;
393
- inputTokens?: number;
394
- promptTokens?: number;
395
- outputTokens?: number;
396
- completionTokens?: number;
397
- };
398
- }>(func: () => Promise<TRes>): Promise<TRes>;
341
+ trackStreamMetricsOf<TStream>(streamCreator: () => TStream, metricsExtractor: (stream: TStream) => Promise<LDAIMetrics>): TStream;
399
342
  /**
400
343
  * Get a summary of the tracked metrics.
401
344
  */
@@ -503,9 +446,10 @@ interface LDAIConfig extends Omit<LDAIConfigDefault, 'enabled'> {
503
446
  */
504
447
  enabled: boolean;
505
448
  /**
506
- * Creates a new tracker for this AI Config invocation. Each call returns a
507
- * new tracker with a fresh runId. Use createTracker() at the start of each
508
- * execution to obtain a tracker, then use it to record metrics for that run.
449
+ * Creates a new tracker for a fresh AI run. Each call mints a new runId (a
450
+ * UUIDv4) that LaunchDarkly uses to correlate the run's events in metrics
451
+ * views. Call this once per AI run; metrics from different runIds cannot be
452
+ * combined.
509
453
  */
510
454
  createTracker: () => LDAIConfigTracker;
511
455
  }
@@ -562,12 +506,6 @@ interface LDAIJudgeConfigDefault extends LDAIConfigDefault {
562
506
  * The key of the metric that this judge can evaluate.
563
507
  */
564
508
  evaluationMetricKey?: string;
565
- /**
566
- * Evaluation metric keys for judge configurations (legacy).
567
- * The keys of the metrics that this judge can evaluate.
568
- * @deprecated Use evaluationMetricKey instead. This field is kept for legacy support.
569
- */
570
- evaluationMetricKeys?: string[];
571
509
  }
572
510
  /**
573
511
  * Union type for all default AI Config variants.
@@ -626,12 +564,6 @@ interface LDAIJudgeConfig extends LDAIConfig {
626
564
  * The key of the metric that this judge can evaluate.
627
565
  */
628
566
  evaluationMetricKey?: string;
629
- /**
630
- * Evaluation metric keys for judge configurations (legacy).
631
- * The keys of the metrics that this judge can evaluate.
632
- * @deprecated Use evaluationMetricKey instead. This field is kept for legacy support.
633
- */
634
- evaluationMetricKeys?: string[];
635
567
  }
636
568
  /**
637
569
  * Union type for all AI Config variants.
@@ -912,7 +844,13 @@ declare class ManagedModel {
912
844
  }
913
845
 
914
846
  /**
915
- * Tracks graph-level and edge-level metrics for an agent graph invocation.
847
+ * The LDGraphTracker records metrics for a single AI run of an agent graph.
848
+ *
849
+ * All events a graph tracker emits share a runId (a UUIDv4) so LaunchDarkly
850
+ * can correlate them in metrics views. Call `createTracker` on the agent
851
+ * graph to start a new run. A resumption token preserves the runId, so events
852
+ * emitted by a tracker reconstructed in another process correlate with the
853
+ * original run.
916
854
  *
917
855
  * Graph-level methods enforce at-most-once semantics: calling the same method
918
856
  * twice on a tracker instance drops the second call and emits a warning.
@@ -944,7 +882,7 @@ interface LDGraphTracker {
944
882
  /**
945
883
  * Returns a snapshot of all graph-level metrics tracked so far. Fields
946
884
  * populate incrementally as `track*` methods are called, so the result is
947
- * a `Partial<LDAIGraphMetricSummary>`. Once the graph invocation has
885
+ * a `Partial<LDAIGraphMetricSummary>`. Once the graph run has
948
886
  * completed via `ManagedAgentGraph.run()`, prefer `ManagedGraphResult.metrics`
949
887
  * which is fully populated.
950
888
  */
@@ -960,19 +898,19 @@ interface LDGraphTracker {
960
898
  */
961
899
  readonly resumptionToken: string;
962
900
  /**
963
- * Tracks a successful graph invocation.
901
+ * Tracks a successful graph run.
964
902
  * Emits event `$ld:ai:graph:invocation_success` with metric value `1`.
965
903
  * At-most-once: subsequent calls are dropped with a warning.
966
904
  */
967
905
  trackInvocationSuccess(): void;
968
906
  /**
969
- * Tracks an unsuccessful graph invocation.
907
+ * Tracks an unsuccessful graph run.
970
908
  * Emits event `$ld:ai:graph:invocation_failure` with metric value `1`.
971
909
  * At-most-once: subsequent calls are dropped with a warning.
972
910
  */
973
911
  trackInvocationFailure(): void;
974
912
  /**
975
- * Tracks the total duration of the graph execution in milliseconds.
913
+ * Tracks the total duration of the graph run in milliseconds.
976
914
  * Emits event `$ld:ai:graph:duration:total` with the duration as the metric value.
977
915
  * At-most-once: subsequent calls are dropped with a warning.
978
916
  *
@@ -980,7 +918,7 @@ interface LDGraphTracker {
980
918
  */
981
919
  trackDuration(durationMs: number): void;
982
920
  /**
983
- * Tracks aggregate token usage across the entire graph invocation.
921
+ * Tracks aggregate token usage across the entire graph run.
984
922
  * Emits event `$ld:ai:graph:total_tokens` with the total token count as the metric value.
985
923
  * At-most-once: subsequent calls are dropped with a warning.
986
924
  *
@@ -988,12 +926,12 @@ interface LDGraphTracker {
988
926
  */
989
927
  trackTotalTokens(tokens: LDTokenUsage): void;
990
928
  /**
991
- * Tracks the execution path through the graph.
929
+ * Tracks the path taken through the graph during this run.
992
930
  * Emits event `$ld:ai:graph:path` with metric value `1`.
993
931
  * The data payload includes the path array in addition to standard track data.
994
932
  * At-most-once: subsequent calls are dropped with a warning.
995
933
  *
996
- * @param path An ordered array of agent config keys representing the execution path.
934
+ * @param path An ordered array of agent config keys representing the path taken.
997
935
  */
998
936
  trackPath(path: string[]): void;
999
937
  /**
@@ -1112,10 +1050,10 @@ declare class AgentGraphDefinition {
1112
1050
  */
1113
1051
  getConfig(): LDAgentGraphFlagValue;
1114
1052
  /**
1115
- * Returns a new {@link LDGraphTracker} for this graph invocation.
1053
+ * Returns a new {@link LDGraphTracker} for a fresh graph run.
1116
1054
  *
1117
- * Call this once per invocation. Each call produces a tracker with a fresh `runId`
1118
- * that groups all events for that invocation.
1055
+ * Call this once per graph run. Each call produces a tracker with a fresh `runId`
1056
+ * that groups all events for that run.
1119
1057
  */
1120
1058
  createTracker(): LDGraphTracker;
1121
1059
  /**
@@ -1161,61 +1099,6 @@ declare class AgentGraphDefinition {
1161
1099
  static collectAllKeys(graph: LDAgentGraphFlagValue): Set<string>;
1162
1100
  }
1163
1101
 
1164
- /**
1165
- * ManagedAgentGraph wraps an AgentGraphDefinition and provides a managed run()
1166
- * method that returns ManagedGraphResult with async judge evaluations.
1167
- *
1168
- * The runner function is responsible for executing the graph and returning
1169
- * an AgentGraphRunnerResult. ManagedAgentGraph builds the managed result from
1170
- * the runner result, including LDAIGraphMetricSummary with the graphTracker's
1171
- * resumptionToken.
1172
- */
1173
- declare class ManagedAgentGraph {
1174
- private readonly _graphDefinition;
1175
- private readonly _logger?;
1176
- constructor(_graphDefinition: AgentGraphDefinition, _logger?: LDLogger$1 | undefined);
1177
- /**
1178
- * Runs the agent graph using the provided runner function and returns a ManagedGraphResult.
1179
- *
1180
- * The runner function receives the graph tracker and AgentGraphDefinition,
1181
- * executes the graph, and returns an AgentGraphRunnerResult.
1182
- *
1183
- * run() returns before ManagedGraphResult.evaluations resolves.
1184
- *
1185
- * @param runner Async function that executes the graph and returns AgentGraphRunnerResult.
1186
- * @returns ManagedGraphResult with LDAIGraphMetricSummary and evaluations promise.
1187
- */
1188
- run(runner: (graphDefinition: AgentGraphDefinition, graphTracker: LDGraphTracker) => Promise<AgentGraphRunnerResult>): Promise<ManagedGraphResult>;
1189
- /**
1190
- * Converts per-node LDAIMetrics from the runner into LDAIMetricSummary by
1191
- * creating a per-node tracker, firing tracking events, and calling getSummary().
1192
- */
1193
- private _trackNodeMetrics;
1194
- /**
1195
- * Returns the underlying AgentGraphDefinition.
1196
- */
1197
- getGraphDefinition(): AgentGraphDefinition;
1198
- }
1199
-
1200
- /**
1201
- * Chat response structure.
1202
- */
1203
- interface ChatResponse {
1204
- /**
1205
- * The response message from the AI.
1206
- */
1207
- message: LDMessage;
1208
- /**
1209
- * Metrics information including success status and token usage.
1210
- */
1211
- metrics: LDAIMetrics;
1212
- /**
1213
- * Promise that resolves to judge evaluation results.
1214
- * Only present when judges are configured for evaluation.
1215
- */
1216
- evaluations?: Promise<LDJudgeResult[]>;
1217
- }
1218
-
1219
1102
  /**
1220
1103
  * Judge implementation that handles evaluation functionality and conversation management.
1221
1104
  *
@@ -1234,8 +1117,7 @@ declare class Judge {
1234
1117
  */
1235
1118
  get sampleRate(): number;
1236
1119
  /**
1237
- * Gets the evaluation metric key, prioritizing evaluationMetricKey over evaluationMetricKeys.
1238
- * Falls back to the first valid (non-empty, non-whitespace) value in evaluationMetricKeys if evaluationMetricKey is not provided.
1120
+ * Gets the evaluation metric key from the judge AI config.
1239
1121
  * Treats empty strings and whitespace-only strings as invalid.
1240
1122
  * @returns The evaluation metric key, or undefined if not available
1241
1123
  */
@@ -1252,15 +1134,19 @@ declare class Judge {
1252
1134
  */
1253
1135
  evaluate(input: string, output: string, samplingRate?: number): Promise<LDJudgeResult>;
1254
1136
  /**
1255
- * Evaluates an AI response from chat messages and response.
1137
+ * Evaluates an AI response from chat messages and a runner result.
1138
+ *
1139
+ * Each message is rendered as `<role>: <content>` so the judge model can
1140
+ * distinguish speakers in the message history. Messages are joined with a
1141
+ * single newline.
1256
1142
  *
1257
1143
  * @param messages Array of messages representing the conversation history
1258
- * @param response The AI response to be evaluated
1144
+ * @param response The runner result containing the AI-generated content to evaluate
1259
1145
  * @param samplingRatio Sampling ratio (0-1). When omitted, the Judge's
1260
1146
  * constructor-default rate is used.
1261
1147
  * @returns Promise that resolves to evaluation results
1262
1148
  */
1263
- evaluateMessages(messages: LDMessage[], response: ChatResponse, samplingRatio?: number): Promise<LDJudgeResult>;
1149
+ evaluateMessages(messages: LDMessage[], response: RunnerResult, samplingRatio?: number): Promise<LDJudgeResult>;
1264
1150
  /**
1265
1151
  * Returns the AI Config used by this judge.
1266
1152
  */
@@ -1312,10 +1198,14 @@ declare abstract class AIProvider {
1312
1198
  * Default implementation returns `undefined`.
1313
1199
  *
1314
1200
  * @param config The completion or judge AI configuration.
1201
+ * @param multiTurn Whether the runner should accumulate conversation history
1202
+ * across successive `run()` calls. Defaults to `true` (chat semantics).
1203
+ * Pass `false` for stateless runners such as judges where each call must
1204
+ * start from the initial config messages.
1315
1205
  * @returns Promise resolving to a {@link Runner}, or `undefined` if this
1316
1206
  * provider does not support model creation.
1317
1207
  */
1318
- createModel(_config: LDAICompletionConfig | LDAIJudgeConfig): Promise<Runner | undefined>;
1208
+ createModel(_config: LDAICompletionConfig | LDAIJudgeConfig, _multiTurn?: boolean): Promise<Runner | undefined>;
1319
1209
  /**
1320
1210
  * Create a Runner for an agent AI Config.
1321
1211
  *
@@ -1407,10 +1297,14 @@ declare class RunnerFactory {
1407
1297
  * ('openai', 'langchain', 'vercel', …). When set, only that provider is
1408
1298
  * tried. When omitted, providers are tried in priority order based on the
1409
1299
  * provider name in the config.
1300
+ * @param multiTurn Whether the runner should accumulate conversation history
1301
+ * across successive `run()` calls. Defaults to `true` (chat semantics).
1302
+ * Judges pass `false` so each evaluation starts from the initial config
1303
+ * messages.
1410
1304
  * @returns A configured {@link Runner} ready to invoke the model, or
1411
1305
  * `undefined` if no suitable provider could be loaded.
1412
1306
  */
1413
- static createModel(config: LDAICompletionConfig | LDAIJudgeConfig, logger?: LDLogger$1, defaultAiProvider?: SupportedAIProvider): Promise<Runner | undefined>;
1307
+ static createModel(config: LDAICompletionConfig | LDAIJudgeConfig, logger?: LDLogger$1, defaultAiProvider?: SupportedAIProvider, multiTurn?: boolean): Promise<Runner | undefined>;
1414
1308
  /**
1415
1309
  * Create a Runner for an agent AI Config.
1416
1310
  *
@@ -1457,9 +1351,11 @@ interface LDAIClient {
1457
1351
  * the message content. The keys correspond to placeholders within the template, and the values
1458
1352
  * are the corresponding replacements.
1459
1353
  *
1460
- * @returns The AI `config`, customized `messages`, and a `tracker`. If the configuration cannot be accessed from
1461
- * LaunchDarkly, then the return value will include information from the `defaultValue`. The returned `tracker` can
1462
- * be used to track AI operation metrics (latency, token usage, etc.).
1354
+ * @returns An {@link LDAICompletionConfig} with `enabled`, `model`, `provider`,
1355
+ * `messages`, and a `createTracker()` factory. Call `createTracker()` on the
1356
+ * returned config to obtain a tracker for each AI run. If the configuration
1357
+ * cannot be accessed from LaunchDarkly, the return value will include
1358
+ * information from the `defaultValue`.
1463
1359
  *
1464
1360
  * @example
1465
1361
  * ```
@@ -1472,35 +1368,15 @@ interface LDAIClient {
1472
1368
  * provider: { name: 'openai' },
1473
1369
  * };
1474
1370
  *
1475
- * const result = completionConfig(key, context, defaultValue, variables);
1476
- * // Output:
1477
- * {
1478
- * enabled: true,
1479
- * config: {
1480
- * modelId: "gpt-4o",
1481
- * temperature: 0.2,
1482
- * maxTokens: 4096,
1483
- * userDefinedKey: "myValue",
1484
- * },
1485
- * messages: [
1486
- * {
1487
- * role: "system",
1488
- * content: "You are an amazing GPT."
1489
- * },
1490
- * {
1491
- * role: "user",
1492
- * content: "Explain how you're an amazing GPT."
1493
- * }
1494
- * ],
1495
- * tracker: ...
1371
+ * const completionConfig = await client.completionConfig(key, context, defaultValue, variables);
1372
+ * if (completionConfig.enabled) {
1373
+ * const tracker = completionConfig.createTracker();
1374
+ * // Use completionConfig.messages and completionConfig.model with your LLM,
1375
+ * // then record metrics with tracker.trackSuccess(), tracker.trackTokens(), etc.
1496
1376
  * }
1497
1377
  * ```
1498
1378
  */
1499
1379
  completionConfig(key: string, context: LDContext, defaultValue?: LDAICompletionConfigDefault, variables?: Record<string, unknown>, defaultAiProvider?: SupportedAIProvider): Promise<LDAICompletionConfig>;
1500
- /**
1501
- * @deprecated Use `completionConfig` instead. This method will be removed in a future version.
1502
- */
1503
- config(key: string, context: LDContext, defaultValue?: LDAICompletionConfigDefault, variables?: Record<string, unknown>): Promise<LDAICompletionConfig>;
1504
1380
  /**
1505
1381
  * Retrieves and processes a single AI Config agent based on the provided key, LaunchDarkly context,
1506
1382
  * and variables. This includes the model configuration and the customized instructions.
@@ -1515,9 +1391,11 @@ interface LDAIClient {
1515
1391
  * the instructions. The keys correspond to placeholders within the template, and the values
1516
1392
  * are the corresponding replacements.
1517
1393
  *
1518
- * @returns An AI agent with customized `instructions` and a `tracker`. If the configuration
1519
- * cannot be accessed from LaunchDarkly, then the return value will include information from the
1520
- * `defaultValue`. The returned `tracker` can be used to track AI operation metrics (latency, token usage, etc.).
1394
+ * @returns An {@link LDAIAgentConfig} with customized `instructions`, `model`,
1395
+ * `provider`, and a `createTracker()` factory. Call `createTracker()` on the
1396
+ * returned config to obtain a tracker for each AI run. If the configuration
1397
+ * cannot be accessed from LaunchDarkly, the return value will include
1398
+ * information from the `defaultValue`.
1521
1399
  *
1522
1400
  * @example
1523
1401
  * ```
@@ -1531,15 +1409,14 @@ interface LDAIClient {
1531
1409
  * instructions: 'You are a research assistant.',
1532
1410
  * }, variables);
1533
1411
  *
1534
- * const researchResult = agentConfig.instructions; // Interpolated instructions
1535
- * agentConfig.tracker.trackSuccess();
1412
+ * if (agentConfig.enabled) {
1413
+ * const tracker = agentConfig.createTracker();
1414
+ * const researchResult = agentConfig.instructions; // Interpolated instructions
1415
+ * tracker.trackSuccess();
1416
+ * }
1536
1417
  * ```
1537
1418
  */
1538
1419
  agentConfig(key: string, context: LDContext, defaultValue?: LDAIAgentConfigDefault, variables?: Record<string, unknown>, defaultAiProvider?: SupportedAIProvider): Promise<LDAIAgentConfig>;
1539
- /**
1540
- * @deprecated Use `agentConfig` instead. This method will be removed in a future version.
1541
- */
1542
- agent(key: string, context: LDContext, defaultValue?: LDAIAgentConfigDefault, variables?: Record<string, unknown>): Promise<LDAIAgentConfig>;
1543
1420
  /**
1544
1421
  * Retrieves and processes a Judge AI Config based on the provided key, LaunchDarkly context,
1545
1422
  * and variables. This includes the model configuration and the customized messages for evaluation.
@@ -1551,7 +1428,10 @@ interface LDAIClient {
1551
1428
  * @param defaultValue Optional fallback when the configuration is not available from LaunchDarkly.
1552
1429
  * When omitted or null, a disabled default is used.
1553
1430
  * @param variables Optional variables for template interpolation in messages and instructions.
1554
- * @returns A promise that resolves to a tracked judge configuration.
1431
+ * @returns A promise that resolves to an {@link LDAIJudgeConfig} with `enabled`,
1432
+ * `model`, `provider`, `messages`, `evaluationMetricKey`, and a `createTracker()`
1433
+ * factory. Call `createTracker()` on the returned config to obtain a tracker for
1434
+ * each AI run.
1555
1435
  *
1556
1436
  * @example
1557
1437
  * ```typescript
@@ -1563,8 +1443,11 @@ interface LDAIClient {
1563
1443
  * messages: [{ role: 'system', content: 'You are a relevance judge.' }]
1564
1444
  * }, variables);
1565
1445
  *
1566
- * const config = judgeConf.config; // Interpolated configuration
1567
- * judgeConf.tracker.trackSuccess();
1446
+ * if (judgeConf.enabled) {
1447
+ * const tracker = judgeConf.createTracker();
1448
+ * // Use judgeConf.messages and judgeConf.model with your LLM,
1449
+ * // then record metrics with tracker.trackSuccess(), tracker.trackJudgeResult(), etc.
1450
+ * }
1568
1451
  * ```
1569
1452
  */
1570
1453
  judgeConfig(key: string, context: LDContext, defaultValue?: LDAIJudgeConfigDefault, variables?: Record<string, unknown>): Promise<LDAIJudgeConfig>;
@@ -1578,10 +1461,11 @@ interface LDAIClient {
1578
1461
  * current environment, user, or session. This context may influence how the configuration is
1579
1462
  * processed or personalized.
1580
1463
  *
1581
- * @returns A map of agent keys to their respective AI agents with customized `instructions` and `tracker`.
1582
- * If a configuration cannot be accessed from LaunchDarkly, then the return value will include information
1583
- * from the respective `defaultValue`. The returned `tracker` can be used to track AI operation metrics
1584
- * (latency, token usage, etc.).
1464
+ * @returns A map of agent keys to their respective {@link LDAIAgentConfig}s,
1465
+ * each with customized `instructions` and a `createTracker()` factory. Call
1466
+ * `createTracker()` on a returned config to obtain a tracker for each AI run.
1467
+ * If a configuration cannot be accessed from LaunchDarkly, the return value
1468
+ * will include information from the respective `defaultValue`.
1585
1469
  *
1586
1470
  * @example
1587
1471
  * ```
@@ -1610,15 +1494,14 @@ interface LDAIClient {
1610
1494
  * const context = {...};
1611
1495
  *
1612
1496
  * const configs = await client.agentConfigs(agentConfigsList, context);
1613
- * const researchResult = configs["research_agent"].instructions; // Interpolated instructions
1614
- * configs["research_agent"].tracker.trackSuccess();
1497
+ * if (configs["research_agent"].enabled) {
1498
+ * const tracker = configs["research_agent"].createTracker();
1499
+ * const researchResult = configs["research_agent"].instructions; // Interpolated instructions
1500
+ * tracker.trackSuccess();
1501
+ * }
1615
1502
  * ```
1616
1503
  */
1617
1504
  agentConfigs<const T extends readonly LDAIAgentRequestConfig[]>(agentConfigs: T, context: LDContext): Promise<Record<T[number]['key'], LDAIAgentConfig>>;
1618
- /**
1619
- * @deprecated Use `agentConfigs` instead. This method will be removed in a future version.
1620
- */
1621
- agents<const T extends readonly LDAIAgentRequestConfig[]>(agentConfigs: T, context: LDContext): Promise<Record<T[number]['key'], LDAIAgentConfig>>;
1622
1505
  /**
1623
1506
  * Creates and returns a new ManagedModel instance for LLM model interactions.
1624
1507
  *
@@ -1666,14 +1549,6 @@ interface LDAIClient {
1666
1549
  * @returns A promise that resolves to the ManagedAgent instance, or undefined if disabled.
1667
1550
  */
1668
1551
  createAgent(key: string, context: LDContext, defaultValue?: LDAIAgentConfigDefault, variables?: Record<string, unknown>, defaultAiProvider?: SupportedAIProvider): Promise<ManagedAgent | undefined>;
1669
- /**
1670
- * @deprecated Use `createModel` instead. This method will be removed in a future version.
1671
- */
1672
- createChat(key: string, context: LDContext, defaultValue?: LDAICompletionConfigDefault, variables?: Record<string, unknown>, defaultAiProvider?: SupportedAIProvider): Promise<ManagedModel | undefined>;
1673
- /**
1674
- * @deprecated Use `createModel` instead. This method will be removed in a future version.
1675
- */
1676
- initChat(key: string, context: LDContext, defaultValue?: LDAICompletionConfigDefault, variables?: Record<string, unknown>, defaultAiProvider?: SupportedAIProvider): Promise<ManagedModel | undefined>;
1677
1552
  /**
1678
1553
  * Creates and returns a new Judge instance for AI evaluation.
1679
1554
  *
@@ -1713,7 +1588,7 @@ interface LDAIClient {
1713
1588
  /**
1714
1589
  * Reconstructs an AIConfigTracker from a resumption token string previously
1715
1590
  * obtained from a tracker's `resumptionToken` property. Use this to associate
1716
- * deferred events (such as user feedback) with the original invocation's runId.
1591
+ * deferred events (such as user feedback) with the original tracker's runId.
1717
1592
  *
1718
1593
  * @param token A URL-safe Base64-encoded resumption token string.
1719
1594
  * @param context The evaluation context to use for subsequent track calls.
@@ -1777,6 +1652,42 @@ interface LDClientMin {
1777
1652
  readonly logger?: LDLogger$1;
1778
1653
  }
1779
1654
 
1655
+ /**
1656
+ * ManagedAgentGraph wraps an AgentGraphDefinition and provides a managed run()
1657
+ * method that returns ManagedGraphResult with async judge evaluations.
1658
+ *
1659
+ * The runner function is responsible for executing the graph and returning
1660
+ * an AgentGraphRunnerResult. ManagedAgentGraph builds the managed result from
1661
+ * the runner result, including LDAIGraphMetricSummary with the graphTracker's
1662
+ * resumptionToken.
1663
+ */
1664
+ declare class ManagedAgentGraph {
1665
+ private readonly _graphDefinition;
1666
+ private readonly _logger?;
1667
+ constructor(_graphDefinition: AgentGraphDefinition, _logger?: LDLogger$1 | undefined);
1668
+ /**
1669
+ * Runs the agent graph using the provided runner function and returns a ManagedGraphResult.
1670
+ *
1671
+ * The runner function receives the graph tracker and AgentGraphDefinition,
1672
+ * executes the graph, and returns an AgentGraphRunnerResult.
1673
+ *
1674
+ * run() returns before ManagedGraphResult.evaluations resolves.
1675
+ *
1676
+ * @param runner Async function that executes the graph and returns AgentGraphRunnerResult.
1677
+ * @returns ManagedGraphResult with LDAIGraphMetricSummary and evaluations promise.
1678
+ */
1679
+ run(runner: (graphDefinition: AgentGraphDefinition, graphTracker: LDGraphTracker) => Promise<AgentGraphRunnerResult>): Promise<ManagedGraphResult>;
1680
+ /**
1681
+ * Converts per-node LDAIMetrics from the runner into LDAIMetricSummary by
1682
+ * creating a per-node tracker, firing tracking events, and calling getSummary().
1683
+ */
1684
+ private _trackNodeMetrics;
1685
+ /**
1686
+ * Returns the underlying AgentGraphDefinition.
1687
+ */
1688
+ getGraphDefinition(): AgentGraphDefinition;
1689
+ }
1690
+
1780
1691
  /**
1781
1692
  * Concrete implementation of {@link LDGraphTracker}.
1782
1693
  *
@@ -1839,4 +1750,4 @@ declare class LDGraphTrackerImpl implements LDGraphTracker {
1839
1750
  declare function initAi(ldClient: LDClientMin): LDAIClient;
1840
1751
  type LDLogger = common.LDLogger;
1841
1752
 
1842
- export { AIProvider, AgentGraphDefinition, AgentGraphNode, type AgentGraphRunner, type AgentGraphRunnerResult, type ChatResponse, Judge, type LDAIAgentConfig, type LDAIAgentConfigDefault, type LDAIAgentRequestConfig, type LDAIClient, type LDAICompletionConfig, type LDAICompletionConfigDefault, type LDAIConfig, type LDAIConfigDefault, type LDAIConfigDefaultKind, type LDAIConfigKind, type LDAIConfigMode, type LDAIConfigTracker, type LDAIGraphMetricSummary, type LDAIGraphMetrics, type LDAIJudgeConfig, type LDAIJudgeConfigDefault, type LDAIMetricSummary, type LDAIMetrics, type LDAgentGraphFlagValue, LDFeedbackKind, type LDGraphEdge, type LDGraphTrackData, type LDGraphTracker, LDGraphTrackerImpl, type LDJudge, type LDJudgeConfiguration, type LDJudgeResult, type LDLogger, type LDMessage, type LDModelConfig, type LDProviderConfig, type LDTokenUsage, type LDTool, ManagedAgent, ManagedAgentGraph, type ManagedGraphResult, ManagedModel, type ManagedResult, type Runner, RunnerFactory, type RunnerResult, SUPPORTED_AI_PROVIDERS, type SupportedAIProvider, type ToolRegistry, type TraversalFn, createBedrockTokenUsage, createOpenAiUsage, createVercelAISDKTokenUsage, initAi };
1753
+ export { AIProvider, AgentGraphDefinition, AgentGraphNode, type AgentGraphRunner, type AgentGraphRunnerResult, Judge, type LDAIAgentConfig, type LDAIAgentConfigDefault, type LDAIAgentRequestConfig, type LDAIClient, type LDAICompletionConfig, type LDAICompletionConfigDefault, type LDAIConfig, type LDAIConfigDefault, type LDAIConfigDefaultKind, type LDAIConfigKind, type LDAIConfigMode, type LDAIConfigTracker, type LDAIGraphMetricSummary, type LDAIGraphMetrics, type LDAIJudgeConfig, type LDAIJudgeConfigDefault, type LDAIMetricSummary, type LDAIMetrics, type LDAgentGraphFlagValue, LDFeedbackKind, type LDGraphEdge, type LDGraphTrackData, type LDGraphTracker, LDGraphTrackerImpl, type LDJudge, type LDJudgeConfiguration, type LDJudgeResult, type LDLogger, type LDMessage, type LDModelConfig, type LDProviderConfig, type LDTokenUsage, type LDTool, ManagedAgent, ManagedAgentGraph, type ManagedGraphResult, ManagedModel, type ManagedResult, type Runner, RunnerFactory, type RunnerResult, SUPPORTED_AI_PROVIDERS, type SupportedAIProvider, type ToolRegistry, type TraversalFn, initAi };