illuma-agents 1.0.10 → 1.0.11
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/LICENSE +1 -1
- package/dist/cjs/agents/AgentContext.cjs +228 -27
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +2 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +3 -11
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +27 -18
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +1 -3
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +1 -1
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +122 -7
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +1 -1
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +6 -6
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +1 -1
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +18 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +149 -54
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +85 -0
- package/dist/cjs/messages/tools.cjs.map +1 -0
- package/dist/cjs/run.cjs +0 -8
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +4 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +438 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +53 -15
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearchRegex.cjs +455 -0
- package/dist/cjs/tools/ToolSearchRegex.cjs.map +1 -0
- package/dist/cjs/tools/search/schema.cjs +7 -9
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +5 -1
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +228 -27
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +2 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +4 -12
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +27 -18
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +1 -3
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +1 -1
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +122 -7
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +1 -1
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +6 -6
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +1 -1
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +149 -54
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +82 -0
- package/dist/esm/messages/tools.mjs.map +1 -0
- package/dist/esm/run.mjs +0 -8
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +4 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +430 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +53 -15
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearchRegex.mjs +448 -0
- package/dist/esm/tools/ToolSearchRegex.mjs.map +1 -0
- package/dist/esm/tools/search/schema.mjs +7 -9
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +5 -1
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +65 -5
- package/dist/types/common/enum.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +31 -4
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +3 -3
- package/dist/types/llm/openrouter/index.d.ts +1 -1
- package/dist/types/messages/cache.d.ts +23 -8
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/messages/tools.d.ts +17 -0
- package/dist/types/test/mockTools.d.ts +28 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +91 -0
- package/dist/types/tools/ToolNode.d.ts +10 -2
- package/dist/types/tools/ToolSearchRegex.d.ts +80 -0
- package/dist/types/types/graph.d.ts +7 -1
- package/dist/types/types/tools.d.ts +138 -0
- package/package.json +7 -2
- package/src/agents/AgentContext.ts +267 -27
- package/src/agents/__tests__/AgentContext.test.ts +805 -0
- package/src/common/enum.ts +2 -0
- package/src/events.ts +5 -12
- package/src/graphs/Graph.ts +33 -19
- package/src/index.ts +2 -0
- package/src/instrumentation.ts +1 -4
- package/src/llm/anthropic/index.ts +2 -2
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +473 -0
- package/src/llm/bedrock/index.ts +150 -13
- package/src/llm/google/index.ts +2 -2
- package/src/llm/openai/index.ts +9 -9
- package/src/llm/openrouter/index.ts +2 -2
- package/src/messages/__tests__/tools.test.ts +473 -0
- package/src/messages/cache.ts +163 -61
- package/src/messages/index.ts +1 -0
- package/src/messages/tools.ts +99 -0
- package/src/run.ts +0 -9
- package/src/scripts/code_exec_ptc.ts +334 -0
- package/src/scripts/image.ts +178 -0
- package/src/scripts/programmatic_exec.ts +396 -0
- package/src/scripts/programmatic_exec_agent.ts +231 -0
- package/src/scripts/test-tools-before-handoff.ts +5 -1
- package/src/scripts/tool_search_regex.ts +162 -0
- package/src/scripts/tools.ts +4 -1
- package/src/specs/thinking-prune.test.ts +52 -118
- package/src/test/mockTools.ts +366 -0
- package/src/tools/CodeExecutor.ts +4 -0
- package/src/tools/ProgrammaticToolCalling.ts +558 -0
- package/src/tools/ToolNode.ts +59 -18
- package/src/tools/ToolSearchRegex.ts +535 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +318 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +853 -0
- package/src/tools/__tests__/ToolSearchRegex.integration.test.ts +161 -0
- package/src/tools/__tests__/ToolSearchRegex.test.ts +232 -0
- package/src/tools/search/jina-reranker.test.ts +16 -16
- package/src/tools/search/schema.ts +7 -9
- package/src/types/graph.ts +7 -1
- package/src/types/tools.ts +166 -0
- package/src/utils/run.ts +5 -1
- package/src/tools/search/direct-url.test.ts +0 -530
package/dist/esm/utils/run.mjs
CHANGED
|
@@ -28,8 +28,12 @@ class RunnableCallable extends Runnable {
|
|
|
28
28
|
}
|
|
29
29
|
async _tracedInvoke(input, config, runManager) {
|
|
30
30
|
return new Promise((resolve, reject) => {
|
|
31
|
+
// Defensive check: ensure runManager has getChild method before calling
|
|
32
|
+
const childCallbacks = typeof runManager?.getChild === 'function'
|
|
33
|
+
? runManager.getChild()
|
|
34
|
+
: undefined;
|
|
31
35
|
const childConfig = patchConfig(config, {
|
|
32
|
-
callbacks:
|
|
36
|
+
callbacks: childCallbacks,
|
|
33
37
|
});
|
|
34
38
|
void AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
|
|
35
39
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.mjs","sources":["../../../src/utils/run.ts"],"sourcesContent":["import { CallbackManagerForChainRun } from '@langchain/core/callbacks/manager';\nimport {\n mergeConfigs,\n patchConfig,\n Runnable,\n RunnableConfig,\n} from '@langchain/core/runnables';\nimport { AsyncLocalStorageProviderSingleton } from '@langchain/core/singletons';\n\n/**\n * Delays the execution for a specified number of milliseconds.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @return {Promise<void>} A promise that resolves after the specified delay.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface RunnableCallableArgs extends Partial<any> {\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n func: (...args: any[]) => any;\n tags?: string[];\n trace?: boolean;\n recurse?: boolean;\n}\n\nexport class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[] = ['langgraph'];\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n func: (...args: any[]) => any;\n\n tags?: string[];\n\n config?: RunnableConfig;\n\n trace: boolean = true;\n\n recurse: boolean = true;\n\n constructor(fields: RunnableCallableArgs) {\n super();\n this.name = fields.name ?? fields.func.name;\n this.func = fields.func;\n this.config = fields.tags ? { tags: fields.tags } : undefined;\n this.trace = fields.trace ?? this.trace;\n this.recurse = fields.recurse ?? this.recurse;\n }\n\n protected async _tracedInvoke(\n input: I,\n config?: Partial<RunnableConfig>,\n runManager?: CallbackManagerForChainRun\n ): Promise<O> {\n return new Promise<O>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks:
|
|
1
|
+
{"version":3,"file":"run.mjs","sources":["../../../src/utils/run.ts"],"sourcesContent":["import { CallbackManagerForChainRun } from '@langchain/core/callbacks/manager';\nimport {\n mergeConfigs,\n patchConfig,\n Runnable,\n RunnableConfig,\n} from '@langchain/core/runnables';\nimport { AsyncLocalStorageProviderSingleton } from '@langchain/core/singletons';\n\n/**\n * Delays the execution for a specified number of milliseconds.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @return {Promise<void>} A promise that resolves after the specified delay.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface RunnableCallableArgs extends Partial<any> {\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n func: (...args: any[]) => any;\n tags?: string[];\n trace?: boolean;\n recurse?: boolean;\n}\n\nexport class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {\n lc_namespace: string[] = ['langgraph'];\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n func: (...args: any[]) => any;\n\n tags?: string[];\n\n config?: RunnableConfig;\n\n trace: boolean = true;\n\n recurse: boolean = true;\n\n constructor(fields: RunnableCallableArgs) {\n super();\n this.name = fields.name ?? fields.func.name;\n this.func = fields.func;\n this.config = fields.tags ? { tags: fields.tags } : undefined;\n this.trace = fields.trace ?? this.trace;\n this.recurse = fields.recurse ?? this.recurse;\n }\n\n protected async _tracedInvoke(\n input: I,\n config?: Partial<RunnableConfig>,\n runManager?: CallbackManagerForChainRun\n ): Promise<O> {\n return new Promise<O>((resolve, reject) => {\n // Defensive check: ensure runManager has getChild method before calling\n const childCallbacks = typeof runManager?.getChild === 'function' \n ? runManager.getChild() \n : undefined;\n const childConfig = patchConfig(config, {\n callbacks: childCallbacks,\n });\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n childConfig,\n async () => {\n try {\n const output = await this.func(input, childConfig);\n resolve(output);\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n }\n\n async invoke(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n options?: Partial<RunnableConfig> | undefined\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let returnValue: any;\n\n if (this.trace) {\n returnValue = await this._callWithConfig(\n this._tracedInvoke,\n input,\n mergeConfigs(this.config, options)\n );\n } else {\n returnValue = await this.func(input, mergeConfigs(this.config, options));\n }\n\n if (Runnable.isRunnable(returnValue) && this.recurse) {\n return await returnValue.invoke(input, options);\n }\n\n return returnValue;\n }\n}"],"names":[],"mappings":";;;AASA;;;;;AAKG;AACG,SAAU,KAAK,CAAC,EAAU,EAAA;AAC9B,IAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC1D;AAYM,MAAO,gBAA2C,SAAQ,QAAc,CAAA;AAC5E,IAAA,YAAY,GAAa,CAAC,WAAW,CAAC;;AAGtC,IAAA,IAAI;AAEJ,IAAA,IAAI;AAEJ,IAAA,MAAM;IAEN,KAAK,GAAY,IAAI;IAErB,OAAO,GAAY,IAAI;AAEvB,IAAA,WAAA,CAAY,MAA4B,EAAA;AACtC,QAAA,KAAK,EAAE;AACP,QAAA,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI;AAC3C,QAAA,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,SAAS;QAC7D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;;AAGrC,IAAA,MAAM,aAAa,CAC3B,KAAQ,EACR,MAAgC,EAChC,UAAuC,EAAA;QAEvC,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,KAAI;;AAExC,YAAA,MAAM,cAAc,GAAG,OAAO,UAAU,EAAE,QAAQ,KAAK;AACrD,kBAAE,UAAU,CAAC,QAAQ;kBACnB,SAAS;AACb,YAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE;AACtC,gBAAA,SAAS,EAAE,cAAc;AAC1B,aAAA,CAAC;YACF,KAAK,kCAAkC,CAAC,aAAa,CACnD,WAAW,EACX,YAAW;AACT,gBAAA,IAAI;oBACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC;oBAClD,OAAO,CAAC,MAAM,CAAC;;gBACf,OAAO,CAAC,EAAE;oBACV,MAAM,CAAC,CAAC,CAAC;;AAEb,aAAC,CACF;AACH,SAAC,CAAC;;AAGJ,IAAA,MAAM,MAAM;;AAEV,IAAA,KAAU,EACV;;;;AAIA,QAAA,IAAI,WAAgB;AAEpB,QAAA,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,WAAW,GAAG,MAAM,IAAI,CAAC,eAAe,CACtC,IAAI,CAAC,aAAa,EAClB,KAAK,EACL,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CACnC;;aACI;AACL,YAAA,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;;QAG1E,IAAI,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;YACpD,OAAO,MAAM,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;;AAGjD,QAAA,OAAO,WAAW;;AAErB;;;;"}
|
|
@@ -38,6 +38,13 @@ export declare class AgentContext {
|
|
|
38
38
|
tools?: t.GraphTools;
|
|
39
39
|
/** Tool map for this agent */
|
|
40
40
|
toolMap?: t.ToolMap;
|
|
41
|
+
/**
|
|
42
|
+
* Tool definitions registry (includes deferred and programmatic tool metadata).
|
|
43
|
+
* Used for tool search and programmatic tool calling.
|
|
44
|
+
*/
|
|
45
|
+
toolRegistry?: t.LCToolRegistry;
|
|
46
|
+
/** Set of tool names discovered via tool search (to be loaded) */
|
|
47
|
+
discoveredToolNames: Set<string>;
|
|
41
48
|
/** Instructions for this agent */
|
|
42
49
|
instructions?: string;
|
|
43
50
|
/** Additional instructions for this agent */
|
|
@@ -52,13 +59,17 @@ export declare class AgentContext {
|
|
|
52
59
|
currentTokenType: ContentTypes.TEXT | ContentTypes.THINK | 'think_and_text';
|
|
53
60
|
/** Whether tools should end the workflow */
|
|
54
61
|
toolEnd: boolean;
|
|
55
|
-
/**
|
|
56
|
-
|
|
62
|
+
/** Cached system runnable (created lazily) */
|
|
63
|
+
private cachedSystemRunnable?;
|
|
64
|
+
/** Whether system runnable needs rebuild (set when discovered tools change) */
|
|
65
|
+
private systemRunnableStale;
|
|
66
|
+
/** Cached system message token count (separate from tool tokens) */
|
|
67
|
+
private systemMessageTokens;
|
|
57
68
|
/** Promise for token calculation initialization */
|
|
58
69
|
tokenCalculationPromise?: Promise<void>;
|
|
59
70
|
/** Format content blocks as strings (for legacy compatibility) */
|
|
60
71
|
useLegacyContent: boolean;
|
|
61
|
-
constructor({ agentId, provider, clientOptions, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, instructions, additionalInstructions, reasoningKey, toolEnd, instructionTokens, useLegacyContent, }: {
|
|
72
|
+
constructor({ agentId, provider, clientOptions, maxContextTokens, streamBuffer, tokenCounter, tools, toolMap, toolRegistry, instructions, additionalInstructions, reasoningKey, toolEnd, instructionTokens, useLegacyContent, }: {
|
|
62
73
|
agentId: string;
|
|
63
74
|
provider: Providers;
|
|
64
75
|
clientOptions?: t.ClientOptions;
|
|
@@ -67,6 +78,7 @@ export declare class AgentContext {
|
|
|
67
78
|
tokenCounter?: t.TokenCounter;
|
|
68
79
|
tools?: t.GraphTools;
|
|
69
80
|
toolMap?: t.ToolMap;
|
|
81
|
+
toolRegistry?: t.LCToolRegistry;
|
|
70
82
|
instructions?: string;
|
|
71
83
|
additionalInstructions?: string;
|
|
72
84
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
@@ -75,9 +87,35 @@ export declare class AgentContext {
|
|
|
75
87
|
useLegacyContent?: boolean;
|
|
76
88
|
});
|
|
77
89
|
/**
|
|
78
|
-
*
|
|
90
|
+
* Builds instructions text for tools that are ONLY callable via programmatic code execution.
|
|
91
|
+
* These tools cannot be called directly by the LLM but are available through the
|
|
92
|
+
* run_tools_with_code tool.
|
|
93
|
+
*
|
|
94
|
+
* Includes:
|
|
95
|
+
* - Code_execution-only tools that are NOT deferred
|
|
96
|
+
* - Code_execution-only tools that ARE deferred but have been discovered via tool search
|
|
97
|
+
*/
|
|
98
|
+
private buildProgrammaticOnlyToolsInstructions;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the system runnable, creating it lazily if needed.
|
|
101
|
+
* Includes instructions, additional instructions, and programmatic-only tools documentation.
|
|
102
|
+
* Only rebuilds when marked stale (via markToolsAsDiscovered).
|
|
103
|
+
*/
|
|
104
|
+
get systemRunnable(): Runnable<BaseMessage[], (BaseMessage | SystemMessage)[], RunnableConfig<Record<string, unknown>>> | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Explicitly initializes the system runnable.
|
|
107
|
+
* Call this before async token calculation to ensure system message tokens are counted first.
|
|
108
|
+
*/
|
|
109
|
+
initializeSystemRunnable(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Builds the raw instructions string (without creating SystemMessage).
|
|
79
112
|
*/
|
|
80
|
-
private
|
|
113
|
+
private buildInstructionsString;
|
|
114
|
+
/**
|
|
115
|
+
* Build system runnable from pre-built instructions string.
|
|
116
|
+
* Only called when content has actually changed.
|
|
117
|
+
*/
|
|
118
|
+
private buildSystemRunnable;
|
|
81
119
|
/**
|
|
82
120
|
* Reset context for a new run
|
|
83
121
|
*/
|
|
@@ -91,4 +129,26 @@ export declare class AgentContext {
|
|
|
91
129
|
* Note: System message tokens are calculated during systemRunnable creation
|
|
92
130
|
*/
|
|
93
131
|
calculateInstructionTokens(tokenCounter: t.TokenCounter): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Gets the tool registry for deferred tools (for tool search).
|
|
134
|
+
* @param onlyDeferred If true, only returns tools with defer_loading=true
|
|
135
|
+
* @returns LCToolRegistry with tool definitions
|
|
136
|
+
*/
|
|
137
|
+
getDeferredToolRegistry(onlyDeferred?: boolean): t.LCToolRegistry;
|
|
138
|
+
/**
|
|
139
|
+
* Marks tools as discovered via tool search.
|
|
140
|
+
* Discovered tools will be included in the next model binding.
|
|
141
|
+
* Only marks system runnable stale if NEW tools were actually added.
|
|
142
|
+
* @param toolNames - Array of discovered tool names
|
|
143
|
+
* @returns true if any new tools were discovered
|
|
144
|
+
*/
|
|
145
|
+
markToolsAsDiscovered(toolNames: string[]): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Gets tools that should be bound to the LLM.
|
|
148
|
+
* Includes:
|
|
149
|
+
* 1. Non-deferred tools with allowed_callers: ['direct']
|
|
150
|
+
* 2. Discovered tools (from tool search)
|
|
151
|
+
* @returns Array of tools to bind to model
|
|
152
|
+
*/
|
|
153
|
+
getToolsForBinding(): t.GraphTools | undefined;
|
|
94
154
|
}
|
|
@@ -114,6 +114,8 @@ export declare enum Callback {
|
|
|
114
114
|
export declare enum Constants {
|
|
115
115
|
OFFICIAL_CODE_BASEURL = "https://api.illuma.ai/v1",
|
|
116
116
|
EXECUTE_CODE = "execute_code",
|
|
117
|
+
TOOL_SEARCH_REGEX = "tool_search_regex",
|
|
118
|
+
PROGRAMMATIC_TOOL_CALLING = "run_tools_with_code",
|
|
117
119
|
WEB_SEARCH = "web_search",
|
|
118
120
|
CONTENT_AND_ARTIFACT = "content_and_artifact",
|
|
119
121
|
LC_TRANSFER_TO_ = "lc_transfer_to_"
|
|
@@ -91,9 +91,10 @@ export declare class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode>
|
|
|
91
91
|
instructions?: string;
|
|
92
92
|
additional_instructions?: string;
|
|
93
93
|
}): t.SystemRunnable | undefined;
|
|
94
|
-
initializeTools({ currentTools, currentToolMap, }: {
|
|
94
|
+
initializeTools({ currentTools, currentToolMap, agentContext, }: {
|
|
95
95
|
currentTools?: t.GraphTools;
|
|
96
96
|
currentToolMap?: t.ToolMap;
|
|
97
|
+
agentContext?: AgentContext;
|
|
97
98
|
}): CustomToolNode<t.BaseGraphState> | ToolNode<t.BaseGraphState>;
|
|
98
99
|
initializeModel({ provider, tools, clientOptions, }: {
|
|
99
100
|
provider: Providers;
|
|
@@ -109,7 +110,7 @@ export declare class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode>
|
|
|
109
110
|
/** Execute model invocation with streaming support */
|
|
110
111
|
private attemptInvoke;
|
|
111
112
|
cleanupSignalListener(currentModel?: t.ChatModel): void;
|
|
112
|
-
createCallModel(agentId?: string
|
|
113
|
+
createCallModel(agentId?: string): (state: t.BaseGraphState, config?: RunnableConfig) => Promise<Partial<t.BaseGraphState>>;
|
|
113
114
|
createAgentNode(agentId: string): t.CompiledAgentWorfklow;
|
|
114
115
|
createWorkflow(): t.CompiledStateWorkflow;
|
|
115
116
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from './messages';
|
|
|
6
6
|
export * from './graphs';
|
|
7
7
|
export * from './tools/Calculator';
|
|
8
8
|
export * from './tools/CodeExecutor';
|
|
9
|
+
export * from './tools/ProgrammaticToolCalling';
|
|
10
|
+
export * from './tools/ToolSearchRegex';
|
|
9
11
|
export * from './tools/handlers';
|
|
10
12
|
export * from './tools/search';
|
|
11
13
|
export * from './common';
|
|
@@ -21,7 +21,7 @@ export declare class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
21
21
|
private emitted_usage?;
|
|
22
22
|
top_k: number | undefined;
|
|
23
23
|
constructor(fields?: CustomAnthropicInput);
|
|
24
|
-
static lc_name(): '
|
|
24
|
+
static lc_name(): 'LibreChatAnthropic';
|
|
25
25
|
/**
|
|
26
26
|
* Get the parameters used to invoke the model
|
|
27
27
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Optimized ChatBedrockConverse wrapper that fixes contentBlockIndex conflicts
|
|
3
|
+
* and adds prompt caching support for Bedrock Converse API.
|
|
3
4
|
*
|
|
4
5
|
* Bedrock sends the same contentBlockIndex for both text and tool_use content blocks,
|
|
5
6
|
* causing LangChain's merge logic to fail with "field[contentBlockIndex] already exists"
|
|
@@ -9,19 +10,45 @@
|
|
|
9
10
|
* The contentBlockIndex field is only used internally by Bedrock's streaming protocol
|
|
10
11
|
* and isn't needed by application logic - the index field on tool_call_chunks serves
|
|
11
12
|
* the purpose of tracking tool call ordering.
|
|
13
|
+
*
|
|
14
|
+
* PROMPT CACHING:
|
|
15
|
+
* When promptCache: true is set, this wrapper adds cachePoint markers to the tools array
|
|
16
|
+
* to enable Bedrock prompt caching for tool definitions. This allows tool schemas to be
|
|
17
|
+
* cached and reused across requests, reducing latency and costs.
|
|
18
|
+
*
|
|
19
|
+
* CACHE TOKEN EXTRACTION:
|
|
20
|
+
* LangChain AWS doesn't extract cacheReadInputTokens/cacheWriteInputTokens from Bedrock's
|
|
21
|
+
* response. This wrapper adds input_token_details to usage_metadata with cache information.
|
|
12
22
|
*/
|
|
13
23
|
import { ChatBedrockConverse } from '@langchain/aws';
|
|
14
24
|
import type { ChatBedrockConverseInput } from '@langchain/aws';
|
|
15
25
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
16
26
|
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
17
27
|
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
28
|
+
/** Extended input type with promptCache option */
|
|
29
|
+
export interface CustomChatBedrockConverseInput extends ChatBedrockConverseInput {
|
|
30
|
+
promptCache?: boolean;
|
|
31
|
+
}
|
|
18
32
|
export declare class CustomChatBedrockConverse extends ChatBedrockConverse {
|
|
19
|
-
|
|
33
|
+
promptCache: boolean;
|
|
34
|
+
constructor(fields?: CustomChatBedrockConverseInput);
|
|
20
35
|
static lc_name(): string;
|
|
21
36
|
/**
|
|
22
|
-
* Override
|
|
23
|
-
* This
|
|
24
|
-
*
|
|
37
|
+
* Override invocationParams to add cachePoint to tools when promptCache is enabled.
|
|
38
|
+
* This enables Bedrock prompt caching for tool definitions.
|
|
39
|
+
*
|
|
40
|
+
* STRATEGY: Separate cachePoints for core tools and MCP tools
|
|
41
|
+
* - Core tools (web_search, execute_code, etc.) are stable → cache first
|
|
42
|
+
* - MCP tools (have '_mcp_' in name) are dynamic → cache separately after
|
|
43
|
+
* - This allows core tools to stay cached when MCP selection changes
|
|
44
|
+
*
|
|
45
|
+
* NOTE: Only Claude models support cachePoint - Nova and other models will reject it.
|
|
46
|
+
*/
|
|
47
|
+
invocationParams(options?: this['ParsedCallOptions']): ReturnType<ChatBedrockConverse['invocationParams']>;
|
|
48
|
+
/**
|
|
49
|
+
* Override _streamResponseChunks to:
|
|
50
|
+
* 1. Strip contentBlockIndex from response_metadata to prevent merge conflicts
|
|
51
|
+
* 2. Extract cacheReadInputTokens/cacheWriteInputTokens and add to usage_metadata
|
|
25
52
|
*/
|
|
26
53
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
27
54
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class CustomChatGoogleGenerativeAI extends ChatGoogleGenerativeAI
|
|
|
12
12
|
*/
|
|
13
13
|
get _isMultimodalModel(): boolean;
|
|
14
14
|
constructor(fields: GoogleClientOptions);
|
|
15
|
-
static lc_name(): '
|
|
15
|
+
static lc_name(): 'LibreChatGoogleGenerativeAI';
|
|
16
16
|
/**
|
|
17
17
|
* Helper function to convert Gemini API usage metadata to LangChain format
|
|
18
18
|
* Includes support for cached tokens and tier-based tracking for gemini-3-pro-preview
|
|
@@ -63,7 +63,7 @@ export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
|
63
63
|
_lc_stream_delay?: number;
|
|
64
64
|
});
|
|
65
65
|
get exposedClient(): CustomOpenAIClient;
|
|
66
|
-
static lc_name(): '
|
|
66
|
+
static lc_name(): 'LibreChatAzureOpenAI';
|
|
67
67
|
/**
|
|
68
68
|
* Returns backwards compatible reasoning parameters from constructor params and call options
|
|
69
69
|
* @internal
|
|
@@ -75,7 +75,7 @@ export declare class AzureChatOpenAI extends OriginalAzureChatOpenAI {
|
|
|
75
75
|
}
|
|
76
76
|
export declare class ChatDeepSeek extends OriginalChatDeepSeek {
|
|
77
77
|
get exposedClient(): CustomOpenAIClient;
|
|
78
|
-
static lc_name(): '
|
|
78
|
+
static lc_name(): 'LibreChatDeepSeek';
|
|
79
79
|
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
80
80
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
81
81
|
}
|
|
@@ -106,7 +106,7 @@ export declare class ChatXAI extends OriginalChatXAI {
|
|
|
106
106
|
};
|
|
107
107
|
_lc_stream_delay?: number;
|
|
108
108
|
});
|
|
109
|
-
static lc_name(): '
|
|
109
|
+
static lc_name(): 'LibreChatXAI';
|
|
110
110
|
get exposedClient(): CustomOpenAIClient;
|
|
111
111
|
protected _getClientOptions(options?: OpenAICoreRequestOptions): OpenAICoreRequestOptions;
|
|
112
112
|
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
@@ -9,7 +9,7 @@ export interface ChatOpenRouterCallOptions extends ChatOpenAICallOptions {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class ChatOpenRouter extends ChatOpenAI {
|
|
11
11
|
constructor(_fields: Partial<ChatOpenRouterCallOptions>);
|
|
12
|
-
static lc_name(): '
|
|
12
|
+
static lc_name(): 'LibreChatOpenRouter';
|
|
13
13
|
protected _convertOpenAIDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: 'function' | 'user' | 'system' | 'developer' | 'assistant' | 'tool'): AIMessageChunk | HumanMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
|
14
14
|
_streamResponseChunks2(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
15
15
|
}
|
|
@@ -23,14 +23,29 @@ export declare function stripAnthropicCacheControl<T extends MessageWithContent>
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function stripBedrockCacheControl<T extends MessageWithContent>(messages: T[]): T[];
|
|
25
25
|
/**
|
|
26
|
-
* Adds Bedrock Converse API cache points
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
26
|
+
* Adds Bedrock Converse API cache points using "Stable Prefix Caching" strategy.
|
|
27
|
+
*
|
|
28
|
+
* STRATEGY: Place cache point after the LAST ASSISTANT message only.
|
|
29
|
+
* This ensures the prefix (everything before the cache point) remains STABLE
|
|
30
|
+
* as the conversation grows, maximizing cache hits.
|
|
31
|
+
*
|
|
32
|
+
* Why this works:
|
|
33
|
+
* - System message has its own cachePoint (added in AgentContext)
|
|
34
|
+
* - Tools have their own cachePoint (added in CustomChatBedrockConverse)
|
|
35
|
+
* - Conversation history grows, but the PREFIX stays the same
|
|
36
|
+
* - Only the NEW user message is uncached (it's always different)
|
|
37
|
+
*
|
|
38
|
+
* Example conversation flow:
|
|
39
|
+
* Request 1: [System+cachePoint][Tools+cachePoint][User1] → No conversation cache yet
|
|
40
|
+
* Request 2: [System][Tools][User1][Assistant1+cachePoint][User2] → Cache User1+Assistant1
|
|
41
|
+
* Request 3: [System][Tools][User1][Assistant1][User2][Assistant2+cachePoint][User3]
|
|
42
|
+
* → Cache reads User1+A1+User2+A2, cache writes new portion
|
|
43
|
+
*
|
|
44
|
+
* Claude's "Simplified Cache Management" automatically looks back up to 20 content
|
|
45
|
+
* blocks from the cache checkpoint to find the longest matching prefix.
|
|
46
|
+
*
|
|
47
|
+
* @param messages - The array of message objects (excluding system message).
|
|
48
|
+
* @returns - The updated array with a single cache point after the last assistant message.
|
|
34
49
|
*/
|
|
35
50
|
export declare function addBedrockCacheControl<T extends Partial<BaseMessage> & MessageWithContent>(messages: T[]): T[];
|
|
36
51
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts discovered tool names from tool search results in the current turn.
|
|
4
|
+
* Only processes tool search messages after the latest AI message with tool calls.
|
|
5
|
+
*
|
|
6
|
+
* Similar pattern to formatArtifactPayload - finds relevant messages efficiently
|
|
7
|
+
* by identifying the latest AI parent and only processing subsequent tool messages.
|
|
8
|
+
*
|
|
9
|
+
* @param messages - All messages in the conversation
|
|
10
|
+
* @returns Array of discovered tool names (empty if no new discoveries)
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractToolDiscoveries(messages: BaseMessage[]): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the current turn has any tool search results.
|
|
15
|
+
* Quick check to avoid full extraction when not needed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hasToolSearchInCurrentTurn(messages: BaseMessage[]): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
2
|
+
import type { LCToolRegistry } from '@/types';
|
|
3
|
+
/**
|
|
4
|
+
* Mock get_team_members tool - returns list of team members
|
|
5
|
+
*/
|
|
6
|
+
export declare function createGetTeamMembersTool(): StructuredToolInterface;
|
|
7
|
+
/**
|
|
8
|
+
* Mock get_expenses tool - returns expense records for a user
|
|
9
|
+
*/
|
|
10
|
+
export declare function createGetExpensesTool(): StructuredToolInterface;
|
|
11
|
+
/**
|
|
12
|
+
* Mock get_weather tool - returns weather data for a city
|
|
13
|
+
*/
|
|
14
|
+
export declare function createGetWeatherTool(): StructuredToolInterface;
|
|
15
|
+
/**
|
|
16
|
+
* Mock calculator tool - evaluates mathematical expressions
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCalculatorTool(): StructuredToolInterface;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a tool registry for programmatic tool calling tests.
|
|
21
|
+
* Tools are configured with allowed_callers to demonstrate classification.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createProgrammaticToolRegistry(): LCToolRegistry;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a sample tool registry for tool search tests.
|
|
26
|
+
* Includes mix of deferred and non-deferred tools.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createToolSearchToolRegistry(): LCToolRegistry;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
+
import type * as t from '@/types';
|
|
4
|
+
declare const ProgrammaticToolCallingSchema: z.ZodObject<{
|
|
5
|
+
code: z.ZodString;
|
|
6
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
7
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
code: string;
|
|
10
|
+
timeout: number;
|
|
11
|
+
session_id?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
code: string;
|
|
14
|
+
timeout?: number | undefined;
|
|
15
|
+
session_id?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes a tool name to Python identifier format.
|
|
19
|
+
* Must match the Code API's `normalizePythonFunctionName` exactly:
|
|
20
|
+
* 1. Replace hyphens and spaces with underscores
|
|
21
|
+
* 2. Remove any other invalid characters
|
|
22
|
+
* 3. Prefix with underscore if starts with number
|
|
23
|
+
* 4. Append `_tool` if it's a Python keyword
|
|
24
|
+
* @param name - The tool name to normalize
|
|
25
|
+
* @returns Normalized Python-safe identifier
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeToPythonIdentifier(name: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Extracts tool names that are actually called in the Python code.
|
|
30
|
+
* Handles hyphen/underscore conversion since Python identifiers use underscores.
|
|
31
|
+
* @param code - The Python code to analyze
|
|
32
|
+
* @param toolNameMap - Map from normalized Python name to original tool name
|
|
33
|
+
* @returns Set of original tool names found in the code
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractUsedToolNames(code: string, toolNameMap: Map<string, string>): Set<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Filters tool definitions to only include tools actually used in the code.
|
|
38
|
+
* Handles the hyphen-to-underscore conversion for Python compatibility.
|
|
39
|
+
* @param toolDefs - All available tool definitions
|
|
40
|
+
* @param code - The Python code to analyze
|
|
41
|
+
* @param debug - Enable debug logging
|
|
42
|
+
* @returns Filtered array of tool definitions
|
|
43
|
+
*/
|
|
44
|
+
export declare function filterToolsByUsage(toolDefs: t.LCTool[], code: string, debug?: boolean): t.LCTool[];
|
|
45
|
+
/**
|
|
46
|
+
* Makes an HTTP request to the Code API.
|
|
47
|
+
* @param endpoint - The API endpoint URL
|
|
48
|
+
* @param apiKey - The API key for authentication
|
|
49
|
+
* @param body - The request body
|
|
50
|
+
* @param proxy - Optional HTTP proxy URL
|
|
51
|
+
* @returns The parsed API response
|
|
52
|
+
*/
|
|
53
|
+
export declare function makeRequest(endpoint: string, apiKey: string, body: Record<string, unknown>, proxy?: string): Promise<t.ProgrammaticExecutionResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* Executes tools in parallel when requested by the API.
|
|
56
|
+
* Uses Promise.all for parallel execution, catching individual errors.
|
|
57
|
+
* @param toolCalls - Array of tool calls from the API
|
|
58
|
+
* @param toolMap - Map of tool names to executable tools
|
|
59
|
+
* @returns Array of tool results
|
|
60
|
+
*/
|
|
61
|
+
export declare function executeTools(toolCalls: t.PTCToolCall[], toolMap: t.ToolMap): Promise<t.PTCToolResult[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Formats the completed response for the agent.
|
|
64
|
+
* @param response - The completed API response
|
|
65
|
+
* @returns Tuple of [formatted string, artifact]
|
|
66
|
+
*/
|
|
67
|
+
export declare function formatCompletedResponse(response: t.ProgrammaticExecutionResponse): [string, t.ProgrammaticExecutionArtifact];
|
|
68
|
+
/**
|
|
69
|
+
* Creates a Programmatic Tool Calling tool for complex multi-tool workflows.
|
|
70
|
+
*
|
|
71
|
+
* This tool enables AI agents to write Python code that orchestrates multiple
|
|
72
|
+
* tool calls programmatically, reducing LLM round-trips and token usage.
|
|
73
|
+
*
|
|
74
|
+
* The tool map must be provided at runtime via config.configurable.toolMap.
|
|
75
|
+
*
|
|
76
|
+
* @param params - Configuration parameters (apiKey, baseUrl, maxRoundTrips, proxy)
|
|
77
|
+
* @returns A LangChain DynamicStructuredTool for programmatic tool calling
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const ptcTool = createProgrammaticToolCallingTool({
|
|
81
|
+
* apiKey: process.env.CODE_API_KEY,
|
|
82
|
+
* maxRoundTrips: 20
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* const [output, artifact] = await ptcTool.invoke(
|
|
86
|
+
* { code, tools },
|
|
87
|
+
* { configurable: { toolMap } }
|
|
88
|
+
* );
|
|
89
|
+
*/
|
|
90
|
+
export declare function createProgrammaticToolCallingTool(initParams?: t.ProgrammaticToolCallingParams): DynamicStructuredTool<typeof ProgrammaticToolCallingSchema>;
|
|
91
|
+
export {};
|
|
@@ -5,7 +5,6 @@ import type { BaseMessage } from '@langchain/core/messages';
|
|
|
5
5
|
import type * as t from '@/types';
|
|
6
6
|
import { RunnableCallable } from '@/utils';
|
|
7
7
|
export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
8
|
-
tools: t.GenericTool[];
|
|
9
8
|
private toolMap;
|
|
10
9
|
private loadRuntimeTools?;
|
|
11
10
|
handleToolErrors: boolean;
|
|
@@ -13,7 +12,16 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
13
12
|
toolCallStepIds?: Map<string, string>;
|
|
14
13
|
errorHandler?: t.ToolNodeConstructorParams['errorHandler'];
|
|
15
14
|
private toolUsageCount;
|
|
16
|
-
|
|
15
|
+
/** Tool registry for filtering (lazy computation of programmatic maps) */
|
|
16
|
+
private toolRegistry?;
|
|
17
|
+
/** Cached programmatic tools (computed once on first PTC call) */
|
|
18
|
+
private programmaticCache?;
|
|
19
|
+
constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, }: t.ToolNodeConstructorParams);
|
|
20
|
+
/**
|
|
21
|
+
* Returns cached programmatic tools, computing once on first access.
|
|
22
|
+
* Single iteration builds both toolMap and toolDefs simultaneously.
|
|
23
|
+
*/
|
|
24
|
+
private getProgrammaticTools;
|
|
17
25
|
/**
|
|
18
26
|
* Returns a snapshot of the current tool usage counts.
|
|
19
27
|
* @returns A ReadonlyMap where keys are tool names and values are their usage counts.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
+
import type * as t from '@/types';
|
|
4
|
+
declare const ToolSearchRegexSchema: z.ZodObject<{
|
|
5
|
+
query: z.ZodString;
|
|
6
|
+
fields: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodEnum<["name", "description", "parameters"]>, "many">>>;
|
|
7
|
+
max_results: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
query: string;
|
|
10
|
+
fields: ("name" | "description" | "parameters")[];
|
|
11
|
+
max_results: number;
|
|
12
|
+
}, {
|
|
13
|
+
query: string;
|
|
14
|
+
fields?: ("name" | "description" | "parameters")[] | undefined;
|
|
15
|
+
max_results?: number | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Escapes special regex characters in a string to use as a literal pattern.
|
|
19
|
+
* @param pattern - The string to escape
|
|
20
|
+
* @returns The escaped string safe for use in a RegExp
|
|
21
|
+
*/
|
|
22
|
+
declare function escapeRegexSpecialChars(pattern: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Counts the maximum nesting depth of groups in a regex pattern.
|
|
25
|
+
* @param pattern - The regex pattern to analyze
|
|
26
|
+
* @returns The maximum nesting depth
|
|
27
|
+
*/
|
|
28
|
+
declare function countNestedGroups(pattern: string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Detects nested quantifiers that can cause catastrophic backtracking.
|
|
31
|
+
* Patterns like (a+)+, (a*)*, (a+)*, etc.
|
|
32
|
+
* @param pattern - The regex pattern to check
|
|
33
|
+
* @returns True if nested quantifiers are detected
|
|
34
|
+
*/
|
|
35
|
+
declare function hasNestedQuantifiers(pattern: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a regex pattern contains potentially dangerous constructs.
|
|
38
|
+
* @param pattern - The regex pattern to validate
|
|
39
|
+
* @returns True if the pattern is dangerous
|
|
40
|
+
*/
|
|
41
|
+
declare function isDangerousPattern(pattern: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Sanitizes a regex pattern for safe execution.
|
|
44
|
+
* If the pattern is dangerous, it will be escaped to a literal string search.
|
|
45
|
+
* @param pattern - The regex pattern to sanitize
|
|
46
|
+
* @returns Object containing the safe pattern and whether it was escaped
|
|
47
|
+
*/
|
|
48
|
+
declare function sanitizeRegex(pattern: string): {
|
|
49
|
+
safe: string;
|
|
50
|
+
wasEscaped: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Creates a Tool Search Regex tool for discovering tools from a large registry.
|
|
54
|
+
*
|
|
55
|
+
* This tool enables AI agents to dynamically discover tools from a large library
|
|
56
|
+
* without loading all tool definitions into the LLM context window. The agent
|
|
57
|
+
* can search for relevant tools on-demand using regex patterns.
|
|
58
|
+
*
|
|
59
|
+
* The tool registry can be provided either:
|
|
60
|
+
* 1. At initialization time via params.toolRegistry
|
|
61
|
+
* 2. At runtime via config.configurable.toolRegistry when invoking
|
|
62
|
+
*
|
|
63
|
+
* @param params - Configuration parameters for the tool (toolRegistry is optional)
|
|
64
|
+
* @returns A LangChain DynamicStructuredTool for tool searching
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Option 1: Registry at initialization
|
|
68
|
+
* const tool = createToolSearchRegexTool({ apiKey, toolRegistry });
|
|
69
|
+
* await tool.invoke({ query: 'expense' });
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Option 2: Registry at runtime
|
|
73
|
+
* const tool = createToolSearchRegexTool({ apiKey });
|
|
74
|
+
* await tool.invoke(
|
|
75
|
+
* { query: 'expense' },
|
|
76
|
+
* { configurable: { toolRegistry, onlyDeferred: true } }
|
|
77
|
+
* );
|
|
78
|
+
*/
|
|
79
|
+
declare function createToolSearchRegexTool(initParams?: t.ToolSearchRegexParams): DynamicStructuredTool<typeof ToolSearchRegexSchema>;
|
|
80
|
+
export { createToolSearchRegexTool, sanitizeRegex, escapeRegexSpecialChars, isDangerousPattern, countNestedGroups, hasNestedQuantifiers, };
|
|
@@ -4,7 +4,7 @@ import type { BaseMessage, AIMessageChunk, SystemMessage } from '@langchain/core
|
|
|
4
4
|
import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
|
|
5
5
|
import type { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
6
6
|
import type { GoogleAIToolType } from '@langchain/google-common';
|
|
7
|
-
import type { ToolMap, ToolEndEvent, GenericTool } from '@/types/tools';
|
|
7
|
+
import type { ToolMap, ToolEndEvent, GenericTool, LCTool } from '@/types/tools';
|
|
8
8
|
import type { Providers, Callback, GraphNodeKeys } from '@/common';
|
|
9
9
|
import type { StandardGraph, MultiAgentGraph } from '@/graphs';
|
|
10
10
|
import type { ClientOptions } from '@/types/llm';
|
|
@@ -248,4 +248,10 @@ export interface AgentInputs {
|
|
|
248
248
|
reasoningKey?: 'reasoning_content' | 'reasoning';
|
|
249
249
|
/** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
|
|
250
250
|
useLegacyContent?: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Tool definitions for all tools, including deferred and programmatic.
|
|
253
|
+
* Used for tool search and programmatic tool calling.
|
|
254
|
+
* Maps tool name to LCTool definition.
|
|
255
|
+
*/
|
|
256
|
+
toolRegistry?: Map<string, LCTool>;
|
|
251
257
|
}
|