Skip to content

Commit 5a4258a

Browse files
committed
fix: Include the AI Judge Config key with tracked metrics
1 parent a51dcdb commit 5a4258a

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class LDAIClientImpl implements LDAIClient {
6363
this._logger?.warn(
6464
`AI Config mode mismatch for ${key}: expected ${mode}, got ${flagMode}. Returning disabled config.`,
6565
);
66-
return LDAIConfigUtils.createDisabledConfig(mode);
66+
return LDAIConfigUtils.createDisabledConfig(key, mode);
6767
}
6868

6969
const tracker = new LDAIConfigTrackerImpl(
@@ -78,7 +78,7 @@ export class LDAIClientImpl implements LDAIClient {
7878
context,
7979
);
8080

81-
const config = LDAIConfigUtils.fromFlagValue(value, tracker);
81+
const config = LDAIConfigUtils.fromFlagValue(key, value, tracker);
8282

8383
// Apply variable interpolation (always needed for ldctx)
8484
return this._applyInterpolation(config, context, variables);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
7878
trackEvalScores(scores: Record<string, EvalScore>) {
7979
// Track each evaluation score individually
8080
Object.entries(scores).forEach(([metricKey, evalScore]) => {
81-
this._ldClient.track(metricKey, this._context, this.getTrackData(), evalScore.score);
81+
this._ldClient.track(
82+
metricKey,
83+
this._context,
84+
{ ...this.getTrackData(), judgeConfigKey: evalScore.judgeConfigKey },
85+
evalScore.score,
86+
);
8287
});
8388
}
8489

packages/sdk/server-ai/src/api/config/LDAIConfigUtils.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,23 @@ export class LDAIConfigUtils {
8282
* @param tracker The tracker to add to the config
8383
* @returns The appropriate AI configuration type
8484
*/
85-
static fromFlagValue(flagValue: LDAIConfigFlagValue, tracker: LDAIConfigTracker): LDAIConfigKind {
85+
static fromFlagValue(
86+
key: string,
87+
flagValue: LDAIConfigFlagValue,
88+
tracker: LDAIConfigTracker,
89+
): LDAIConfigKind {
8690
// Determine the actual mode from flag value
8791
// eslint-disable-next-line no-underscore-dangle
8892
const flagValueMode = flagValue._ldMeta?.mode;
8993

9094
switch (flagValueMode) {
9195
case 'agent':
92-
return this.toAgentConfig(flagValue, tracker);
96+
return this.toAgentConfig(key, flagValue, tracker);
9397
case 'judge':
94-
return this.toJudgeConfig(flagValue, tracker);
98+
return this.toJudgeConfig(key, flagValue, tracker);
9599
case 'completion':
96100
default:
97-
return this.toCompletionConfig(flagValue, tracker);
101+
return this.toCompletionConfig(key, flagValue, tracker);
98102
}
99103
}
100104

@@ -104,15 +108,17 @@ export class LDAIConfigUtils {
104108
* @param mode The mode for the disabled config
105109
* @returns A disabled config of the appropriate type
106110
*/
107-
static createDisabledConfig(mode: LDAIConfigMode): LDAIConfigKind {
111+
static createDisabledConfig(key: string, mode: LDAIConfigMode): LDAIConfigKind {
108112
switch (mode) {
109113
case 'agent':
110114
return {
115+
key,
111116
enabled: false,
112117
tracker: undefined,
113118
} as LDAIAgentConfig;
114119
case 'judge':
115120
return {
121+
key,
116122
enabled: false,
117123
tracker: undefined,
118124
evaluationMetricKeys: [],
@@ -121,6 +127,7 @@ export class LDAIConfigUtils {
121127
default:
122128
// Default to completion config for completion mode or any unexpected mode
123129
return {
130+
key,
124131
enabled: false,
125132
tracker: undefined,
126133
} as LDAICompletionConfig;
@@ -133,8 +140,9 @@ export class LDAIConfigUtils {
133140
* @param flagValue The flag value from LaunchDarkly
134141
* @returns Base configuration object
135142
*/
136-
private static _toBaseConfig(flagValue: LDAIConfigFlagValue) {
143+
private static _toBaseConfig(key: string, flagValue: LDAIConfigFlagValue) {
137144
return {
145+
key,
138146
// eslint-disable-next-line no-underscore-dangle
139147
enabled: flagValue._ldMeta?.enabled ?? false,
140148
model: flagValue.model,
@@ -150,11 +158,12 @@ export class LDAIConfigUtils {
150158
* @returns A completion configuration
151159
*/
152160
static toCompletionConfig(
161+
key: string,
153162
flagValue: LDAIConfigFlagValue,
154163
tracker: LDAIConfigTracker,
155164
): LDAICompletionConfig {
156165
return {
157-
...this._toBaseConfig(flagValue),
166+
...this._toBaseConfig(key, flagValue),
158167
tracker,
159168
messages: flagValue.messages,
160169
judgeConfiguration: flagValue.judgeConfiguration,
@@ -169,11 +178,12 @@ export class LDAIConfigUtils {
169178
* @returns An agent configuration
170179
*/
171180
static toAgentConfig(
181+
key: string,
172182
flagValue: LDAIConfigFlagValue,
173183
tracker: LDAIConfigTracker,
174184
): LDAIAgentConfig {
175185
return {
176-
...this._toBaseConfig(flagValue),
186+
...this._toBaseConfig(key, flagValue),
177187
tracker,
178188
instructions: flagValue.instructions,
179189
judgeConfiguration: flagValue.judgeConfiguration,
@@ -188,11 +198,12 @@ export class LDAIConfigUtils {
188198
* @returns A judge configuration
189199
*/
190200
static toJudgeConfig(
201+
key: string,
191202
flagValue: LDAIConfigFlagValue,
192203
tracker: LDAIConfigTracker,
193204
): LDAIJudgeConfig {
194205
return {
195-
...this._toBaseConfig(flagValue),
206+
...this._toBaseConfig(key, flagValue),
196207
tracker,
197208
messages: flagValue.messages,
198209
evaluationMetricKeys: flagValue.evaluationMetricKeys || [],

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export interface LDAIConfigDefault {
9595
* Base AI Config interface without mode-specific fields.
9696
*/
9797
export interface LDAIConfig extends Omit<LDAIConfigDefault, 'enabled'> {
98+
/**
99+
* The key of the AI Config.
100+
*/
101+
key: string;
98102
/**
99103
* Whether the configuration is enabled.
100104
*/

packages/sdk/server-ai/src/api/judge/Judge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export class Judge {
208208
results[metricKey] = {
209209
score: evalData.score,
210210
reasoning: evalData.reasoning,
211+
judgeConfigKey: this._aiConfig.key,
211212
};
212213
});
213214

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface EvalScore {
2424
score: number;
2525
/** Reasoning behind the provided score for this metric */
2626
reasoning: string;
27+
/** The key of the judge configuration that was used to evaluate this metric */
28+
judgeConfigKey?: string;
2729
}
2830

2931
/**

0 commit comments

Comments
 (0)