Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion packages/langchain-agents/src/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ describe('model source', () => {
expect(MockChatOpenAI).toHaveBeenCalledWith({
temperature: 0.2,
max_tokens: 512,
tools: ['openai-tool'],
model: 'gpt-4o',
});
expect(mockCreateAgent).toHaveBeenCalledWith(expect.objectContaining({ model: constructed }));
Expand Down
6 changes: 5 additions & 1 deletion packages/langchain-agents/src/__tests__/native-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ describe('toLangGraph', () => {

it('spreads model.parameters into the default ChatOpenAI constructor', async () => {
const root = makeNode('root', '', []);
root.config.model.parameters = { temperature: 0.2, max_tokens: 512 };
root.config.model.parameters = {
temperature: 0.2,
max_tokens: 512,
tools: [{ name: 'openai-tool' }],
};
const def = makeGraphDef([root], {}, 'root');
MockChatOpenAI.mockClear();
await toLangGraph(Promise.resolve(def)).invoke('hi');
Expand Down
3 changes: 2 additions & 1 deletion packages/langchain-agents/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ function modelConstructorArgs(config: AiConfigRep, fallbackName: string): Record
const parameters = {
...(config.model?.parameters && typeof config.model.parameters === 'object' ? config.model.parameters : {}),
};
if ((config.provider?.name ?? '').toLowerCase() === 'bedrock') delete parameters.tools;
// Tools are bound from config.tools. A tools key here is forwarded raw and rejected.
delete parameters.tools;
return { ...parameters, model: resolvedModelName(config, fallbackName) };
}

Expand Down
12 changes: 9 additions & 3 deletions packages/langchain-agents/src/native-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,19 @@ export const toLangGraph = (
const toolHandlers = opts?.toolHandlers ?? {};
const modelFactory =
opts?.modelFactory ??
((node) =>
new ChatOpenAI({
((node) => {
const parameters = {
...(node.config.model.parameters && typeof node.config.model.parameters === 'object'
? node.config.model.parameters
: {}),
};
// Tools are bound from the node config. A tools key here is forwarded raw and rejected.
delete parameters.tools;
return new ChatOpenAI({
...parameters,
model: node.config.model.name,
}));
});
});
const ldContext = opts?.context;

return trace.getTracer('@launchdarkly/ai-langchain-agents').startActiveSpan('launchdarkly.graph', async (span) => {
Expand Down
1 change: 0 additions & 1 deletion packages/langchain-messages/src/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,6 @@ describe('model source', () => {
expect(ChatOpenAI).toHaveBeenCalledWith({
temperature: 0.2,
max_tokens: 512,
tools: ['openai-tool'],
model: 'gpt-4o',
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/langchain-messages/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ function modelConstructorArgs(config: AiConfigRep, fallbackName: string): Record
const parameters = {
...(config.model?.parameters && typeof config.model.parameters === 'object' ? config.model.parameters : {}),
};
if ((config.provider?.name ?? '').toLowerCase() === 'bedrock') delete parameters.tools;
// Tools are bound from config.tools. A tools key here is forwarded raw and rejected.
delete parameters.tools;
// Name from the config always wins over a colliding `model` key in the parameter bag.
return { ...parameters, model: resolvedModelName(config, fallbackName) };
}
Expand All @@ -184,7 +185,7 @@ function modelConstructorArgs(config: AiConfigRep, fallbackName: string): Record
* Otherwise, the provider and model name from the AI config are used to
* instantiate the appropriate model via a dynamic import, so that neither
* @langchain/openai, @langchain/anthropic, nor @langchain/aws is a hard
* dependency. Parameters are passed through unchanged.
* dependency. Parameters are passed through, except `tools`, which is bound separately.
*/
async function resolveBaseModel(config: AiConfigRep, llm?: LangChainModelSource): Promise<BaseChatModel> {
const invocation = configForModelCall(config);
Expand Down
Loading