@librechat/agents 3.1.0 → 3.1.2
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.
- package/dist/cjs/agents/AgentContext.cjs +2 -5
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +1 -0
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +26 -17
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -0
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +3 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +37 -27
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +21 -17
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +1 -0
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +37 -30
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +25 -23
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +9 -33
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/utils/schema.cjs +27 -0
- package/dist/cjs/utils/schema.cjs.map +1 -0
- package/dist/cjs/utils/title.cjs +28 -14
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +2 -5
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +1 -0
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +26 -17
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -0
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +37 -27
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +21 -17
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +1 -0
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +37 -30
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +25 -23
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +10 -34
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs +24 -0
- package/dist/esm/utils/schema.mjs.map +1 -0
- package/dist/esm/utils/title.mjs +28 -14
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/types/tools/CodeExecutor.d.ts +1 -15
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -13
- package/dist/types/tools/ToolSearch.d.ts +1 -15
- package/dist/types/tools/search/schema.d.ts +25 -7
- package/dist/types/tools/search/tool.d.ts +1 -52
- package/dist/types/tools/search/types.d.ts +5 -23
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/schema.d.ts +8 -0
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +5 -11
- package/src/graphs/MultiAgentGraph.ts +26 -17
- package/src/specs/agent-handoffs.test.ts +1 -2
- package/src/specs/azure.simple.test.ts +214 -175
- package/src/specs/tool-error.test.ts +7 -2
- package/src/test/mockTools.ts +34 -14
- package/src/tools/CodeExecutor.ts +48 -31
- package/src/tools/ProgrammaticToolCalling.ts +24 -23
- package/src/tools/ToolSearch.ts +54 -43
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +10 -9
- package/src/tools/__tests__/ToolSearch.integration.test.ts +10 -9
- package/src/tools/search/schema.ts +30 -25
- package/src/tools/search/tool.ts +23 -16
- package/src/tools/search/types.ts +5 -29
- package/src/utils/index.ts +1 -0
- package/src/utils/schema.ts +35 -0
- 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;;;;"}
|
package/dist/esm/utils/title.mjs
CHANGED
|
@@ -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 =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
1
|
+
{"version":3,"file":"title.mjs","sources":["../../../src/utils/title.ts"],"sourcesContent":["import { 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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AE;AACxC,gBAAA,OAAO,GAAG,QAAQ,CAAC,OAAO;;iBACrB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;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
|
|
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
|
|
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
|
|
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:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare const
|
|
16
|
-
|
|
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
|
-
|
|
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
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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
|
+
}
|
|
@@ -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,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
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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 (
|
|
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
|
-
?
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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 (
|
|
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
|
-
?
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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:
|
|
710
|
+
schema: { type: 'object', properties: {}, required: [] },
|
|
712
711
|
func: async (): Promise<string> => 'Tool result',
|
|
713
712
|
});
|
|
714
713
|
|