@librechat/agents 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +2 -5
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +1 -0
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/graphs/MultiAgentGraph.cjs +26 -17
  6. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  7. package/dist/cjs/llm/openai/index.cjs +1 -0
  8. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  9. package/dist/cjs/main.cjs +3 -0
  10. package/dist/cjs/main.cjs.map +1 -1
  11. package/dist/cjs/tools/CodeExecutor.cjs +37 -27
  12. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  13. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +21 -17
  14. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  15. package/dist/cjs/tools/ToolNode.cjs +1 -0
  16. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  17. package/dist/cjs/tools/ToolSearch.cjs +37 -30
  18. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  19. package/dist/cjs/tools/search/schema.cjs +25 -23
  20. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  21. package/dist/cjs/tools/search/tool.cjs +9 -33
  22. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  23. package/dist/cjs/utils/schema.cjs +27 -0
  24. package/dist/cjs/utils/schema.cjs.map +1 -0
  25. package/dist/cjs/utils/title.cjs +28 -14
  26. package/dist/cjs/utils/title.cjs.map +1 -1
  27. package/dist/esm/agents/AgentContext.mjs +2 -5
  28. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  29. package/dist/esm/graphs/Graph.mjs +1 -0
  30. package/dist/esm/graphs/Graph.mjs.map +1 -1
  31. package/dist/esm/graphs/MultiAgentGraph.mjs +26 -17
  32. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  33. package/dist/esm/llm/openai/index.mjs +1 -0
  34. package/dist/esm/llm/openai/index.mjs.map +1 -1
  35. package/dist/esm/main.mjs +1 -0
  36. package/dist/esm/main.mjs.map +1 -1
  37. package/dist/esm/tools/CodeExecutor.mjs +37 -27
  38. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  39. package/dist/esm/tools/ProgrammaticToolCalling.mjs +21 -17
  40. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  41. package/dist/esm/tools/ToolNode.mjs +1 -0
  42. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  43. package/dist/esm/tools/ToolSearch.mjs +37 -30
  44. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  45. package/dist/esm/tools/search/schema.mjs +25 -23
  46. package/dist/esm/tools/search/schema.mjs.map +1 -1
  47. package/dist/esm/tools/search/tool.mjs +10 -34
  48. package/dist/esm/tools/search/tool.mjs.map +1 -1
  49. package/dist/esm/utils/schema.mjs +24 -0
  50. package/dist/esm/utils/schema.mjs.map +1 -0
  51. package/dist/esm/utils/title.mjs +28 -14
  52. package/dist/esm/utils/title.mjs.map +1 -1
  53. package/dist/types/tools/CodeExecutor.d.ts +1 -15
  54. package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -13
  55. package/dist/types/tools/ToolSearch.d.ts +1 -15
  56. package/dist/types/tools/search/schema.d.ts +25 -7
  57. package/dist/types/tools/search/tool.d.ts +1 -52
  58. package/dist/types/tools/search/types.d.ts +5 -23
  59. package/dist/types/utils/index.d.ts +1 -0
  60. package/dist/types/utils/schema.d.ts +8 -0
  61. package/package.json +1 -1
  62. package/src/agents/AgentContext.ts +5 -11
  63. package/src/graphs/MultiAgentGraph.ts +26 -17
  64. package/src/specs/agent-handoffs.test.ts +1 -2
  65. package/src/specs/tool-error.test.ts +7 -2
  66. package/src/test/mockTools.ts +34 -14
  67. package/src/tools/CodeExecutor.ts +48 -31
  68. package/src/tools/ProgrammaticToolCalling.ts +24 -23
  69. package/src/tools/ToolSearch.ts +54 -43
  70. package/src/tools/search/schema.ts +30 -25
  71. package/src/tools/search/tool.ts +23 -16
  72. package/src/tools/search/types.ts +5 -29
  73. package/src/utils/index.ts +1 -0
  74. package/src/utils/schema.ts +35 -0
  75. package/src/utils/title.ts +31 -19
@@ -0,0 +1,24 @@
1
+ import { zodToJsonSchema } from 'zod-to-json-schema';
2
+
3
+ // src/utils/schema.ts
4
+ /** Checks if a schema is a Zod schema by looking for the _def property */
5
+ function isZodSchema(schema) {
6
+ return (schema != null && typeof schema === 'object' && '_def' in schema);
7
+ }
8
+ /**
9
+ * Converts a schema to JSON schema format.
10
+ * Handles both Zod schemas (converts) and JSON schemas (passthrough).
11
+ */
12
+ function toJsonSchema(schema, name, description) {
13
+ if (isZodSchema(schema)) {
14
+ const zodSchema = schema;
15
+ const described = description != null && description !== ''
16
+ ? zodSchema.describe(description)
17
+ : schema;
18
+ return zodToJsonSchema(described, name ?? '');
19
+ }
20
+ return schema;
21
+ }
22
+
23
+ export { isZodSchema, toJsonSchema };
24
+ //# sourceMappingURL=schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.mjs","sources":["../../../src/utils/schema.ts"],"sourcesContent":["// src/utils/schema.ts\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport type { ZodTypeAny } from 'zod';\n\n/** Checks if a schema is a Zod schema by looking for the _def property */\nexport function isZodSchema(schema: unknown): schema is ZodTypeAny {\n return (\n schema != null && typeof schema === 'object' && '_def' in (schema as object)\n );\n}\n\n/**\n * Converts a schema to JSON schema format.\n * Handles both Zod schemas (converts) and JSON schemas (passthrough).\n */\nexport function toJsonSchema(\n schema: unknown,\n name?: string,\n description?: string\n): Record<string, unknown> {\n if (isZodSchema(schema)) {\n const zodSchema = schema as ZodTypeAny & {\n describe: (desc: string) => ZodTypeAny;\n };\n const described =\n description != null && description !== ''\n ? zodSchema.describe(description)\n : schema;\n return zodToJsonSchema(\n described as Parameters<typeof zodToJsonSchema>[0],\n name ?? ''\n );\n }\n return schema as Record<string, unknown>;\n}\n"],"names":[],"mappings":";;AAAA;AAIA;AACM,SAAU,WAAW,CAAC,MAAe,EAAA;AACzC,IAAA,QACE,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAK,MAAiB;AAEhF;AAEA;;;AAGG;SACa,YAAY,CAC1B,MAAe,EACf,IAAa,EACb,WAAoB,EAAA;AAEpB,IAAA,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE;QACvB,MAAM,SAAS,GAAG,MAEjB;QACD,MAAM,SAAS,GACb,WAAW,IAAI,IAAI,IAAI,WAAW,KAAK;AACrC,cAAE,SAAS,CAAC,QAAQ,CAAC,WAAW;cAC9B,MAAM;QACZ,OAAO,eAAe,CACpB,SAAkD,EAClD,IAAI,IAAI,EAAE,CACX;;AAEH,IAAA,OAAO,MAAiC;AAC1C;;;;"}
@@ -1,4 +1,3 @@
1
- import { z } from 'zod';
2
1
  import { ChatPromptTemplate } from '@langchain/core/prompts';
3
2
  import { RunnableLambda, RunnableSequence } from '@langchain/core/runnables';
4
3
  import { ContentTypes } from '../common/enum.mjs';
@@ -8,17 +7,30 @@ const defaultTitlePrompt = `Analyze this conversation and provide:
8
7
  2. A concise title in the detected language (5 words or less, no punctuation or quotation)
9
8
 
10
9
  {convo}`;
11
- const titleSchema = z.object({
12
- title: z
13
- .string()
14
- .describe('A concise title for the conversation in 5 words or less, without punctuation or quotation'),
15
- });
16
- const combinedSchema = z.object({
17
- language: z.string().describe('The detected language of the conversation'),
18
- title: z
19
- .string()
20
- .describe('A concise title for the conversation in 5 words or less, without punctuation or quotation'),
21
- });
10
+ const titleSchema = {
11
+ type: 'object',
12
+ properties: {
13
+ title: {
14
+ type: 'string',
15
+ description: 'A concise title for the conversation in 5 words or less, without punctuation or quotation',
16
+ },
17
+ },
18
+ required: ['title'],
19
+ };
20
+ const combinedSchema = {
21
+ type: 'object',
22
+ properties: {
23
+ language: {
24
+ type: 'string',
25
+ description: 'The detected language of the conversation',
26
+ },
27
+ title: {
28
+ type: 'string',
29
+ description: 'A concise title for the conversation in 5 words or less, without punctuation or quotation',
30
+ },
31
+ },
32
+ required: ['language', 'title'],
33
+ };
22
34
  const createTitleRunnable = async (model, _titlePrompt) => {
23
35
  // Disabled since this works fine
24
36
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -33,13 +45,15 @@ const createTitleRunnable = async (model, _titlePrompt) => {
33
45
  /** Wrap titleOnlyChain in RunnableLambda to create parent span */
34
46
  const titleOnlyChain = new RunnableLambda({
35
47
  func: async (input, config) => {
36
- return await titleOnlyInnerChain.invoke(input, config);
48
+ const result = await titleOnlyInnerChain.invoke(input, config);
49
+ return result;
37
50
  },
38
51
  }).withConfig({ runName: 'TitleOnlyChain' });
39
52
  /** Wrap combinedChain in RunnableLambda to create parent span */
40
53
  const combinedChain = new RunnableLambda({
41
54
  func: async (input, config) => {
42
- return await combinedInnerChain.invoke(input, config);
55
+ const result = await combinedInnerChain.invoke(input, config);
56
+ return result;
43
57
  },
44
58
  }).withConfig({ runName: 'TitleLanguageChain' });
45
59
  /** Runnable to add default values if needed */
@@ -1 +1 @@
1
- {"version":3,"file":"title.mjs","sources":["../../../src/utils/title.ts"],"sourcesContent":["import { z } from 'zod';\nimport { ChatPromptTemplate } from '@langchain/core/prompts';\nimport { RunnableLambda, RunnableSequence } from '@langchain/core/runnables';\nimport type { Runnable, RunnableConfig } from '@langchain/core/runnables';\nimport type { AIMessage } from '@langchain/core/messages';\nimport type * as t from '@/types';\nimport { ContentTypes } from '@/common';\n\nconst defaultTitlePrompt = `Analyze this conversation and provide:\n1. The detected language of the conversation\n2. A concise title in the detected language (5 words or less, no punctuation or quotation)\n\n{convo}`;\n\nconst titleSchema = z.object({\n title: z\n .string()\n .describe(\n 'A concise title for the conversation in 5 words or less, without punctuation or quotation'\n ),\n});\n\nconst combinedSchema = z.object({\n language: z.string().describe('The detected language of the conversation'),\n title: z\n .string()\n .describe(\n 'A concise title for the conversation in 5 words or less, without punctuation or quotation'\n ),\n});\n\nexport const createTitleRunnable = async (\n model: t.ChatModelInstance,\n _titlePrompt?: string\n): Promise<Runnable> => {\n // Disabled since this works fine\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /* @ts-ignore */\n const titleLLM = model.withStructuredOutput(titleSchema);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /* @ts-ignore */\n const combinedLLM = model.withStructuredOutput(combinedSchema);\n\n const titlePrompt = ChatPromptTemplate.fromTemplate(\n _titlePrompt ?? defaultTitlePrompt\n ).withConfig({ runName: 'TitlePrompt' });\n\n const titleOnlyInnerChain = RunnableSequence.from([titlePrompt, titleLLM]);\n const combinedInnerChain = RunnableSequence.from([titlePrompt, combinedLLM]);\n\n /** Wrap titleOnlyChain in RunnableLambda to create parent span */\n const titleOnlyChain = new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ title: string }> => {\n return await titleOnlyInnerChain.invoke(input, config);\n },\n }).withConfig({ runName: 'TitleOnlyChain' });\n\n /** Wrap combinedChain in RunnableLambda to create parent span */\n const combinedChain = new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ language: string; title: string }> => {\n return await combinedInnerChain.invoke(input, config);\n },\n }).withConfig({ runName: 'TitleLanguageChain' });\n\n /** Runnable to add default values if needed */\n const addDefaults = new RunnableLambda({\n func: (\n result: { language: string; title: string } | undefined\n ): { language: string; title: string } => ({\n language: result?.language ?? 'English',\n title: result?.title ?? '',\n }),\n }).withConfig({ runName: 'AddDefaults' });\n\n const combinedChainInner = RunnableSequence.from([\n combinedChain,\n addDefaults,\n ]);\n\n /** Wrap combinedChainWithDefaults in RunnableLambda to create parent span */\n const combinedChainWithDefaults = new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ language: string; title: string }> => {\n return await combinedChainInner.invoke(input, config);\n },\n }).withConfig({ runName: 'CombinedChainWithDefaults' });\n\n return new RunnableLambda({\n func: async (\n input: {\n convo: string;\n inputText: string;\n skipLanguage: boolean;\n },\n config?: Partial<RunnableConfig>\n ): Promise<{ language: string; title: string } | { title: string }> => {\n const invokeInput = { convo: input.convo };\n\n if (input.skipLanguage) {\n return (await titleOnlyChain.invoke(invokeInput, config)) as {\n title: string;\n };\n }\n\n return await combinedChainWithDefaults.invoke(invokeInput, config);\n },\n }).withConfig({ runName: 'TitleGenerator' });\n};\n\nconst defaultCompletionPrompt = `Provide a concise, 5-word-or-less title for the conversation, using title case conventions. Only return the title itself.\n\nConversation:\n{convo}`;\n\nexport const createCompletionTitleRunnable = async (\n model: t.ChatModelInstance,\n titlePrompt?: string\n): Promise<Runnable> => {\n const completionPrompt = ChatPromptTemplate.fromTemplate(\n titlePrompt ?? defaultCompletionPrompt\n ).withConfig({ runName: 'CompletionTitlePrompt' });\n\n /** Runnable to extract content from model response */\n const extractContent = new RunnableLambda({\n func: (response: AIMessage): { title: string } => {\n let content = '';\n if (typeof response.content === 'string') {\n content = response.content;\n } else if (Array.isArray(response.content)) {\n content = response.content\n .filter(\n (part): part is { type: ContentTypes.TEXT; text: string } =>\n part.type === ContentTypes.TEXT\n )\n .map((part) => part.text)\n .join('');\n }\n return { title: content.trim() };\n },\n }).withConfig({ runName: 'ExtractTitle' });\n\n const innerChain = RunnableSequence.from([\n completionPrompt,\n model,\n extractContent,\n ]);\n\n /** Wrap in RunnableLambda to create a parent span for LangFuse */\n return new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ title: string }> => {\n return await innerChain.invoke(input, config);\n },\n }).withConfig({ runName: 'CompletionTitleChain' });\n};\n"],"names":[],"mappings":";;;;;AAQA,MAAM,kBAAkB,GAAG,CAAA;;;;QAInB;AAER,MAAM,WAAW,GAAG,CAAC,CA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{ ChatPromptTemplate } from '@langchain/core/prompts';\nimport { RunnableLambda, RunnableSequence } from '@langchain/core/runnables';\nimport type { Runnable, RunnableConfig } from '@langchain/core/runnables';\nimport type { AIMessage } from '@langchain/core/messages';\nimport type * as t from '@/types';\nimport { ContentTypes } from '@/common';\n\nconst defaultTitlePrompt = `Analyze this conversation and provide:\n1. The detected language of the conversation\n2. A concise title in the detected language (5 words or less, no punctuation or quotation)\n\n{convo}`;\n\nconst titleSchema = {\n type: 'object',\n properties: {\n title: {\n type: 'string',\n description:\n 'A concise title for the conversation in 5 words or less, without punctuation or quotation',\n },\n },\n required: ['title'],\n} as const;\n\nconst combinedSchema = {\n type: 'object',\n properties: {\n language: {\n type: 'string',\n description: 'The detected language of the conversation',\n },\n title: {\n type: 'string',\n description:\n 'A concise title for the conversation in 5 words or less, without punctuation or quotation',\n },\n },\n required: ['language', 'title'],\n} as const;\n\nexport const createTitleRunnable = async (\n model: t.ChatModelInstance,\n _titlePrompt?: string\n): Promise<Runnable> => {\n // Disabled since this works fine\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /* @ts-ignore */\n const titleLLM = model.withStructuredOutput(titleSchema);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n /* @ts-ignore */\n const combinedLLM = model.withStructuredOutput(combinedSchema);\n\n const titlePrompt = ChatPromptTemplate.fromTemplate(\n _titlePrompt ?? defaultTitlePrompt\n ).withConfig({ runName: 'TitlePrompt' });\n\n const titleOnlyInnerChain = RunnableSequence.from([titlePrompt, titleLLM]);\n const combinedInnerChain = RunnableSequence.from([titlePrompt, combinedLLM]);\n\n /** Wrap titleOnlyChain in RunnableLambda to create parent span */\n const titleOnlyChain = new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ title: string }> => {\n const result = await titleOnlyInnerChain.invoke(input, config);\n return result as { title: string };\n },\n }).withConfig({ runName: 'TitleOnlyChain' });\n\n /** Wrap combinedChain in RunnableLambda to create parent span */\n const combinedChain = new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ language: string; title: string }> => {\n const result = await combinedInnerChain.invoke(input, config);\n return result as { language: string; title: string };\n },\n }).withConfig({ runName: 'TitleLanguageChain' });\n\n /** Runnable to add default values if needed */\n const addDefaults = new RunnableLambda({\n func: (\n result: { language: string; title: string } | undefined\n ): { language: string; title: string } => ({\n language: result?.language ?? 'English',\n title: result?.title ?? '',\n }),\n }).withConfig({ runName: 'AddDefaults' });\n\n const combinedChainInner = RunnableSequence.from([\n combinedChain,\n addDefaults,\n ]);\n\n /** Wrap combinedChainWithDefaults in RunnableLambda to create parent span */\n const combinedChainWithDefaults = new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ language: string; title: string }> => {\n return await combinedChainInner.invoke(input, config);\n },\n }).withConfig({ runName: 'CombinedChainWithDefaults' });\n\n return new RunnableLambda({\n func: async (\n input: {\n convo: string;\n inputText: string;\n skipLanguage: boolean;\n },\n config?: Partial<RunnableConfig>\n ): Promise<{ language: string; title: string } | { title: string }> => {\n const invokeInput = { convo: input.convo };\n\n if (input.skipLanguage) {\n return (await titleOnlyChain.invoke(invokeInput, config)) as {\n title: string;\n };\n }\n\n return await combinedChainWithDefaults.invoke(invokeInput, config);\n },\n }).withConfig({ runName: 'TitleGenerator' });\n};\n\nconst defaultCompletionPrompt = `Provide a concise, 5-word-or-less title for the conversation, using title case conventions. Only return the title itself.\n\nConversation:\n{convo}`;\n\nexport const createCompletionTitleRunnable = async (\n model: t.ChatModelInstance,\n titlePrompt?: string\n): Promise<Runnable> => {\n const completionPrompt = ChatPromptTemplate.fromTemplate(\n titlePrompt ?? defaultCompletionPrompt\n ).withConfig({ runName: 'CompletionTitlePrompt' });\n\n /** Runnable to extract content from model response */\n const extractContent = new RunnableLambda({\n func: (response: AIMessage): { title: string } => {\n let content = '';\n if (typeof response.content === 'string') {\n content = response.content;\n } else if (Array.isArray(response.content)) {\n content = response.content\n .filter(\n (part): part is { type: ContentTypes.TEXT; text: string } =>\n part.type === ContentTypes.TEXT\n )\n .map((part) => part.text)\n .join('');\n }\n return { title: content.trim() };\n },\n }).withConfig({ runName: 'ExtractTitle' });\n\n const innerChain = RunnableSequence.from([\n completionPrompt,\n model,\n extractContent,\n ]);\n\n /** Wrap in RunnableLambda to create a parent span for LangFuse */\n return new RunnableLambda({\n func: async (\n input: { convo: string },\n config?: Partial<RunnableConfig>\n ): Promise<{ title: string }> => {\n return await innerChain.invoke(input, config);\n },\n }).withConfig({ runName: 'CompletionTitleChain' });\n};\n"],"names":[],"mappings":";;;;AAOA,MAAM,kBAAkB,GAAG,CAAA;;;;QAInB;AAER,MAAM,WAAW,GAAG;AAClB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EACT,2FAA2F;AAC9F,SAAA;AACF,KAAA;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;CACX;AAEV,MAAM,cAAc,GAAG;AACrB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,QAAQ,EAAE;AACR,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EAAE,2CAA2C;AACzD,SAAA;AACD,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EACT,2FAA2F;AAC9F,SAAA;AACF,KAAA;AACD,IAAA,QAAQ,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;CACvB;AAEG,MAAA,mBAAmB,GAAG,OACjC,KAA0B,EAC1B,YAAqB,KACA;;;;IAIrB,MAAM,QAAQ,GAAG,KAAK,CAAC,oBAAoB,CAAC,WAAW,CAAC;;;IAGxD,MAAM,WAAW,GAAG,KAAK,CAAC,oBAAoB,CAAC,cAAc,CAAC;AAE9D,IAAA,MAAM,WAAW,GAAG,kBAAk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;gBAC1C,OAAO,GAAG,QAAQ,CAAC;AAChB,qBAAA,MAAM,CACL,CAAC,IAAI,KACH,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI;qBAElC,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;qBACvB,IAAI,CAAC,EAAE,CAAC;;YAEb,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE;SACjC;KACF,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1C,IAAA,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC;QACvC,gBAAgB;QAChB,KAAK;QACL,cAAc;AACf,KAAA,CAAC;;IAGF,OAAO,IAAI,cAAc,CAAC;AACxB,QAAA,IAAI,EAAE,OACJ,KAAwB,EACxB,MAAgC,KACF;YAC9B,OAAO,MAAM,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;SAC9C;KACF,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;AACpD;;;;"}
@@ -1,20 +1,6 @@
1
- import { z } from 'zod';
2
1
  import { DynamicStructuredTool } from '@langchain/core/tools';
3
2
  import type * as t from '@/types';
4
3
  export declare const imageExtRegex: RegExp;
5
4
  export declare const getCodeBaseURL: () => string;
6
- declare const CodeExecutionToolSchema: z.ZodObject<{
7
- lang: z.ZodEnum<["py", "js", "ts", "c", "cpp", "java", "php", "rs", "go", "d", "f90", "r"]>;
8
- code: z.ZodString;
9
- args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
- }, "strip", z.ZodTypeAny, {
11
- code: string;
12
- lang: "r" | "d" | "py" | "js" | "ts" | "c" | "cpp" | "java" | "php" | "rs" | "go" | "f90";
13
- args?: string[] | undefined;
14
- }, {
15
- code: string;
16
- lang: "r" | "d" | "py" | "js" | "ts" | "c" | "cpp" | "java" | "php" | "rs" | "go" | "f90";
17
- args?: string[] | undefined;
18
- }>;
19
- declare function createCodeExecutionTool(params?: t.CodeExecutionToolParams): DynamicStructuredTool<typeof CodeExecutionToolSchema>;
5
+ declare function createCodeExecutionTool(params?: t.CodeExecutionToolParams): DynamicStructuredTool;
20
6
  export { createCodeExecutionTool };
@@ -1,16 +1,5 @@
1
- import { z } from 'zod';
2
1
  import { DynamicStructuredTool } from '@langchain/core/tools';
3
2
  import type * as t from '@/types';
4
- declare const ProgrammaticToolCallingSchema: z.ZodObject<{
5
- code: z.ZodString;
6
- timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
7
- }, "strip", z.ZodTypeAny, {
8
- code: string;
9
- timeout: number;
10
- }, {
11
- code: string;
12
- timeout?: number | undefined;
13
- }>;
14
3
  /**
15
4
  * Normalizes a tool name to Python identifier format.
16
5
  * Must match the Code API's `normalizePythonFunctionName` exactly:
@@ -103,5 +92,4 @@ export declare function formatCompletedResponse(response: t.ProgrammaticExecutio
103
92
  * { configurable: { toolMap } }
104
93
  * );
105
94
  */
106
- export declare function createProgrammaticToolCallingTool(initParams?: t.ProgrammaticToolCallingParams): DynamicStructuredTool<typeof ProgrammaticToolCallingSchema>;
107
- export {};
95
+ export declare function createProgrammaticToolCallingTool(initParams?: t.ProgrammaticToolCallingParams): DynamicStructuredTool;
@@ -1,19 +1,5 @@
1
- import { z } from 'zod';
2
1
  import { DynamicStructuredTool } from '@langchain/core/tools';
3
2
  import type * as t from '@/types';
4
- /** Zod schema type for tool search parameters */
5
- type ToolSearchSchema = z.ZodObject<{
6
- query: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
- fields: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodEnum<['name', 'description', 'parameters']>>>>;
8
- max_results: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
9
- mcp_server: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString>]>>;
10
- }>;
11
- /**
12
- * Creates the Zod schema with dynamic query description based on mode.
13
- * @param mode - The search mode determining query interpretation
14
- * @returns Zod schema for tool search parameters
15
- */
16
- declare function createToolSearchSchema(mode: t.ToolSearchMode): ToolSearchSchema;
17
3
  /**
18
4
  * Extracts the MCP server name from a tool name.
19
5
  * MCP tools follow the pattern: toolName_mcp_serverName
@@ -144,5 +130,5 @@ declare function formatServerListing(tools: t.ToolMetadata[], serverNames: strin
144
130
  * const tool = createToolSearch({ mode: 'local', toolRegistry });
145
131
  * await tool.invoke({ query: 'expense' });
146
132
  */
147
- declare function createToolSearch(initParams?: t.ToolSearchParams): DynamicStructuredTool<ReturnType<typeof createToolSearchSchema>>;
133
+ declare function createToolSearch(initParams?: t.ToolSearchParams): DynamicStructuredTool;
148
134
  export { createToolSearch, performLocalSearch, extractMcpServerName, isFromMcpServer, isFromAnyMcpServer, normalizeServerFilter, getAvailableMcpServers, getDeferredToolsListing, getBaseToolName, formatServerListing, sanitizeRegex, escapeRegexSpecialChars, isDangerousPattern, countNestedGroups, hasNestedQuantifiers, };
@@ -1,4 +1,3 @@
1
- import { z } from 'zod';
2
1
  export declare enum DATE_RANGE {
3
2
  PAST_HOUR = "h",
4
3
  PAST_24_HOURS = "d",
@@ -8,9 +7,28 @@ export declare enum DATE_RANGE {
8
7
  }
9
8
  export declare const DEFAULT_QUERY_DESCRIPTION: string;
10
9
  export declare const DEFAULT_COUNTRY_DESCRIPTION: string;
11
- export declare const querySchema: z.ZodString;
12
- export declare const dateSchema: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
13
- export declare const countrySchema: z.ZodOptional<z.ZodString>;
14
- export declare const imagesSchema: z.ZodOptional<z.ZodBoolean>;
15
- export declare const videosSchema: z.ZodOptional<z.ZodBoolean>;
16
- export declare const newsSchema: z.ZodOptional<z.ZodBoolean>;
10
+ export declare const querySchema: {
11
+ readonly type: "string";
12
+ readonly description: string;
13
+ };
14
+ export declare const dateSchema: {
15
+ readonly type: "string";
16
+ readonly enum: DATE_RANGE[];
17
+ readonly description: "Date range for search results.";
18
+ };
19
+ export declare const countrySchema: {
20
+ readonly type: "string";
21
+ readonly description: string;
22
+ };
23
+ export declare const imagesSchema: {
24
+ readonly type: "boolean";
25
+ readonly description: "Whether to also run an image search.";
26
+ };
27
+ export declare const videosSchema: {
28
+ readonly type: "boolean";
29
+ readonly description: "Whether to also run a video search.";
30
+ };
31
+ export declare const newsSchema: {
32
+ readonly type: "boolean";
33
+ readonly description: "Whether to also run a news search.";
34
+ };
@@ -1,54 +1,3 @@
1
- import { z } from 'zod';
2
1
  import { DynamicStructuredTool } from '@langchain/core/tools';
3
2
  import type * as t from './types';
4
- import { DATE_RANGE } from './schema';
5
- /**
6
- * Creates a search tool with a schema that dynamically includes the country field
7
- * only when the searchProvider is 'serper'.
8
- *
9
- * Supports multiple scraper providers:
10
- * - Firecrawl (default): Full-featured web scraping with multiple formats
11
- * - Serper: Lightweight scraping using Serper's scrape API
12
- *
13
- * @example
14
- * ```typescript
15
- * // Using Firecrawl scraper (default)
16
- * const searchTool = createSearchTool({
17
- * searchProvider: 'serper',
18
- * scraperProvider: 'firecrawl',
19
- * firecrawlApiKey: 'your-firecrawl-key'
20
- * });
21
- *
22
- * // Using Serper scraper
23
- * const searchTool = createSearchTool({
24
- * searchProvider: 'serper',
25
- * scraperProvider: 'serper',
26
- * serperApiKey: 'your-serper-key'
27
- * });
28
- * ```
29
- *
30
- * @param config - The search tool configuration
31
- * @returns A DynamicStructuredTool with a schema that depends on the searchProvider
32
- */
33
- export declare const createSearchTool: (config?: t.SearchToolConfig) => DynamicStructuredTool<z.ZodObject<{
34
- query: z.ZodString;
35
- date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
36
- country?: z.ZodOptional<z.ZodString>;
37
- images: z.ZodOptional<z.ZodBoolean>;
38
- videos: z.ZodOptional<z.ZodBoolean>;
39
- news: z.ZodOptional<z.ZodBoolean>;
40
- }, "strip", z.ZodTypeAny, {
41
- query: string;
42
- videos?: boolean | undefined;
43
- images?: boolean | undefined;
44
- news?: boolean | undefined;
45
- date?: DATE_RANGE | undefined;
46
- country?: unknown;
47
- }, {
48
- query: string;
49
- videos?: boolean | undefined;
50
- images?: boolean | undefined;
51
- news?: boolean | undefined;
52
- date?: DATE_RANGE | undefined;
53
- country?: unknown;
54
- }>>;
3
+ export declare const createSearchTool: (config?: t.SearchToolConfig) => DynamicStructuredTool;
@@ -1,4 +1,3 @@
1
- import { z } from 'zod';
2
1
  import type { Logger as WinstonLogger } from 'winston';
3
2
  import type { RunnableConfig } from '@langchain/core/runnables';
4
3
  import type { BaseReranker } from './rerankers';
@@ -567,25 +566,8 @@ export type ProcessSourcesFields = {
567
566
  proMode: boolean;
568
567
  onGetHighlights: SearchToolConfig['onGetHighlights'];
569
568
  };
570
- export type SearchToolSchema = z.ZodObject<{
571
- query: z.ZodString;
572
- date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
573
- country?: z.ZodOptional<z.ZodString>;
574
- images: z.ZodOptional<z.ZodBoolean>;
575
- videos: z.ZodOptional<z.ZodBoolean>;
576
- news: z.ZodOptional<z.ZodBoolean>;
577
- }, 'strip', z.ZodTypeAny, {
578
- query: string;
579
- date?: DATE_RANGE;
580
- country?: unknown;
581
- images?: boolean;
582
- videos?: boolean;
583
- news?: boolean;
584
- }, {
585
- query: string;
586
- date?: DATE_RANGE;
587
- country?: unknown;
588
- images?: boolean;
589
- videos?: boolean;
590
- news?: boolean;
591
- }>;
569
+ export interface SearchToolSchema {
570
+ type: 'object';
571
+ properties: Record<string, unknown>;
572
+ required: string[];
573
+ }
@@ -4,3 +4,4 @@ export * from './misc';
4
4
  export * from './handlers';
5
5
  export * from './run';
6
6
  export * from './tokens';
7
+ export * from './schema';
@@ -0,0 +1,8 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ /** Checks if a schema is a Zod schema by looking for the _def property */
3
+ export declare function isZodSchema(schema: unknown): schema is ZodTypeAny;
4
+ /**
5
+ * Converts a schema to JSON schema format.
6
+ * Handles both Zod schemas (converts) and JSON schemas (passthrough).
7
+ */
8
+ export declare function toJsonSchema(schema: unknown, name?: string, description?: string): Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "3.1.00",
3
+ "version": "3.1.01",
4
4
  "main": "./dist/cjs/main.cjs",
5
5
  "module": "./dist/esm/main.mjs",
6
6
  "types": "./dist/types/index.d.ts",
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable no-console */
2
2
  // src/agents/AgentContext.ts
3
- import { zodToJsonSchema } from 'zod-to-json-schema';
4
3
  import { SystemMessage } from '@langchain/core/messages';
5
4
  import { RunnableLambda } from '@langchain/core/runnables';
6
5
  import type {
@@ -12,6 +11,7 @@ import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
12
11
  import type * as t from '@/types';
13
12
  import type { createPruneMessages } from '@/messages';
14
13
  import { ContentTypes, Providers } from '@/common';
14
+ import { toJsonSchema } from '@/utils/schema';
15
15
 
16
16
  /**
17
17
  * Encapsulates agent-specific state that can vary between agents in a multi-agent system
@@ -479,15 +479,10 @@ export class AgentContext {
479
479
  genericTool.schema != null &&
480
480
  typeof genericTool.schema === 'object'
481
481
  ) {
482
- const schema = genericTool.schema as {
483
- describe: (desc: string) => unknown;
484
- };
485
- const describedSchema = schema.describe(
486
- (genericTool.description as string) || ''
487
- );
488
- const jsonSchema = zodToJsonSchema(
489
- describedSchema as Parameters<typeof zodToJsonSchema>[0],
490
- (genericTool.name as string) || ''
482
+ const jsonSchema = toJsonSchema(
483
+ genericTool.schema,
484
+ (genericTool.name as string | undefined) ?? '',
485
+ (genericTool.description as string | undefined) ?? ''
491
486
  );
492
487
  toolTokens += tokenCounter(
493
488
  new SystemMessage(JSON.stringify(jsonSchema))
@@ -496,7 +491,6 @@ export class AgentContext {
496
491
  }
497
492
  }
498
493
 
499
- // Add tool tokens to existing instruction tokens (which may already include system message tokens)
500
494
  this.instructionTokens += toolTokens;
501
495
  }
502
496
 
@@ -1,4 +1,3 @@
1
- import { z } from 'zod';
2
1
  import { tool } from '@langchain/core/tools';
3
2
  import { PromptTemplate } from '@langchain/core/prompts';
4
3
  import {
@@ -292,7 +291,8 @@ export class MultiAgentGraph extends StandardGraph {
292
291
 
293
292
  tools.push(
294
293
  tool(
295
- async (input: Record<string, unknown>, config) => {
294
+ async (rawInput, config) => {
295
+ const input = rawInput as Record<string, unknown>;
296
296
  const state = getCurrentTaskInput() as t.BaseGraphState;
297
297
  const toolCallId =
298
298
  (config as ToolRunnableConfig | undefined)?.toolCall?.id ??
@@ -343,13 +343,17 @@ export class MultiAgentGraph extends StandardGraph {
343
343
  {
344
344
  name: toolName,
345
345
  schema: hasHandoffInput
346
- ? z.object({
347
- [promptKey]: z
348
- .string()
349
- .optional()
350
- .describe(handoffInputDescription as string),
351
- })
352
- : z.object({}),
346
+ ? {
347
+ type: 'object',
348
+ properties: {
349
+ [promptKey]: {
350
+ type: 'string',
351
+ description: handoffInputDescription as string,
352
+ },
353
+ },
354
+ required: [],
355
+ }
356
+ : { type: 'object', properties: {}, required: [] },
353
357
  description: toolDescription,
354
358
  }
355
359
  )
@@ -371,7 +375,8 @@ export class MultiAgentGraph extends StandardGraph {
371
375
 
372
376
  tools.push(
373
377
  tool(
374
- async (input: Record<string, unknown>, config) => {
378
+ async (rawInput, config) => {
379
+ const input = rawInput as Record<string, unknown>;
375
380
  const toolCallId =
376
381
  (config as ToolRunnableConfig | undefined)?.toolCall?.id ??
377
382
  'unknown';
@@ -470,13 +475,17 @@ export class MultiAgentGraph extends StandardGraph {
470
475
  {
471
476
  name: toolName,
472
477
  schema: hasHandoffInput
473
- ? z.object({
474
- [promptKey]: z
475
- .string()
476
- .optional()
477
- .describe(handoffInputDescription as string),
478
- })
479
- : z.object({}),
478
+ ? {
479
+ type: 'object',
480
+ properties: {
481
+ [promptKey]: {
482
+ type: 'string',
483
+ description: handoffInputDescription as string,
484
+ },
485
+ },
486
+ required: [],
487
+ }
488
+ : { type: 'object', properties: {}, required: [] },
480
489
  description: toolDescription,
481
490
  }
482
491
  )
@@ -1,5 +1,4 @@
1
1
  // src/specs/agent-handoffs.test.ts
2
- import { z } from 'zod';
3
2
  import { DynamicStructuredTool } from '@langchain/core/tools';
4
3
  import { HumanMessage, ToolMessage } from '@langchain/core/messages';
5
4
  import type { ToolCall } from '@langchain/core/messages/tool';
@@ -708,7 +707,7 @@ describe('Agent Handoffs Tests', () => {
708
707
  const customTool = new DynamicStructuredTool({
709
708
  name: 'custom_tool',
710
709
  description: 'A custom tool',
711
- schema: z.object({}),
710
+ schema: { type: 'object', properties: {}, required: [] },
712
711
  func: async (): Promise<string> => 'Tool result',
713
712
  });
714
713
 
@@ -1,4 +1,3 @@
1
- import { z } from 'zod';
2
1
  import { config } from 'dotenv';
3
2
  config();
4
3
  import { tool } from '@langchain/core/tools';
@@ -21,7 +20,13 @@ const errorTool = tool(
21
20
  {
22
21
  name: 'errorTool',
23
22
  description: 'A tool that always throws an error',
24
- schema: z.object({ input: z.string().optional() }),
23
+ schema: {
24
+ type: 'object',
25
+ properties: {
26
+ input: { type: 'string' },
27
+ },
28
+ required: [],
29
+ },
25
30
  }
26
31
  );
27
32
 
@@ -3,7 +3,6 @@
3
3
  * Shared mock tools for testing across all test scripts.
4
4
  * Centralizes tool definitions to follow DRY principles.
5
5
  */
6
- import { z } from 'zod';
7
6
  import { tool } from '@langchain/core/tools';
8
7
  import type { StructuredToolInterface } from '@langchain/core/tools';
9
8
  import type { LCTool, LCToolRegistry } from '@/types';
@@ -29,7 +28,7 @@ export function createGetTeamMembersTool(): StructuredToolInterface {
29
28
  name: 'get_team_members',
30
29
  description:
31
30
  'Get list of team members. Returns array of objects with id, name, and department fields.',
32
- schema: z.object({}),
31
+ schema: { type: 'object', properties: {}, required: [] },
33
32
  }
34
33
  );
35
34
  }
@@ -59,7 +58,8 @@ export function createGetExpensesTool(): StructuredToolInterface {
59
58
  };
60
59
 
61
60
  return tool(
62
- async ({ user_id }: { user_id: string }) => {
61
+ async (input) => {
62
+ const { user_id } = input as { user_id: string };
63
63
  await new Promise((resolve) => setTimeout(resolve, 30));
64
64
  return expenseData[user_id] ?? [];
65
65
  },
@@ -67,9 +67,16 @@ export function createGetExpensesTool(): StructuredToolInterface {
67
67
  name: 'get_expenses',
68
68
  description:
69
69
  'Get expense records for a user. Returns array of objects with amount and category fields.',
70
- schema: z.object({
71
- user_id: z.string().describe('The user ID to fetch expenses for'),
72
- }),
70
+ schema: {
71
+ type: 'object',
72
+ properties: {
73
+ user_id: {
74
+ type: 'string',
75
+ description: 'The user ID to fetch expenses for',
76
+ },
77
+ },
78
+ required: ['user_id'],
79
+ },
73
80
  }
74
81
  );
75
82
  }
@@ -91,7 +98,8 @@ export function createGetWeatherTool(): StructuredToolInterface {
91
98
  };
92
99
 
93
100
  return tool(
94
- async ({ city }: { city: string }) => {
101
+ async (input) => {
102
+ const { city } = input as { city: string };
95
103
  await new Promise((resolve) => setTimeout(resolve, 40));
96
104
  const weather = weatherData[city];
97
105
  if (!weather) {
@@ -103,9 +111,13 @@ export function createGetWeatherTool(): StructuredToolInterface {
103
111
  name: 'get_weather',
104
112
  description:
105
113
  'Get current weather for a city. Returns object with temperature (number) and condition (string) fields.',
106
- schema: z.object({
107
- city: z.string().describe('City name'),
108
- }),
114
+ schema: {
115
+ type: 'object',
116
+ properties: {
117
+ city: { type: 'string', description: 'City name' },
118
+ },
119
+ required: ['city'],
120
+ },
109
121
  }
110
122
  );
111
123
  }
@@ -115,7 +127,8 @@ export function createGetWeatherTool(): StructuredToolInterface {
115
127
  */
116
128
  export function createCalculatorTool(): StructuredToolInterface {
117
129
  return tool(
118
- async ({ expression }: { expression: string }) => {
130
+ async (input) => {
131
+ const { expression } = input as { expression: string };
119
132
  await new Promise((resolve) => setTimeout(resolve, 10));
120
133
  // Simple eval for demo (in production, use a proper math parser)
121
134
 
@@ -125,9 +138,16 @@ export function createCalculatorTool(): StructuredToolInterface {
125
138
  {
126
139
  name: 'calculator',
127
140
  description: 'Evaluate a mathematical expression',
128
- schema: z.object({
129
- expression: z.string().describe('Mathematical expression to evaluate'),
130
- }),
141
+ schema: {
142
+ type: 'object',
143
+ properties: {
144
+ expression: {
145
+ type: 'string',
146
+ description: 'Mathematical expression to evaluate',
147
+ },
148
+ },
149
+ required: ['expression'],
150
+ },
131
151
  }
132
152
  );
133
153
  }