createAgent rejects TavilySearch with exactOptionalPropertyTypes enabled
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
import { TavilySearch } from '@langchain/tavily';
import { createAgent } from 'langchain';
createAgent({
model: 'openai:gpt-4.1-mini',
tools: [new TavilySearch()],
});Error Message and Stack Trace (if applicable)
No overload matches this call.
The last overload gave the following error.
Type 'TavilySearch' is not assignable to type 'ClientTool | ServerTool'.
Type 'TavilySearch' is not assignable to type 'ServerTool'.
Index signature for type 'string' is missing in type 'TavilySearch'.
index.d.ts(232, 18): The last overload is declared here.Description
I'm using the official TavilySearch integration from @langchain/tavily directly in the tools array passed to createAgent().
With exactOptionalPropertyTypes: true, TypeScript rejects TavilySearch as not assignable to the ClientTool | ServerTool type expected by createAgent().
I expect the following to type-check without a cast or wrapper:
createAgent({
model: 'openai:gpt-4.1-mini',
tools: [new TavilySearch()],
});Instead, TypeScript reports:
Type 'TavilySearch' is not assignable to type 'ClientTool | ServerTool'.TypeScript configuration
The issue surfaced after adding @tsconfig/strictest, which enables exactOptionalPropertyTypes.
My project extends:
{
"extends": [
"@tsconfig/recommended/tsconfig.json",
"@tsconfig/node-lts/tsconfig.json",
"@tsconfig/strictest/tsconfig.json"
]
}The relevant effective compiler option is:
{
"compilerOptions": {
"exactOptionalPropertyTypes": true
}
}This is important because the same official tool is expected to remain assignable to the tool type accepted by createAgent() when consumers enable stricter TypeScript optional-property checking.
Dependency versions
The relevant LangChain dependencies are:
[email protected]
@langchain/[email protected]
@langchain/[email protected]
@langchain/[email protected]
@langchain/[email protected]npm ls shows that all of these resolve to the same @langchain/[email protected]; there are no duplicate @langchain/core installations involved.
Current workaround
The only workaround currently needed is a type assertion:
import type { ClientTool } from '@langchain/core/tools';
const tavily = new TavilySearch() as unknown as ClientTool;
createAgent({
model: 'openai:gpt-4.1-mini',
tools: [tavily],
});This changes no runtime behavior and only suppresses the type incompatibility.
I would expect the official TavilySearch integration to be accepted directly by createAgent() with exactOptionalPropertyTypes enabled.
System Info
Node: v24.21.0
npm: 11.19.0
TypeScript: 6.0.3
[email protected]
@langchain/[email protected]
@langchain/[email protected]
@langchain/[email protected]
@langchain/[email protected]
Relevant tsconfig packages:
@tsconfig/[email protected]
@tsconfig/[email protected]
@tsconfig/[email protected]
Relevant effective TypeScript options:
module: nodenext
moduleResolution: nodenext
strict: true
exactOptionalPropertyTypes: true
noUncheckedIndexedAccess: true
isolatedModules: true
skipLibCheck: true
All relevant LangChain packages resolve to the same
@langchain/[email protected] installation.Source: langchain-ai/langchainjs