Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions packages/sdk/server-ai/__tests__/LDAIClientImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,88 @@ describe('optional default values', () => {
expect(result.enabled).toBe(false);
});
});

describe('tools map support', () => {
it('includes tools map in completion config from flag variation', async () => {
const client = new LDAIClientImpl(mockLdClient);
const key = 'test-flag';
const defaultValue: LDAICompletionConfigDefault = { enabled: false };
const mockVariation = {
model: { name: 'example-model' },
tools: {
'web-search-tool': {
name: 'web-search-tool',
type: 'function',
parameters: { type: 'object', properties: {}, required: [] },
customParameters: { 'some-custom-parameter': 'some-custom-value' },
},
},
_ldMeta: { variationKey: 'v1', enabled: true, mode: 'completion' },
};
mockLdClient.variation.mockResolvedValue(mockVariation);

const result = await client.completionConfig(key, testContext, defaultValue);

expect(result.tools).toEqual(mockVariation.tools);
});

it('includes tools map in agent config from flag variation', async () => {
const client = new LDAIClientImpl(mockLdClient);
const key = 'test-agent';
const defaultValue: LDAIAgentConfigDefault = { enabled: false };
const mockVariation = {
model: { name: 'example-model' },
instructions: 'You are a helpful agent.',
tools: {
'search-tool': {
name: 'search-tool',
type: 'function',
customParameters: { maxResults: 10 },
},
},
_ldMeta: { variationKey: 'v1', enabled: true, mode: 'agent' },
};
mockLdClient.variation.mockResolvedValue(mockVariation);

const result = await client.agentConfig(key, testContext, defaultValue);

expect(result.tools).toEqual(mockVariation.tools);
});

it('uses tools from defaults when completion config flag has no tools', async () => {
const client = new LDAIClientImpl(mockLdClient);
const key = 'test-flag';
const defaultTools = {
'default-tool': {
name: 'default-tool',
type: 'function',
customParameters: { priority: 'high' },
},
};
const defaultValue: LDAICompletionConfigDefault = { enabled: true, tools: defaultTools };
mockLdClient.variation.mockResolvedValue(
defaultValue.constructor
? { _ldMeta: { enabled: true, mode: 'completion', variationKey: '' }, tools: defaultTools }
: defaultValue,
);
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

const result = await client.completionConfig(key, testContext, defaultValue);

expect(result.tools).toEqual(defaultTools);
Comment thread
jsonbailey marked this conversation as resolved.
Outdated
});

it('returns undefined tools when no tools are configured', async () => {
const client = new LDAIClientImpl(mockLdClient);
const key = 'test-flag';
const defaultValue: LDAICompletionConfigDefault = { enabled: false };
const mockVariation = {
model: { name: 'example-model' },
_ldMeta: { variationKey: 'v1', enabled: true, mode: 'completion' },
};
mockLdClient.variation.mockResolvedValue(mockVariation);

const result = await client.completionConfig(key, testContext, defaultValue);

expect(result.tools).toBeUndefined();
});
});
7 changes: 7 additions & 0 deletions packages/sdk/server-ai/src/api/config/LDAIConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
LDMessage,
LDModelConfig,
LDProviderConfig,
LDTool,
} from './types';

/**
Expand All @@ -32,6 +33,7 @@ export interface LDAIConfigFlagValue {
evaluationMetricKey?: string;
evaluationMetricKeys?: string[];
judgeConfiguration?: LDJudgeConfiguration;
tools?: { [toolName: string]: LDTool };
}

/**
Expand Down Expand Up @@ -75,6 +77,9 @@ export class LDAIConfigUtils {
if ('judgeConfiguration' in config && config.judgeConfiguration !== undefined) {
flagValue.judgeConfiguration = config.judgeConfiguration;
}
if ('tools' in config && config.tools !== undefined) {
flagValue.tools = config.tools;
}

return flagValue;
}
Expand Down Expand Up @@ -172,6 +177,7 @@ export class LDAIConfigUtils {
createTracker: trackerFactory,
messages: flagValue.messages,
judgeConfiguration: flagValue.judgeConfiguration,
tools: flagValue.tools,
};
}

Expand All @@ -193,6 +199,7 @@ export class LDAIConfigUtils {
createTracker: trackerFactory,
instructions: flagValue.instructions,
judgeConfiguration: flagValue.judgeConfiguration,
tools: flagValue.tools,
};
}

Expand Down
31 changes: 31 additions & 0 deletions packages/sdk/server-ai/src/api/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ export interface LDProviderConfig {
name: string;
}

// ============================================================================
// Tool Types
// ============================================================================

/**
* Configuration for a single tool entry in the root-level tools map.
* Separate from model.parameters.tools[] which is the LLM-passable array.
*/
export interface LDTool {
name: string;
type?: string;
parameters?: { [index: string]: unknown };
customParameters?: { [index: string]: unknown };
}

// ============================================================================
// Judge Types
// ============================================================================
Expand Down Expand Up @@ -129,6 +144,10 @@ export interface LDAIAgentConfigDefault extends LDAIConfigDefault {
* References judge AI Configs that should evaluate this AI Config.
*/
judgeConfiguration?: LDJudgeConfiguration;
/**
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
*/
tools?: { [toolName: string]: LDTool };
}

/**
Expand All @@ -144,6 +163,10 @@ export interface LDAICompletionConfigDefault extends LDAIConfigDefault {
* References judge AI Configs that should evaluate this AI Config.
*/
judgeConfiguration?: LDJudgeConfiguration;
/**
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
*/
tools?: { [toolName: string]: LDTool };
Comment thread
jsonbailey marked this conversation as resolved.
}

/**
Expand Down Expand Up @@ -192,6 +215,10 @@ export interface LDAIAgentConfig extends LDAIConfig {
* References judge AI Configs that should evaluate this AI Config.
*/
judgeConfiguration?: LDJudgeConfiguration;
/**
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
*/
tools?: { [toolName: string]: LDTool };
}

/**
Expand All @@ -207,6 +234,10 @@ export interface LDAICompletionConfig extends LDAIConfig {
* References judge AI Configs that should evaluate this AI Config.
*/
judgeConfiguration?: LDJudgeConfiguration;
/**
* Root-level tools map keyed by tool name. Distinct from model.parameters.tools[].
*/
tools?: { [toolName: string]: LDTool };
}

/**
Expand Down
Loading