Skip to content

Commit c216575

Browse files
authored
fix!: Use LDAIGraphMetricSummary for graph metric summary (#1362)
1 parent 70e4eb9 commit c216575

4 files changed

Lines changed: 32 additions & 54 deletions

File tree

packages/sdk/server-ai/src/LDGraphTrackerImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { LDClientMin } from './LDClientMin';
1212
* {@link LDGraphTrackerImpl.fromResumptionToken}.
1313
*/
1414
export class LDGraphTrackerImpl implements LDGraphTracker {
15-
private _summary: LDAIGraphMetricSummary = {};
15+
private _summary: Partial<LDAIGraphMetricSummary> = {};
1616

1717
constructor(
1818
private readonly _ldClient: LDClientMin,
@@ -67,7 +67,7 @@ export class LDGraphTrackerImpl implements LDGraphTracker {
6767
};
6868
}
6969

70-
getSummary(): LDAIGraphMetricSummary {
70+
getSummary(): Partial<LDAIGraphMetricSummary> {
7171
return { ...this._summary };
7272
}
7373

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ export interface LDGraphTracker {
3333
};
3434

3535
/**
36-
* Returns a snapshot of all graph-level metrics tracked so far.
36+
* Returns a snapshot of all graph-level metrics tracked so far. Fields
37+
* populate incrementally as `track*` methods are called, so the result is
38+
* a `Partial<LDAIGraphMetricSummary>`. Once the graph invocation has
39+
* completed via `ManagedAgentGraph.run()`, prefer `ManagedGraphResult.metrics`
40+
* which is fully populated.
3741
*/
38-
getSummary(): LDAIGraphMetricSummary;
42+
getSummary(): Partial<LDAIGraphMetricSummary>;
3943

4044
/**
4145
* A URL-safe Base64-encoded (RFC 4648, no padding) token encoding the tracker's

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: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,38 @@ export interface LDAgentGraphFlagValue {
4040
}
4141

4242
/**
43-
* Accumulated graph-level metrics collected by an LDGraphTracker.
43+
* Summarized graph-level metrics for a completed graph invocation, as
44+
* returned by {@link ManagedAgentGraph.run} via {@link ManagedGraphResult.metrics}.
45+
*
46+
* For the tracker-layer incremental view (where fields populate as tracking
47+
* calls arrive), see {@link LDGraphTracker.getSummary}, which returns a
48+
* `Partial<LDAIGraphMetricSummary>`.
4449
*/
4550
export interface LDAIGraphMetricSummary {
4651
/**
47-
* Whether the graph invocation succeeded. Absent if not yet tracked.
52+
* Whether the graph invocation succeeded.
4853
*/
49-
success?: boolean;
54+
success: boolean;
5055

5156
/**
52-
* Total graph execution duration in milliseconds. Absent if not yet tracked.
57+
* Execution path through the graph as an ordered array of config keys.
5358
*/
54-
durationMs?: number;
59+
path: string[];
60+
61+
/**
62+
* Per-node metric summaries keyed by agent config key.
63+
*/
64+
nodeMetrics: Record<string, LDAIMetricSummary>;
5565

5666
/**
57-
* Aggregate token usage across the entire graph invocation. Absent if not yet tracked.
67+
* Total graph execution duration in milliseconds, if tracked.
5868
*/
59-
tokens?: LDTokenUsage;
69+
durationMs?: number;
6070

6171
/**
62-
* Execution path through the graph as an array of config keys. Absent if not yet tracked.
72+
* Aggregate token usage across the entire graph invocation, if available.
6373
*/
64-
path?: string[];
74+
tokens?: LDTokenUsage;
6575

6676
/**
6777
* Resumption token for deferred feedback association.
@@ -125,42 +135,6 @@ export interface AgentGraphRunnerResult {
125135
// Managed-Layer Graph Types
126136
// ============================================================================
127137

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-
164138
/**
165139
* The result returned by a managed graph invocation (ManagedAgentGraph.run()).
166140
*/
@@ -173,7 +147,7 @@ export interface ManagedGraphResult {
173147
/**
174148
* Summarized metrics for this graph invocation.
175149
*/
176-
metrics: GraphMetricSummary;
150+
metrics: LDAIGraphMetricSummary;
177151

178152
/**
179153
* The raw response object from the provider, if available.

0 commit comments

Comments
 (0)