Skip to content

Commit d645b30

Browse files
jsonbaileyclaude
andcommitted
feat!: consolidate graph metric summary into LDAIGraphMetricSummary
The managed-layer `AIGraphMetricSummary` and the tracker-layer `LDAIGraphMetricSummary` were duplicate interfaces describing the same concept with slightly different fields. Consolidate to the existing `LDAIGraphMetricSummary` (which follows the JS LD-prefix naming convention for the spec's `AIGraphMetricSummary`) and add the missing `nodeMetrics` field so it can carry the per-node summaries returned by `ManagedAgentGraph.run()`. `AIGraphMetricSummary` is removed; `ManagedGraphResult.metrics` and `ManagedAgentGraph` now use `LDAIGraphMetricSummary`. All fields remain optional so the tracker can populate them incrementally; the managed layer fills them all in. BREAKING CHANGE: `AIGraphMetricSummary` is removed. Consumers should import `LDAIGraphMetricSummary` from `@launchdarkly/server-sdk-ai` instead. Existing `LDAIGraphMetricSummary` consumers gain an optional `nodeMetrics` field. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 70e4eb9 commit d645b30

2 files changed

Lines changed: 15 additions & 42 deletions

File tree

packages/sdk/server-ai/src/api/graph/ManagedAgentGraph.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { LDAIMetricSummary } from '../model/types';
55
import { LDJudgeResult } from '../judge/types';
66
import { AgentGraphDefinition } from './AgentGraphDefinition';
77
import { LDGraphTracker } from './LDGraphTracker';
8-
import { AgentGraphRunnerResult, GraphMetricSummary, ManagedGraphResult } from './types';
8+
import { AgentGraphRunnerResult, LDAIGraphMetricSummary, ManagedGraphResult } from './types';
99

1010
/**
1111
* ManagedAgentGraph wraps an AgentGraphDefinition and provides a managed run()
1212
* method that returns ManagedGraphResult with async judge evaluations.
1313
*
1414
* The runner function is responsible for executing the graph and returning
1515
* an AgentGraphRunnerResult. ManagedAgentGraph builds the managed result from
16-
* the runner result, including GraphMetricSummary with the graphTracker's
16+
* the runner result, including LDAIGraphMetricSummary with the graphTracker's
1717
* resumptionToken.
1818
*/
1919
export class ManagedAgentGraph {
@@ -31,7 +31,7 @@ export class ManagedAgentGraph {
3131
* run() returns before ManagedGraphResult.evaluations resolves.
3232
*
3333
* @param runner Async function that executes the graph and returns AgentGraphRunnerResult.
34-
* @returns ManagedGraphResult with GraphMetricSummary and evaluations promise.
34+
* @returns ManagedGraphResult with LDAIGraphMetricSummary and evaluations promise.
3535
*/
3636
async run(
3737
runner: (
@@ -43,7 +43,7 @@ export class ManagedAgentGraph {
4343

4444
const runnerResult = await runner(this._graphDefinition, graphTracker);
4545

46-
const metrics: GraphMetricSummary = {
46+
const metrics: LDAIGraphMetricSummary = {
4747
success: runnerResult.metrics.success,
4848
path: runnerResult.metrics.path,
4949
durationMs: runnerResult.metrics.durationMs,

packages/sdk/server-ai/src/api/graph/types.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export interface LDAgentGraphFlagValue {
4040
}
4141

4242
/**
43-
* Accumulated graph-level metrics collected by an LDGraphTracker.
43+
* Summarized graph-level metrics for a graph invocation. Returned by both
44+
* {@link LDGraphTracker.getSummary} (populated incrementally as tracking calls
45+
* arrive) and {@link ManagedAgentGraph.run} via {@link ManagedGraphResult.metrics}
46+
* (populated fully from the runner result).
4447
*/
4548
export interface LDAIGraphMetricSummary {
4649
/**
@@ -63,6 +66,12 @@ export interface LDAIGraphMetricSummary {
6366
*/
6467
path?: string[];
6568

69+
/**
70+
* Per-node metric summaries keyed by agent config key. Populated by
71+
* {@link ManagedAgentGraph.run}; absent on tracker-produced summaries.
72+
*/
73+
nodeMetrics?: Record<string, LDAIMetricSummary>;
74+
6675
/**
6776
* Resumption token for deferred feedback association.
6877
*/
@@ -125,42 +134,6 @@ export interface AgentGraphRunnerResult {
125134
// Managed-Layer Graph Types
126135
// ============================================================================
127136

128-
/**
129-
* Graph metric summary returned in ManagedGraphResult.
130-
* Includes per-node metrics and a resumption token.
131-
*/
132-
export interface GraphMetricSummary {
133-
/**
134-
* Whether the graph invocation succeeded.
135-
*/
136-
success: boolean;
137-
138-
/**
139-
* Execution path through the graph as an ordered array of config keys.
140-
*/
141-
path: string[];
142-
143-
/**
144-
* Total graph execution duration in milliseconds, if tracked.
145-
*/
146-
durationMs?: number;
147-
148-
/**
149-
* Aggregate token usage across the entire graph invocation, if available.
150-
*/
151-
tokens?: LDTokenUsage;
152-
153-
/**
154-
* Per-node metric summaries keyed by agent config key.
155-
*/
156-
nodeMetrics: Record<string, LDAIMetricSummary>;
157-
158-
/**
159-
* Resumption token for deferred feedback association.
160-
*/
161-
resumptionToken?: string;
162-
}
163-
164137
/**
165138
* The result returned by a managed graph invocation (ManagedAgentGraph.run()).
166139
*/
@@ -173,7 +146,7 @@ export interface ManagedGraphResult {
173146
/**
174147
* Summarized metrics for this graph invocation.
175148
*/
176-
metrics: GraphMetricSummary;
149+
metrics: LDAIGraphMetricSummary;
177150

178151
/**
179152
* The raw response object from the provider, if available.

0 commit comments

Comments
 (0)