Skip to content

Commit 487182b

Browse files
authored
feat: Add root-level tools map with customParameters to AI Config types (#1295)
1 parent ef79eac commit 487182b

3 files changed

Lines changed: 122 additions & 0 deletions

File tree

packages/sdk/server-ai/__tests__/LDAIClientImpl.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,86 @@ describe('optional default values', () => {
833833
expect(result.enabled).toBe(false);
834834
});
835835
});
836+
837+
describe('tools map support', () => {
838+
it('includes tools map in completion config from flag variation', async () => {
839+
const client = new LDAIClientImpl(mockLdClient);
840+
const key = 'test-flag';
841+
const defaultValue: LDAICompletionConfigDefault = { enabled: false };
842+
const mockVariation = {
843+
model: { name: 'example-model' },
844+
tools: {
845+
'web-search-tool': {
846+
name: 'web-search-tool',
847+
type: 'function',
848+
parameters: { type: 'object', properties: {}, required: [] },
849+
customParameters: { 'some-custom-parameter': 'some-custom-value' },
850+
},
851+
},
852+
_ldMeta: { variationKey: 'v1', enabled: true, mode: 'completion' },
853+
};
854+
mockLdClient.variation.mockResolvedValue(mockVariation);
855+
856+
const result = await client.completionConfig(key, testContext, defaultValue);
857+
858+
expect(result.tools).toEqual(mockVariation.tools);
859+
});
860+
861+
it('includes tools map in agent config from flag variation', async () => {
862+
const client = new LDAIClientImpl(mockLdClient);
863+
const key = 'test-agent';
864+
const defaultValue: LDAIAgentConfigDefault = { enabled: false };
865+
const mockVariation = {
866+
model: { name: 'example-model' },
867+
instructions: 'You are a helpful agent.',
868+
tools: {
869+
'search-tool': {
870+
name: 'search-tool',
871+
type: 'function',
872+
customParameters: { maxResults: 10 },
873+
},
874+
},
875+
_ldMeta: { variationKey: 'v1', enabled: true, mode: 'agent' },
876+
};
877+
mockLdClient.variation.mockResolvedValue(mockVariation);
878+
879+
const result = await client.agentConfig(key, testContext, defaultValue);
880+
881+
expect(result.tools).toEqual(mockVariation.tools);
882+
});
883+
884+
it('returns undefined tools when variation has no tools', async () => {
885+
const client = new LDAIClientImpl(mockLdClient);
886+
const key = 'test-flag';
887+
const defaultTools = {
888+
'default-tool': {
889+
name: 'default-tool',
890+
type: 'function',
891+
customParameters: { priority: 'high' },
892+
},
893+
};
894+
const defaultValue: LDAICompletionConfigDefault = { enabled: true, tools: defaultTools };
895+
mockLdClient.variation.mockResolvedValue({
896+
_ldMeta: { enabled: true, mode: 'completion', variationKey: '' },
897+
});
898+
899+
const result = await client.completionConfig(key, testContext, defaultValue);
900+
901+
expect(result.tools).toBeUndefined();
902+
});
903+
904+
it('returns undefined tools when no tools are configured', async () => {
905+
const client = new LDAIClientImpl(mockLdClient);
906+
const key = 'test-flag';
907+
const defaultValue: LDAICompletionConfigDefault = { enabled: false };
908+
const mockVariation = {
909+
model: { name: 'example-model' },
910+
_ldMeta: { variationKey: 'v1', enabled: true, mode: 'completion' },
911+
};
912+
mockLdClient.variation.mockResolvedValue(mockVariation);
913+
914+
const result = await client.completionConfig(key, testContext, defaultValue);
915+
916+
expect(result.tools).toBeUndefined();
917+
});
918+
});

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
LDMessage,
1111
LDModelConfig,
1212
LDProviderConfig,
13+
LDTool,
1314
} from './types';
1415

1516
/**
@@ -32,6 +33,7 @@ export interface LDAIConfigFlagValue {
3233
evaluationMetricKey?: string;
3334
evaluationMetricKeys?: string[];
3435
judgeConfiguration?: LDJudgeConfiguration;
36+
tools?: { [toolName: string]: LDTool };
3537
}
3638

3739
/**
@@ -75,6 +77,9 @@ export class LDAIConfigUtils {
7577
if ('judgeConfiguration' in config && config.judgeConfiguration !== undefined) {
7678
flagValue.judgeConfiguration = config.judgeConfiguration;
7779
}
80+
if ('tools' in config && config.tools !== undefined) {
81+
flagValue.tools = config.tools;
82+
}
7883

7984
return flagValue;
8085
}
@@ -172,6 +177,7 @@ export class LDAIConfigUtils {
172177
createTracker: trackerFactory,
173178
messages: flagValue.messages,
174179
judgeConfiguration: flagValue.judgeConfiguration,
180+
tools: flagValue.tools,
175181
};
176182
}
177183

@@ -193,6 +199,7 @@ export class LDAIConfigUtils {
193199
createTracker: trackerFactory,
194200
instructions: flagValue.instructions,
195201
judgeConfiguration: flagValue.judgeConfiguration,
202+
tools: flagValue.tools,
196203
};
197204
}
198205

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ export interface LDProviderConfig {
4545
name: string;
4646
}
4747

48+
// ============================================================================
49+
// Tool Types
50+
// ============================================================================
51+
52+
/**
53+
* Configuration for a single tool entry in the root-level tools map.
54+
* Separate from model.parameters.tools[] which is the LLM-passable array.
55+
*/
56+
export interface LDTool {
57+
name: string;
58+
description?: string;
59+
type?: string;
60+
parameters?: { [index: string]: unknown };
61+
customParameters?: { [index: string]: unknown };
62+
}
63+
4864
// ============================================================================
4965
// Judge Types
5066
// ============================================================================
@@ -129,6 +145,10 @@ export interface LDAIAgentConfigDefault extends LDAIConfigDefault {
129145
* References judge AI Configs that should evaluate this AI Config.
130146
*/
131147
judgeConfiguration?: LDJudgeConfiguration;
148+
/**
149+
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
150+
*/
151+
tools?: { [toolName: string]: LDTool };
132152
}
133153

134154
/**
@@ -144,6 +164,10 @@ export interface LDAICompletionConfigDefault extends LDAIConfigDefault {
144164
* References judge AI Configs that should evaluate this AI Config.
145165
*/
146166
judgeConfiguration?: LDJudgeConfiguration;
167+
/**
168+
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
169+
*/
170+
tools?: { [toolName: string]: LDTool };
147171
}
148172

149173
/**
@@ -192,6 +216,10 @@ export interface LDAIAgentConfig extends LDAIConfig {
192216
* References judge AI Configs that should evaluate this AI Config.
193217
*/
194218
judgeConfiguration?: LDJudgeConfiguration;
219+
/**
220+
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
221+
*/
222+
tools?: { [toolName: string]: LDTool };
195223
}
196224

197225
/**
@@ -207,6 +235,10 @@ export interface LDAICompletionConfig extends LDAIConfig {
207235
* References judge AI Configs that should evaluate this AI Config.
208236
*/
209237
judgeConfiguration?: LDJudgeConfiguration;
238+
/**
239+
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
240+
*/
241+
tools?: { [toolName: string]: LDTool };
210242
}
211243

212244
/**

0 commit comments

Comments
 (0)