@librechat/agents 3.1.67-dev.4 → 3.1.68
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 +3 -23
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +0 -16
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +0 -91
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +36 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/main.cjs +1 -53
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +12 -74
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/run.cjs +0 -111
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs +41 -0
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +121 -63
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +140 -304
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +3 -23
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +1 -15
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +0 -91
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +36 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -13
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +4 -66
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/run.mjs +0 -111
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +41 -1
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +121 -63
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +142 -306
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +0 -6
- package/dist/types/common/enum.d.ts +1 -10
- package/dist/types/graphs/Graph.d.ts +0 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +12 -0
- package/dist/types/index.d.ts +0 -8
- package/dist/types/messages/format.d.ts +1 -2
- package/dist/types/run.d.ts +0 -1
- package/dist/types/summarization/index.d.ts +2 -0
- package/dist/types/summarization/node.d.ts +0 -2
- package/dist/types/tools/ToolNode.d.ts +2 -24
- package/dist/types/types/graph.d.ts +2 -61
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/run.d.ts +0 -20
- package/dist/types/types/tools.d.ts +1 -38
- package/package.json +1 -5
- package/src/agents/AgentContext.ts +2 -26
- package/src/common/enum.ts +0 -15
- package/src/graphs/Graph.ts +0 -113
- package/src/graphs/MultiAgentGraph.ts +39 -0
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +91 -0
- package/src/index.ts +0 -10
- package/src/messages/format.ts +4 -74
- package/src/run.ts +0 -126
- package/src/summarization/__tests__/node.test.ts +42 -0
- package/src/summarization/__tests__/trigger.test.ts +100 -1
- package/src/summarization/index.ts +47 -0
- package/src/summarization/node.ts +149 -77
- package/src/tools/ToolNode.ts +169 -391
- package/src/tools/__tests__/ToolNode.session.test.ts +12 -12
- package/src/types/graph.ts +1 -80
- package/src/types/index.ts +0 -1
- package/src/types/run.ts +0 -20
- package/src/types/tools.ts +1 -41
- package/dist/cjs/hooks/HookRegistry.cjs +0 -162
- package/dist/cjs/hooks/HookRegistry.cjs.map +0 -1
- package/dist/cjs/hooks/executeHooks.cjs +0 -276
- package/dist/cjs/hooks/executeHooks.cjs.map +0 -1
- package/dist/cjs/hooks/matchers.cjs +0 -256
- package/dist/cjs/hooks/matchers.cjs.map +0 -1
- package/dist/cjs/hooks/types.cjs +0 -27
- package/dist/cjs/hooks/types.cjs.map +0 -1
- package/dist/cjs/tools/BashExecutor.cjs +0 -175
- package/dist/cjs/tools/BashExecutor.cjs.map +0 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -296
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +0 -1
- package/dist/cjs/tools/ReadFile.cjs +0 -43
- package/dist/cjs/tools/ReadFile.cjs.map +0 -1
- package/dist/cjs/tools/SkillTool.cjs +0 -50
- package/dist/cjs/tools/SkillTool.cjs.map +0 -1
- package/dist/cjs/tools/SubagentTool.cjs +0 -92
- package/dist/cjs/tools/SubagentTool.cjs.map +0 -1
- package/dist/cjs/tools/skillCatalog.cjs +0 -84
- package/dist/cjs/tools/skillCatalog.cjs.map +0 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +0 -511
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +0 -1
- package/dist/esm/hooks/HookRegistry.mjs +0 -160
- package/dist/esm/hooks/HookRegistry.mjs.map +0 -1
- package/dist/esm/hooks/executeHooks.mjs +0 -273
- package/dist/esm/hooks/executeHooks.mjs.map +0 -1
- package/dist/esm/hooks/matchers.mjs +0 -251
- package/dist/esm/hooks/matchers.mjs.map +0 -1
- package/dist/esm/hooks/types.mjs +0 -25
- package/dist/esm/hooks/types.mjs.map +0 -1
- package/dist/esm/tools/BashExecutor.mjs +0 -169
- package/dist/esm/tools/BashExecutor.mjs.map +0 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -287
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +0 -1
- package/dist/esm/tools/ReadFile.mjs +0 -38
- package/dist/esm/tools/ReadFile.mjs.map +0 -1
- package/dist/esm/tools/SkillTool.mjs +0 -45
- package/dist/esm/tools/SkillTool.mjs.map +0 -1
- package/dist/esm/tools/SubagentTool.mjs +0 -85
- package/dist/esm/tools/SubagentTool.mjs.map +0 -1
- package/dist/esm/tools/skillCatalog.mjs +0 -82
- package/dist/esm/tools/skillCatalog.mjs.map +0 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +0 -505
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +0 -1
- package/dist/types/hooks/HookRegistry.d.ts +0 -56
- package/dist/types/hooks/executeHooks.d.ts +0 -79
- package/dist/types/hooks/index.d.ts +0 -6
- package/dist/types/hooks/matchers.d.ts +0 -95
- package/dist/types/hooks/types.d.ts +0 -320
- package/dist/types/tools/BashExecutor.d.ts +0 -45
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +0 -72
- package/dist/types/tools/ReadFile.d.ts +0 -28
- package/dist/types/tools/SkillTool.d.ts +0 -40
- package/dist/types/tools/SubagentTool.d.ts +0 -36
- package/dist/types/tools/skillCatalog.d.ts +0 -19
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +0 -137
- package/dist/types/tools/subagent/index.d.ts +0 -2
- package/dist/types/types/skill.d.ts +0 -9
- package/src/hooks/HookRegistry.ts +0 -208
- package/src/hooks/__tests__/HookRegistry.test.ts +0 -190
- package/src/hooks/__tests__/compactHooks.test.ts +0 -214
- package/src/hooks/__tests__/executeHooks.test.ts +0 -1013
- package/src/hooks/__tests__/integration.test.ts +0 -337
- package/src/hooks/__tests__/matchers.test.ts +0 -238
- package/src/hooks/__tests__/toolHooks.test.ts +0 -669
- package/src/hooks/executeHooks.ts +0 -375
- package/src/hooks/index.ts +0 -57
- package/src/hooks/matchers.ts +0 -280
- package/src/hooks/types.ts +0 -404
- package/src/messages/formatAgentMessages.skills.test.ts +0 -334
- package/src/scripts/multi-agent-subagent.ts +0 -246
- package/src/scripts/subagent-event-driven-debug.ts +0 -190
- package/src/scripts/subagent-tools-debug.ts +0 -160
- package/src/specs/subagent.test.ts +0 -305
- package/src/tools/BashExecutor.ts +0 -205
- package/src/tools/BashProgrammaticToolCalling.ts +0 -397
- package/src/tools/ReadFile.ts +0 -39
- package/src/tools/SkillTool.ts +0 -46
- package/src/tools/SubagentTool.ts +0 -100
- package/src/tools/__tests__/ReadFile.test.ts +0 -44
- package/src/tools/__tests__/SkillTool.test.ts +0 -442
- package/src/tools/__tests__/SubagentExecutor.test.ts +0 -1148
- package/src/tools/__tests__/SubagentTool.test.ts +0 -149
- package/src/tools/__tests__/skillCatalog.test.ts +0 -161
- package/src/tools/__tests__/subagentHooks.test.ts +0 -215
- package/src/tools/skillCatalog.ts +0 -126
- package/src/tools/subagent/SubagentExecutor.ts +0 -676
- package/src/tools/subagent/index.ts +0 -13
- package/src/types/skill.ts +0 -11
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
2
2
|
import type { RunnableToolLike } from '@langchain/core/runnables';
|
|
3
3
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
4
|
-
import type {
|
|
5
|
-
import type { MessageContentComplex, ToolErrorData } from './stream';
|
|
4
|
+
import type { ToolErrorData } from './stream';
|
|
6
5
|
import { EnvVar } from '@/common';
|
|
7
6
|
/** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
|
|
8
7
|
export type CustomToolCall = {
|
|
@@ -40,12 +39,6 @@ export type ToolNodeOptions = {
|
|
|
40
39
|
agentId?: string;
|
|
41
40
|
/** Tool names that must be executed directly (via runTool) even in event-driven mode (e.g., graph-managed handoff tools) */
|
|
42
41
|
directToolNames?: Set<string>;
|
|
43
|
-
/**
|
|
44
|
-
* Hook registry for PreToolUse/PostToolUse lifecycle hooks.
|
|
45
|
-
* Only fires for event-driven tool calls (`dispatchToolEvents`). Tools
|
|
46
|
-
* routed through `directToolNames` bypass hook dispatch entirely.
|
|
47
|
-
*/
|
|
48
|
-
hookRegistry?: HookRegistry;
|
|
49
42
|
/** Max context tokens for the agent — used to compute tool result truncation limits. */
|
|
50
43
|
maxContextTokens?: number;
|
|
51
44
|
/**
|
|
@@ -161,25 +154,6 @@ export type ToolExecuteBatchRequest = {
|
|
|
161
154
|
/** Promise rejector - handler calls this on fatal error */
|
|
162
155
|
reject: (error: Error) => void;
|
|
163
156
|
};
|
|
164
|
-
/**
|
|
165
|
-
* A message injected into graph state by any tool execution handler.
|
|
166
|
-
* Generic mechanism: any tool returning `injectedMessages` in its `ToolExecuteResult`
|
|
167
|
-
* will have these appended to state after the ToolMessage for this call.
|
|
168
|
-
*/
|
|
169
|
-
export type InjectedMessage = {
|
|
170
|
-
/** 'user' for skill body injection, 'system' for context hints.
|
|
171
|
-
* Both are converted to HumanMessage at runtime; the original role
|
|
172
|
-
* is preserved in additional_kwargs.role. */
|
|
173
|
-
role: 'user' | 'system';
|
|
174
|
-
/** Message content: string for simple text, array for complex multi-part content */
|
|
175
|
-
content: string | MessageContentComplex[];
|
|
176
|
-
/** When true, the message is framework-internal: not shown in UI, not counted as a user turn */
|
|
177
|
-
isMeta?: boolean;
|
|
178
|
-
/** Origin tag for downstream consumers (UI, pruner, compaction) */
|
|
179
|
-
source?: 'skill' | 'hook' | 'system';
|
|
180
|
-
/** Only set when source is 'skill', for compaction preservation */
|
|
181
|
-
skillName?: string;
|
|
182
|
-
};
|
|
183
157
|
/** Result for a single tool call in event-driven execution */
|
|
184
158
|
export type ToolExecuteResult = {
|
|
185
159
|
/** Matches ToolCallRequest.id */
|
|
@@ -192,13 +166,6 @@ export type ToolExecuteResult = {
|
|
|
192
166
|
status: 'success' | 'error';
|
|
193
167
|
/** Error message if status is 'error' */
|
|
194
168
|
errorMessage?: string;
|
|
195
|
-
/**
|
|
196
|
-
* Messages to inject into graph state after the ToolMessage for this call.
|
|
197
|
-
* Placed after tool results to respect provider message ordering (tool_call -> tool_result adjacency).
|
|
198
|
-
* The host's message formatter may merge injected user messages with the preceding tool_result turn.
|
|
199
|
-
* Generic mechanism: any tool execution handler can use this.
|
|
200
|
-
*/
|
|
201
|
-
injectedMessages?: InjectedMessage[];
|
|
202
169
|
};
|
|
203
170
|
/** Map of tool names to tool definitions */
|
|
204
171
|
export type LCToolRegistry = Map<string, LCTool>;
|
|
@@ -299,10 +266,6 @@ export type ProgrammaticExecutionArtifact = {
|
|
|
299
266
|
session_id?: string;
|
|
300
267
|
files?: FileRefs;
|
|
301
268
|
};
|
|
302
|
-
/** Parameters for creating a bash execution tool (same API as CodeExecutor, bash-only) */
|
|
303
|
-
export type BashExecutionToolParams = CodeExecutionToolParams;
|
|
304
|
-
/** Parameters for creating a bash programmatic tool calling tool (same API as PTC, bash-only) */
|
|
305
|
-
export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
|
|
306
269
|
/**
|
|
307
270
|
* Initialization parameters for the PTC tool
|
|
308
271
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.68",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -61,9 +61,6 @@
|
|
|
61
61
|
"tool": "node --trace-warnings -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/tools.ts --provider 'bedrock' --name 'Jo' --location 'New York, NY'",
|
|
62
62
|
"search": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/search.ts --provider 'bedrock' --name 'Jo' --location 'New York, NY'",
|
|
63
63
|
"tool_search": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/tool_search.ts",
|
|
64
|
-
"subagent": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-subagent.ts",
|
|
65
|
-
"subagent:events": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/subagent-event-driven-debug.ts",
|
|
66
|
-
"subagent:tools": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/subagent-tools-debug.ts",
|
|
67
64
|
"programmatic_exec": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/programmatic_exec.ts",
|
|
68
65
|
"code_exec_ptc": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_ptc.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
69
66
|
"programmatic_exec_agent": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/programmatic_exec_agent.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
@@ -80,7 +77,6 @@
|
|
|
80
77
|
"multi-agent-chain": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-chain.ts",
|
|
81
78
|
"multi-agent-sequence": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-sequence.ts",
|
|
82
79
|
"multi-agent-conditional": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-conditional.ts",
|
|
83
|
-
"multi-agent-subagent": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-subagent.ts",
|
|
84
80
|
"multi-agent-supervisor": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/multi-agent-supervisor.ts",
|
|
85
81
|
"test-handoff-preamble": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/test-handoff-preamble.ts",
|
|
86
82
|
"multi-agent-list-handoff": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/test-multi-agent-list-handoff.ts",
|
|
@@ -55,8 +55,6 @@ export class AgentContext {
|
|
|
55
55
|
contextPruningConfig,
|
|
56
56
|
maxToolResultChars,
|
|
57
57
|
toolSchemaTokens,
|
|
58
|
-
subagentConfigs,
|
|
59
|
-
maxSubagentDepth,
|
|
60
58
|
} = agentConfig;
|
|
61
59
|
|
|
62
60
|
const agentContext = new AgentContext({
|
|
@@ -84,10 +82,6 @@ export class AgentContext {
|
|
|
84
82
|
maxToolResultChars,
|
|
85
83
|
});
|
|
86
84
|
|
|
87
|
-
agentContext._sourceInputs = agentConfig;
|
|
88
|
-
agentContext.subagentConfigs = subagentConfigs;
|
|
89
|
-
agentContext.maxSubagentDepth = maxSubagentDepth;
|
|
90
|
-
|
|
91
85
|
if (initialSummary?.text != null && initialSummary.text !== '') {
|
|
92
86
|
agentContext.setInitialSummary(
|
|
93
87
|
initialSummary.text,
|
|
@@ -204,12 +198,6 @@ export class AgentContext {
|
|
|
204
198
|
toolDefinitions?: t.LCTool[];
|
|
205
199
|
/** Set of tool names discovered via tool search (to be loaded) */
|
|
206
200
|
discoveredToolNames: Set<string> = new Set();
|
|
207
|
-
/** Original AgentInputs used to create this context — used for self-spawn subagent resolution. */
|
|
208
|
-
_sourceInputs?: t.AgentInputs;
|
|
209
|
-
/** Subagent configurations for hierarchical delegation. */
|
|
210
|
-
subagentConfigs?: t.SubagentConfig[];
|
|
211
|
-
/** Maximum subagent nesting depth. */
|
|
212
|
-
maxSubagentDepth?: number;
|
|
213
201
|
/** Instructions for this agent */
|
|
214
202
|
instructions?: string;
|
|
215
203
|
/** Additional instructions for this agent */
|
|
@@ -697,20 +685,8 @@ export class AgentContext {
|
|
|
697
685
|
let toolTokens = 0;
|
|
698
686
|
const countedToolNames = new Set<string>();
|
|
699
687
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
* (graph-managed tools like handoff + subagent). `graphTools` is often
|
|
703
|
-
* populated after `fromConfig()` kicks off the initial calculation, so
|
|
704
|
-
* callers that mutate `graphTools` must re-trigger this method to
|
|
705
|
-
* refresh `toolSchemaTokens`.
|
|
706
|
-
*/
|
|
707
|
-
const instanceTools: t.GraphTools = [
|
|
708
|
-
...((this.tools as t.GenericTool[] | undefined) ?? []),
|
|
709
|
-
...((this.graphTools as t.GenericTool[] | undefined) ?? []),
|
|
710
|
-
];
|
|
711
|
-
|
|
712
|
-
if (instanceTools.length > 0) {
|
|
713
|
-
for (const tool of instanceTools) {
|
|
688
|
+
if (this.tools && this.tools.length > 0) {
|
|
689
|
+
for (const tool of this.tools) {
|
|
714
690
|
const genericTool = tool as Record<string, unknown>;
|
|
715
691
|
if (
|
|
716
692
|
genericTool.schema != null &&
|
package/src/common/enum.ts
CHANGED
|
@@ -27,8 +27,6 @@ export enum GraphEvents {
|
|
|
27
27
|
ON_SUMMARIZE_DELTA = 'on_summarize_delta',
|
|
28
28
|
/** [Custom] Emitted when the summarize node completes with the final summary */
|
|
29
29
|
ON_SUMMARIZE_COMPLETE = 'on_summarize_complete',
|
|
30
|
-
/** [Custom] Progress update from a running subagent (wraps child-graph events so hosts can display activity separately from parent). */
|
|
31
|
-
ON_SUBAGENT_UPDATE = 'on_subagent_update',
|
|
32
30
|
/** [Custom] Diagnostic logging event for context management observability */
|
|
33
31
|
ON_AGENT_LOG = 'on_agent_log',
|
|
34
32
|
|
|
@@ -184,21 +182,8 @@ export enum Constants {
|
|
|
184
182
|
MCP_DELIMITER = '_mcp_',
|
|
185
183
|
/** Anthropic server tool ID prefix (web_search, code_execution, etc.) */
|
|
186
184
|
ANTHROPIC_SERVER_TOOL_PREFIX = 'srvtoolu_',
|
|
187
|
-
SKILL_TOOL = 'skill',
|
|
188
|
-
READ_FILE = 'read_file',
|
|
189
|
-
BASH_TOOL = 'bash_tool',
|
|
190
|
-
BASH_PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_bash',
|
|
191
|
-
SUBAGENT = 'subagent',
|
|
192
185
|
}
|
|
193
186
|
|
|
194
|
-
/** Tool names that use the code execution environment (shared session, file tracking). */
|
|
195
|
-
export const CODE_EXECUTION_TOOLS: ReadonlySet<string> = new Set([
|
|
196
|
-
Constants.EXECUTE_CODE,
|
|
197
|
-
Constants.BASH_TOOL,
|
|
198
|
-
Constants.PROGRAMMATIC_TOOL_CALLING,
|
|
199
|
-
Constants.BASH_PROGRAMMATIC_TOOL_CALLING,
|
|
200
|
-
]);
|
|
201
|
-
|
|
202
187
|
export enum TitleMethod {
|
|
203
188
|
STRUCTURED = 'structured',
|
|
204
189
|
FUNCTIONS = 'functions',
|
package/src/graphs/Graph.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { nanoid } from 'nanoid';
|
|
3
|
-
import { tool } from '@langchain/core/tools';
|
|
4
3
|
import { ToolNode } from '@langchain/langgraph/prebuilt';
|
|
5
4
|
import { Runnable, RunnableConfig } from '@langchain/core/runnables';
|
|
6
5
|
import { ToolMessage, AIMessageChunk } from '@langchain/core/messages';
|
|
@@ -40,8 +39,6 @@ import {
|
|
|
40
39
|
joinKeys,
|
|
41
40
|
sleep,
|
|
42
41
|
} from '@/utils';
|
|
43
|
-
import { SubagentExecutor, resolveSubagentConfigs } from '@/tools/subagent';
|
|
44
|
-
import { buildSubagentToolParams } from '@/tools/SubagentTool';
|
|
45
42
|
import { ToolNode as CustomToolNode, toolsCondition } from '@/tools/ToolNode';
|
|
46
43
|
import { safeDispatchCustomEvent, emitAgentLog } from '@/utils/events';
|
|
47
44
|
import { attemptInvoke, tryFallbackProviders } from '@/llm/invoke';
|
|
@@ -56,7 +53,6 @@ import { isThinkingEnabled } from '@/llm/request';
|
|
|
56
53
|
import { initializeModel } from '@/llm/init';
|
|
57
54
|
import { HandlerRegistry } from '@/events';
|
|
58
55
|
import { ChatOpenAI } from '@/llm/openai';
|
|
59
|
-
import type { HookRegistry } from '@/hooks';
|
|
60
56
|
|
|
61
57
|
const { AGENT, TOOLS, SUMMARIZE } = GraphNodeKeys;
|
|
62
58
|
|
|
@@ -127,7 +123,6 @@ export abstract class Graph<
|
|
|
127
123
|
/** Set of invoked tool call IDs from non-message run steps completed mid-run, if any */
|
|
128
124
|
invokedToolIds?: Set<string>;
|
|
129
125
|
handlerRegistry: HandlerRegistry | undefined;
|
|
130
|
-
hookRegistry: HookRegistry | undefined;
|
|
131
126
|
/**
|
|
132
127
|
* Tool session contexts for automatic state persistence across tool invocations.
|
|
133
128
|
* Keyed by tool name (e.g., Constants.EXECUTE_CODE).
|
|
@@ -152,7 +147,6 @@ export abstract class Graph<
|
|
|
152
147
|
this.prelimMessageIdsByStepKey = new Map();
|
|
153
148
|
this.invokedToolIds = undefined;
|
|
154
149
|
this.handlerRegistry = undefined;
|
|
155
|
-
this.hookRegistry = undefined;
|
|
156
150
|
this.sessions.clear();
|
|
157
151
|
}
|
|
158
152
|
}
|
|
@@ -512,7 +506,6 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
512
506
|
agentId: agentContext?.agentId,
|
|
513
507
|
toolCallStepIds: this.toolCallStepIds,
|
|
514
508
|
toolRegistry: agentContext?.toolRegistry,
|
|
515
|
-
hookRegistry: this.hookRegistry,
|
|
516
509
|
directToolNames: directToolNames.size > 0 ? directToolNames : undefined,
|
|
517
510
|
maxContextTokens: agentContext?.maxContextTokens,
|
|
518
511
|
maxToolResultChars: agentContext?.maxToolResultChars,
|
|
@@ -1155,111 +1148,6 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
1155
1148
|
throw new Error(`Agent context not found for agentId: ${agentId}`);
|
|
1156
1149
|
}
|
|
1157
1150
|
|
|
1158
|
-
/**
|
|
1159
|
-
* Depth countdown across graph boundaries: the parent's `maxSubagentDepth`
|
|
1160
|
-
* becomes this executor's `maxDepth`. When the child graph is constructed,
|
|
1161
|
-
* `buildChildInputs()` decrements `maxSubagentDepth` on the child's
|
|
1162
|
-
* `AgentInputs` (only when `allowNested: true`; otherwise subagentConfigs
|
|
1163
|
-
* are stripped entirely). The child graph's own `createAgentNode()` then
|
|
1164
|
-
* reads the decremented value here and creates a narrower executor —
|
|
1165
|
-
* recursion is bounded even though each graph has its own separate
|
|
1166
|
-
* executor instance.
|
|
1167
|
-
*/
|
|
1168
|
-
const effectiveSubagentDepth = agentContext.maxSubagentDepth ?? 1;
|
|
1169
|
-
if (
|
|
1170
|
-
agentContext.subagentConfigs != null &&
|
|
1171
|
-
agentContext.subagentConfigs.length > 0 &&
|
|
1172
|
-
effectiveSubagentDepth > 0
|
|
1173
|
-
) {
|
|
1174
|
-
const resolvedConfigs = resolveSubagentConfigs(
|
|
1175
|
-
agentContext.subagentConfigs,
|
|
1176
|
-
agentContext
|
|
1177
|
-
);
|
|
1178
|
-
if (resolvedConfigs.length > 0) {
|
|
1179
|
-
const getParentHandlerRegistry = (): HandlerRegistry | undefined =>
|
|
1180
|
-
this.handlerRegistry;
|
|
1181
|
-
const executor = new SubagentExecutor({
|
|
1182
|
-
configs: new Map(resolvedConfigs.map((c) => [c.type, c])),
|
|
1183
|
-
parentSignal: this.signal,
|
|
1184
|
-
hookRegistry: this.hookRegistry,
|
|
1185
|
-
/** Lazy — Run wires the registry onto the graph AFTER
|
|
1186
|
-
* `createWorkflow()` runs, so a direct capture here would be
|
|
1187
|
-
* `undefined` at construction time. */
|
|
1188
|
-
parentHandlerRegistry: getParentHandlerRegistry,
|
|
1189
|
-
parentRunId: this.runId ?? '',
|
|
1190
|
-
parentAgentId: agentContext.agentId,
|
|
1191
|
-
tokenCounter: agentContext.tokenCounter,
|
|
1192
|
-
maxDepth: effectiveSubagentDepth,
|
|
1193
|
-
createChildGraph: (input): StandardGraph => new StandardGraph(input),
|
|
1194
|
-
});
|
|
1195
|
-
|
|
1196
|
-
const subagentTool = tool(async (rawInput, config) => {
|
|
1197
|
-
const input = rawInput as {
|
|
1198
|
-
description?: string;
|
|
1199
|
-
subagent_type?: string;
|
|
1200
|
-
};
|
|
1201
|
-
const description =
|
|
1202
|
-
typeof input.description === 'string' &&
|
|
1203
|
-
input.description.trim().length > 0
|
|
1204
|
-
? input.description
|
|
1205
|
-
: 'No task description provided';
|
|
1206
|
-
const subagentType =
|
|
1207
|
-
typeof input.subagent_type === 'string' ? input.subagent_type : '';
|
|
1208
|
-
const threadId = config.configurable?.thread_id as string | undefined;
|
|
1209
|
-
/**
|
|
1210
|
-
* When the tool is dispatched from an LLM's `tool_call`, LangChain
|
|
1211
|
-
* threads the originating `ToolCall` onto the RunnableConfig as
|
|
1212
|
-
* `config.toolCall` (see `ToolRunnableConfig` in
|
|
1213
|
-
* `@langchain/core/tools` — internal but stable since ≥0.3.x).
|
|
1214
|
-
* Surfacing its id lets hosts correlate `SubagentUpdateEvent`s
|
|
1215
|
-
* back to the parent's `tool_call_id` deterministically — no
|
|
1216
|
-
* temporal heuristics needed. If a future LangChain version
|
|
1217
|
-
* changes the threading, the type-guarded read falls back to
|
|
1218
|
-
* `undefined` and the correlation degrades gracefully.
|
|
1219
|
-
*/
|
|
1220
|
-
const toolCall = (config as { toolCall?: { id?: string } }).toolCall;
|
|
1221
|
-
const parentToolCallId =
|
|
1222
|
-
typeof toolCall?.id === 'string' ? toolCall.id : undefined;
|
|
1223
|
-
const result = await executor.execute({
|
|
1224
|
-
description,
|
|
1225
|
-
subagentType,
|
|
1226
|
-
threadId,
|
|
1227
|
-
parentToolCallId,
|
|
1228
|
-
});
|
|
1229
|
-
return result.content;
|
|
1230
|
-
}, buildSubagentToolParams(resolvedConfigs));
|
|
1231
|
-
|
|
1232
|
-
if (!agentContext.graphTools) {
|
|
1233
|
-
agentContext.graphTools = [];
|
|
1234
|
-
}
|
|
1235
|
-
(agentContext.graphTools as t.GenericTool[]).push(subagentTool);
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
* Refresh toolSchemaTokens to include the subagent tool's schema.
|
|
1239
|
-
* `calculateInstructionTokens()` was kicked off in `fromConfig()`
|
|
1240
|
-
* before graphTools was populated, so its result did not count this
|
|
1241
|
-
* tool. Without this retrigger, token-budget/pruning logic
|
|
1242
|
-
* underestimates prompt overhead.
|
|
1243
|
-
*/
|
|
1244
|
-
if (agentContext.tokenCounter) {
|
|
1245
|
-
const { tokenCounter, baseIndexTokenCountMap } = agentContext;
|
|
1246
|
-
agentContext.tokenCalculationPromise = agentContext
|
|
1247
|
-
.calculateInstructionTokens(tokenCounter)
|
|
1248
|
-
.then(() => {
|
|
1249
|
-
agentContext.updateTokenMapWithInstructions(
|
|
1250
|
-
baseIndexTokenCountMap
|
|
1251
|
-
);
|
|
1252
|
-
})
|
|
1253
|
-
.catch((err) => {
|
|
1254
|
-
console.error(
|
|
1255
|
-
'Error recalculating instruction tokens after subagent tool injection:',
|
|
1256
|
-
err
|
|
1257
|
-
);
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
1151
|
const agentNode = `${AGENT}${agentId}` as const;
|
|
1264
1152
|
const toolNode = `${TOOLS}${agentId}` as const;
|
|
1265
1153
|
const summarizeNode = `${SUMMARIZE}${agentId}` as const;
|
|
@@ -1315,7 +1203,6 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
1315
1203
|
},
|
|
1316
1204
|
runId: this.runId,
|
|
1317
1205
|
isMultiAgent: this.isMultiAgentGraph(),
|
|
1318
|
-
hookRegistry: this.hookRegistry,
|
|
1319
1206
|
dispatchRunStep: async (runStep, nodeConfig) => {
|
|
1320
1207
|
this.contentData.push(runStep);
|
|
1321
1208
|
this.contentIndexMap.set(runStep.id, runStep.index);
|
|
@@ -59,11 +59,50 @@ export class MultiAgentGraph extends StandardGraph {
|
|
|
59
59
|
constructor(input: t.MultiAgentGraphInput) {
|
|
60
60
|
super(input);
|
|
61
61
|
this.edges = input.edges;
|
|
62
|
+
this.validateEdgeAgents();
|
|
62
63
|
this.categorizeEdges();
|
|
63
64
|
this.analyzeGraph();
|
|
64
65
|
this.createHandoffTools();
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Fails fast when an edge references an agent that is not in
|
|
70
|
+
* `agentContexts`. Without this check, the underlying LangGraph
|
|
71
|
+
* `StateGraph.compile()` would throw the opaque
|
|
72
|
+
* `Found edge ending at unknown node "<id>"` error after graph
|
|
73
|
+
* construction — far from the true root cause.
|
|
74
|
+
*
|
|
75
|
+
* This catches the common misuse of passing `edges` into a multi-agent
|
|
76
|
+
* config without also passing the corresponding sub-agent configs in
|
|
77
|
+
* `agents` (e.g. a host that forgot to pre-load handoff targets).
|
|
78
|
+
*/
|
|
79
|
+
private validateEdgeAgents(): void {
|
|
80
|
+
const known = new Set(this.agentContexts.keys());
|
|
81
|
+
const unknown = new Set<string>();
|
|
82
|
+
for (const edge of this.edges) {
|
|
83
|
+
const participants = [
|
|
84
|
+
...(Array.isArray(edge.from) ? edge.from : [edge.from]),
|
|
85
|
+
...(Array.isArray(edge.to) ? edge.to : [edge.to]),
|
|
86
|
+
];
|
|
87
|
+
for (const id of participants) {
|
|
88
|
+
if (typeof id === 'string' && !known.has(id)) {
|
|
89
|
+
unknown.add(id);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (unknown.size === 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const missing = Array.from(unknown)
|
|
97
|
+
.map((id) => `"${id}"`)
|
|
98
|
+
.join(', ');
|
|
99
|
+
throw new Error(
|
|
100
|
+
`MultiAgentGraph: edges reference agent(s) not present in agents: [${missing}]. ` +
|
|
101
|
+
'Ensure every agent referenced by an edge is also included in the `agents` array, ' +
|
|
102
|
+
'or filter orphaned edges before constructing the graph.'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
67
106
|
/**
|
|
68
107
|
* Categorize edges into handoff and direct types
|
|
69
108
|
*/
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/graphs/__tests__/MultiAgentGraph.test.ts
|
|
2
|
+
import { MultiAgentGraph } from '../MultiAgentGraph';
|
|
3
|
+
import { Providers } from '@/common';
|
|
4
|
+
import type * as t from '@/types';
|
|
5
|
+
|
|
6
|
+
describe('MultiAgentGraph.validateEdgeAgents', () => {
|
|
7
|
+
const makeAgent = (agentId: string): t.AgentInputs => ({
|
|
8
|
+
agentId,
|
|
9
|
+
provider: Providers.OPENAI,
|
|
10
|
+
instructions: 'test',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('constructs without error when every edge endpoint has a matching agent', () => {
|
|
14
|
+
const input: t.MultiAgentGraphInput = {
|
|
15
|
+
runId: 'r1',
|
|
16
|
+
agents: [makeAgent('A'), makeAgent('B')],
|
|
17
|
+
edges: [{ from: 'A', to: 'B', edgeType: 'handoff' }],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
expect(() => new MultiAgentGraph(input)).not.toThrow();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('throws a descriptive error when an edge `to` points at an unknown agent', () => {
|
|
24
|
+
const input: t.MultiAgentGraphInput = {
|
|
25
|
+
runId: 'r1',
|
|
26
|
+
agents: [makeAgent('A')],
|
|
27
|
+
edges: [{ from: 'A', to: 'MISSING', edgeType: 'handoff' }],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
expect(() => new MultiAgentGraph(input)).toThrow(/MISSING/);
|
|
31
|
+
expect(() => new MultiAgentGraph(input)).toThrow(
|
|
32
|
+
/edges reference agent\(s\) not present in agents/
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('throws when an edge `from` points at an unknown agent', () => {
|
|
37
|
+
const input: t.MultiAgentGraphInput = {
|
|
38
|
+
runId: 'r1',
|
|
39
|
+
agents: [makeAgent('A')],
|
|
40
|
+
edges: [{ from: 'MISSING', to: 'A', edgeType: 'handoff' }],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
expect(() => new MultiAgentGraph(input)).toThrow(/MISSING/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('reports all unknown agent ids in a single error', () => {
|
|
47
|
+
const input: t.MultiAgentGraphInput = {
|
|
48
|
+
runId: 'r1',
|
|
49
|
+
agents: [makeAgent('A')],
|
|
50
|
+
edges: [
|
|
51
|
+
{ from: 'A', to: 'B', edgeType: 'handoff' },
|
|
52
|
+
{ from: 'A', to: 'C', edgeType: 'handoff' },
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
let thrown: Error | undefined;
|
|
57
|
+
try {
|
|
58
|
+
new MultiAgentGraph(input);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
thrown = err as Error;
|
|
61
|
+
}
|
|
62
|
+
expect(thrown).toBeDefined();
|
|
63
|
+
expect(thrown!.message).toMatch(/"B"/);
|
|
64
|
+
expect(thrown!.message).toMatch(/"C"/);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('handles array `from` / `to` fields', () => {
|
|
68
|
+
const valid: t.MultiAgentGraphInput = {
|
|
69
|
+
runId: 'r1',
|
|
70
|
+
agents: [makeAgent('A'), makeAgent('B'), makeAgent('C')],
|
|
71
|
+
edges: [{ from: ['A'], to: ['B', 'C'], edgeType: 'direct' }],
|
|
72
|
+
};
|
|
73
|
+
expect(() => new MultiAgentGraph(valid)).not.toThrow();
|
|
74
|
+
|
|
75
|
+
const invalid: t.MultiAgentGraphInput = {
|
|
76
|
+
runId: 'r1',
|
|
77
|
+
agents: [makeAgent('A'), makeAgent('B')],
|
|
78
|
+
edges: [{ from: ['A'], to: ['B', 'C'], edgeType: 'direct' }],
|
|
79
|
+
};
|
|
80
|
+
expect(() => new MultiAgentGraph(invalid)).toThrow(/"C"/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('accepts an empty edges array (single-agent case with no handoffs)', () => {
|
|
84
|
+
const input: t.MultiAgentGraphInput = {
|
|
85
|
+
runId: 'r1',
|
|
86
|
+
agents: [makeAgent('A')],
|
|
87
|
+
edges: [],
|
|
88
|
+
};
|
|
89
|
+
expect(() => new MultiAgentGraph(input)).not.toThrow();
|
|
90
|
+
});
|
|
91
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -14,14 +14,7 @@ export * from './summarization';
|
|
|
14
14
|
/* Tools */
|
|
15
15
|
export * from './tools/Calculator';
|
|
16
16
|
export * from './tools/CodeExecutor';
|
|
17
|
-
export * from './tools/BashExecutor';
|
|
18
17
|
export * from './tools/ProgrammaticToolCalling';
|
|
19
|
-
export * from './tools/BashProgrammaticToolCalling';
|
|
20
|
-
export * from './tools/SkillTool';
|
|
21
|
-
export * from './tools/SubagentTool';
|
|
22
|
-
export * from './tools/subagent';
|
|
23
|
-
export * from './tools/ReadFile';
|
|
24
|
-
export * from './tools/skillCatalog';
|
|
25
18
|
export * from './tools/ToolSearch';
|
|
26
19
|
export * from './tools/ToolNode';
|
|
27
20
|
export * from './tools/schema';
|
|
@@ -32,9 +25,6 @@ export * from './tools/search';
|
|
|
32
25
|
export * from './common';
|
|
33
26
|
export * from './utils';
|
|
34
27
|
|
|
35
|
-
/* Hooks */
|
|
36
|
-
export * from './hooks';
|
|
37
|
-
|
|
38
28
|
/* Types */
|
|
39
29
|
export type * from './types';
|
|
40
30
|
|
package/src/messages/format.ts
CHANGED
|
@@ -797,39 +797,18 @@ function contentPartCharLength(part: MessageContentComplex): number {
|
|
|
797
797
|
return len;
|
|
798
798
|
}
|
|
799
799
|
|
|
800
|
-
/** Extracts the skillName from a skill tool_call's args (string or object). */
|
|
801
|
-
function extractSkillName(args: unknown): string | undefined {
|
|
802
|
-
let parsed: Record<string, unknown> | undefined;
|
|
803
|
-
if (typeof args === 'string') {
|
|
804
|
-
try {
|
|
805
|
-
parsed = JSON.parse(args) as Record<string, unknown>;
|
|
806
|
-
} catch {
|
|
807
|
-
/* malformed args — skip */
|
|
808
|
-
}
|
|
809
|
-
} else {
|
|
810
|
-
parsed = args as Record<string, unknown> | undefined;
|
|
811
|
-
}
|
|
812
|
-
const name = parsed?.skillName;
|
|
813
|
-
return typeof name === 'string' && name !== '' ? name : undefined;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
800
|
/**
|
|
817
801
|
* Formats an array of messages for LangChain, handling tool calls and creating ToolMessage instances.
|
|
818
802
|
*
|
|
819
803
|
* @param payload - The array of messages to format.
|
|
820
804
|
* @param indexTokenCountMap - Optional map of message indices to token counts.
|
|
821
805
|
* @param tools - Optional set of tool names that are allowed in the request.
|
|
822
|
-
* @param skills - Optional map of skill name to body for reconstructing skill HumanMessages.
|
|
823
806
|
* @returns - Object containing formatted messages and updated indexTokenCountMap if provided.
|
|
824
807
|
*/
|
|
825
808
|
export const formatAgentMessages = (
|
|
826
809
|
payload: TPayload,
|
|
827
810
|
indexTokenCountMap?: Record<number, number | undefined>,
|
|
828
|
-
tools?: Set<string
|
|
829
|
-
/** Pre-resolved skill bodies keyed by skill name. When present, HumanMessages
|
|
830
|
-
* are reconstructed after skill ToolMessages to restore skill instructions
|
|
831
|
-
* that were only in LangGraph state during the original run. */
|
|
832
|
-
skills?: Map<string, string>
|
|
811
|
+
tools?: Set<string>
|
|
833
812
|
): {
|
|
834
813
|
messages: Array<HumanMessage | AIMessage | SystemMessage | ToolMessage>;
|
|
835
814
|
indexTokenCountMap?: Record<number, number>;
|
|
@@ -923,7 +902,6 @@ export const formatAgentMessages = (
|
|
|
923
902
|
* - Dynamically expand the set when tool_search results are encountered
|
|
924
903
|
*/
|
|
925
904
|
let processedMessage = message;
|
|
926
|
-
let pendingSkillNames: Set<string> | undefined;
|
|
927
905
|
if (discoveredTools) {
|
|
928
906
|
const content = message.content;
|
|
929
907
|
if (content != null && Array.isArray(content)) {
|
|
@@ -972,17 +950,8 @@ export const formatAgentMessages = (
|
|
|
972
950
|
}
|
|
973
951
|
|
|
974
952
|
if (discoveredTools.has(toolName)) {
|
|
953
|
+
/** Valid tool - keep it */
|
|
975
954
|
filteredContent.push(part);
|
|
976
|
-
if (
|
|
977
|
-
toolName === Constants.SKILL_TOOL &&
|
|
978
|
-
skills?.size != null &&
|
|
979
|
-
skills.size > 0
|
|
980
|
-
) {
|
|
981
|
-
const skillName = extractSkillName(part.tool_call.args) ?? '';
|
|
982
|
-
if (skillName) {
|
|
983
|
-
(pendingSkillNames ??= new Set()).add(skillName);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
955
|
} else {
|
|
987
956
|
/** Invalid tool - convert to string for context preservation */
|
|
988
957
|
if (
|
|
@@ -1058,25 +1027,6 @@ export const formatAgentMessages = (
|
|
|
1058
1027
|
}
|
|
1059
1028
|
}
|
|
1060
1029
|
|
|
1061
|
-
/** When tools filtering is off, still detect skill tool_calls for body reconstruction */
|
|
1062
|
-
if (!discoveredTools && skills?.size != null && skills.size > 0) {
|
|
1063
|
-
const content = processedMessage.content;
|
|
1064
|
-
if (Array.isArray(content)) {
|
|
1065
|
-
for (const part of content) {
|
|
1066
|
-
if (
|
|
1067
|
-
part.type !== ContentTypes.TOOL_CALL ||
|
|
1068
|
-
part.tool_call?.name !== Constants.SKILL_TOOL
|
|
1069
|
-
) {
|
|
1070
|
-
continue;
|
|
1071
|
-
}
|
|
1072
|
-
const skillName = extractSkillName(part.tool_call.args) ?? '';
|
|
1073
|
-
if (skillName) {
|
|
1074
|
-
(pendingSkillNames ??= new Set()).add(skillName);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
1030
|
const formattedMessages = formatAssistantMessage(processedMessage);
|
|
1081
1031
|
if (sourceMessageId != null && sourceMessageId !== '') {
|
|
1082
1032
|
for (const formattedMessage of formattedMessages) {
|
|
@@ -1085,29 +1035,9 @@ export const formatAgentMessages = (
|
|
|
1085
1035
|
}
|
|
1086
1036
|
messages.push(...formattedMessages);
|
|
1087
1037
|
|
|
1088
|
-
//
|
|
1089
|
-
//
|
|
1038
|
+
// Update the index mapping for this assistant message
|
|
1039
|
+
// Store all indices that were created from this original message
|
|
1090
1040
|
const endMessageIndex = messages.length;
|
|
1091
|
-
|
|
1092
|
-
if (pendingSkillNames?.size != null && pendingSkillNames.size > 0) {
|
|
1093
|
-
for (const skillName of pendingSkillNames) {
|
|
1094
|
-
const body = skills?.get(skillName) ?? '';
|
|
1095
|
-
if (body) {
|
|
1096
|
-
messages.push(
|
|
1097
|
-
new HumanMessage({
|
|
1098
|
-
content: body,
|
|
1099
|
-
additional_kwargs: {
|
|
1100
|
-
role: 'user',
|
|
1101
|
-
isMeta: true,
|
|
1102
|
-
source: 'skill',
|
|
1103
|
-
skillName,
|
|
1104
|
-
},
|
|
1105
|
-
})
|
|
1106
|
-
);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
1041
|
const resultIndices = [];
|
|
1112
1042
|
for (let j = startMessageIndex; j < endMessageIndex; j++) {
|
|
1113
1043
|
resultIndices.push(j);
|