@illuma-ai/agents 1.4.0-alpha.6 → 1.5.0
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/README.md +62 -0
- package/dist/cjs/agents/AgentContext.cjs +274 -67
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +44 -13
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +182 -5
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +152 -1167
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +162 -0
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -0
- package/dist/cjs/hooks/executeHooks.cjs +276 -0
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -0
- package/dist/cjs/hooks/matchers.cjs +256 -0
- package/dist/cjs/hooks/matchers.cjs.map +1 -0
- package/dist/cjs/hooks/types.cjs +27 -0
- package/dist/cjs/hooks/types.cjs.map +1 -0
- package/dist/cjs/langchain/google-common.cjs +3 -0
- package/dist/cjs/langchain/google-common.cjs.map +1 -0
- package/dist/cjs/langchain/index.cjs +86 -0
- package/dist/cjs/langchain/index.cjs.map +1 -0
- package/dist/cjs/langchain/language_models/chat_models.cjs +3 -0
- package/dist/cjs/langchain/language_models/chat_models.cjs.map +1 -0
- package/dist/cjs/langchain/messages/tool.cjs +3 -0
- package/dist/cjs/langchain/messages/tool.cjs.map +1 -0
- package/dist/cjs/langchain/messages.cjs +51 -0
- package/dist/cjs/langchain/messages.cjs.map +1 -0
- package/dist/cjs/langchain/openai.cjs +3 -0
- package/dist/cjs/langchain/openai.cjs.map +1 -0
- package/dist/cjs/langchain/prompts.cjs +11 -0
- package/dist/cjs/langchain/prompts.cjs.map +1 -0
- package/dist/cjs/langchain/runnables.cjs +19 -0
- package/dist/cjs/langchain/runnables.cjs.map +1 -0
- package/dist/cjs/langchain/tools.cjs +23 -0
- package/dist/cjs/langchain/tools.cjs.map +1 -0
- package/dist/cjs/langchain/utils/env.cjs +11 -0
- package/dist/cjs/langchain/utils/env.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +5 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/cacheSupport.cjs +55 -0
- package/dist/cjs/llm/bedrock/cacheSupport.cjs.map +1 -0
- package/dist/cjs/llm/bedrock/index.cjs +61 -33
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +0 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +27 -10
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +178 -127
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +89 -0
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/contextPruning.cjs +156 -0
- package/dist/cjs/messages/contextPruning.cjs.map +1 -0
- package/dist/cjs/messages/contextPruningSettings.cjs +53 -0
- package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -0
- package/dist/cjs/messages/format.cjs +144 -20
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +505 -4
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/run.cjs +141 -1
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +235 -0
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -0
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +297 -0
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/CodeExecutor.cjs +44 -47
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +16 -11
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ReadFile.cjs +44 -0
- package/dist/cjs/tools/ReadFile.cjs.map +1 -0
- package/dist/cjs/tools/SkillTool.cjs +51 -0
- package/dist/cjs/tools/SkillTool.cjs.map +1 -0
- package/dist/cjs/tools/SubagentTool.cjs +93 -0
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +450 -24
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +11 -3
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs +189 -0
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -0
- package/dist/cjs/tools/search/tavily-search.cjs +372 -0
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +28 -4
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +10 -3
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/skillCatalog.cjs +84 -0
- package/dist/cjs/tools/skillCatalog.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +512 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -0
- package/dist/cjs/tools/toolOutputReferences.cjs +670 -0
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -0
- package/dist/cjs/types/agent-cache.cjs +53 -0
- package/dist/cjs/types/agent-cache.cjs.map +1 -0
- package/dist/cjs/types/graph.cjs.map +1 -1
- package/dist/cjs/utils/truncation.cjs +135 -0
- package/dist/cjs/utils/truncation.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs +274 -67
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +44 -12
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +182 -5
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +155 -1170
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/hooks/HookRegistry.mjs +160 -0
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -0
- package/dist/esm/hooks/executeHooks.mjs +273 -0
- package/dist/esm/hooks/executeHooks.mjs.map +1 -0
- package/dist/esm/hooks/matchers.mjs +251 -0
- package/dist/esm/hooks/matchers.mjs.map +1 -0
- package/dist/esm/hooks/types.mjs +25 -0
- package/dist/esm/hooks/types.mjs.map +1 -0
- package/dist/esm/langchain/google-common.mjs +2 -0
- package/dist/esm/langchain/google-common.mjs.map +1 -0
- package/dist/esm/langchain/index.mjs +5 -0
- package/dist/esm/langchain/language_models/chat_models.mjs +2 -0
- package/dist/esm/langchain/language_models/chat_models.mjs.map +1 -0
- package/dist/esm/langchain/messages/tool.mjs +2 -0
- package/dist/esm/langchain/messages/tool.mjs.map +1 -0
- package/dist/esm/langchain/messages.mjs +2 -0
- package/dist/esm/langchain/messages.mjs.map +1 -0
- package/dist/esm/langchain/openai.mjs +2 -0
- package/dist/esm/langchain/openai.mjs.map +1 -0
- package/dist/esm/langchain/prompts.mjs +2 -0
- package/dist/esm/langchain/prompts.mjs.map +1 -0
- package/dist/esm/langchain/runnables.mjs +2 -0
- package/dist/esm/langchain/runnables.mjs.map +1 -0
- package/dist/esm/langchain/tools.mjs +2 -0
- package/dist/esm/langchain/tools.mjs.map +1 -0
- package/dist/esm/langchain/utils/env.mjs +2 -0
- package/dist/esm/langchain/utils/env.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +5 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/cacheSupport.mjs +52 -0
- package/dist/esm/llm/bedrock/cacheSupport.mjs.map +1 -0
- package/dist/esm/llm/bedrock/index.mjs +61 -34
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +0 -3
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +27 -10
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/main.mjs +21 -27
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +89 -0
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs +154 -0
- package/dist/esm/messages/contextPruning.mjs.map +1 -0
- package/dist/esm/messages/contextPruningSettings.mjs +50 -0
- package/dist/esm/messages/contextPruningSettings.mjs.map +1 -0
- package/dist/esm/messages/format.mjs +136 -12
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +504 -7
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/run.mjs +141 -1
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +227 -0
- package/dist/esm/tools/BashExecutor.mjs.map +1 -0
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +288 -0
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/CodeExecutor.mjs +44 -48
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +17 -12
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ReadFile.mjs +39 -0
- package/dist/esm/tools/ReadFile.mjs.map +1 -0
- package/dist/esm/tools/SkillTool.mjs +46 -0
- package/dist/esm/tools/SkillTool.mjs.map +1 -0
- package/dist/esm/tools/SubagentTool.mjs +86 -0
- package/dist/esm/tools/SubagentTool.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +452 -26
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +11 -3
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs +186 -0
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -0
- package/dist/esm/tools/search/tavily-search.mjs +370 -0
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +28 -4
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +10 -3
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/skillCatalog.mjs +82 -0
- package/dist/esm/tools/skillCatalog.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +506 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -0
- package/dist/esm/tools/toolOutputReferences.mjs +662 -0
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -0
- package/dist/esm/types/agent-cache.mjs +51 -0
- package/dist/esm/types/agent-cache.mjs.map +1 -0
- package/dist/esm/types/graph.mjs.map +1 -1
- package/dist/esm/utils/truncation.mjs +128 -0
- package/dist/esm/utils/truncation.mjs.map +1 -0
- package/dist/types/agents/AgentContext.d.ts +101 -8
- package/dist/types/common/enum.d.ts +39 -12
- package/dist/types/common/index.d.ts +0 -1
- package/dist/types/graphs/Graph.d.ts +43 -0
- package/dist/types/graphs/MultiAgentGraph.d.ts +26 -150
- package/dist/types/graphs/index.d.ts +0 -1
- package/dist/types/hooks/HookRegistry.d.ts +56 -0
- package/dist/types/hooks/executeHooks.d.ts +79 -0
- package/dist/types/hooks/index.d.ts +6 -0
- package/dist/types/hooks/matchers.d.ts +95 -0
- package/dist/types/hooks/types.d.ts +320 -0
- package/dist/types/index.d.ts +9 -9
- package/dist/types/langchain/google-common.d.ts +1 -0
- package/dist/types/langchain/index.d.ts +8 -0
- package/dist/types/langchain/language_models/chat_models.d.ts +1 -0
- package/dist/types/langchain/messages/tool.d.ts +1 -0
- package/dist/types/langchain/messages.d.ts +2 -0
- package/dist/types/langchain/openai.d.ts +1 -0
- package/dist/types/langchain/prompts.d.ts +1 -0
- package/dist/types/langchain/runnables.d.ts +2 -0
- package/dist/types/langchain/tools.d.ts +2 -0
- package/dist/types/langchain/utils/env.d.ts +1 -0
- package/dist/types/llm/bedrock/cacheSupport.d.ts +35 -0
- package/dist/types/llm/bedrock/index.d.ts +54 -1
- package/dist/types/messages/contextPruning.d.ts +42 -0
- package/dist/types/messages/contextPruningSettings.d.ts +44 -0
- package/dist/types/messages/format.d.ts +9 -1
- package/dist/types/messages/index.d.ts +2 -0
- package/dist/types/messages/prune.d.ts +91 -1
- package/dist/types/run.d.ts +2 -0
- package/dist/types/tools/BashExecutor.d.ts +76 -0
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +72 -0
- package/dist/types/tools/CodeExecutor.d.ts +8 -26
- package/dist/types/tools/ReadFile.d.ts +28 -0
- package/dist/types/tools/SkillTool.d.ts +40 -0
- package/dist/types/tools/SubagentTool.d.ts +36 -0
- package/dist/types/tools/ToolNode.d.ts +77 -5
- package/dist/types/tools/search/tavily-scraper.d.ts +19 -0
- package/dist/types/tools/search/tavily-search.d.ts +4 -0
- package/dist/types/tools/search/types.d.ts +99 -5
- package/dist/types/tools/search/utils.d.ts +2 -2
- package/dist/types/tools/skillCatalog.d.ts +19 -0
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +137 -0
- package/dist/types/tools/subagent/index.d.ts +2 -0
- package/dist/types/tools/subagent/types.d.ts +84 -0
- package/dist/types/tools/toolOutputReferences.d.ts +236 -0
- package/dist/types/types/agent-cache.d.ts +70 -0
- package/dist/types/types/graph.d.ts +162 -22
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/messages.d.ts +26 -0
- package/dist/types/types/run.d.ts +22 -0
- package/dist/types/types/skill.d.ts +9 -0
- package/dist/types/types/tools.d.ts +111 -0
- package/dist/types/utils/index.d.ts +1 -3
- package/dist/types/utils/truncation.d.ts +70 -0
- package/package.json +57 -17
- package/src/agents/AgentContext.js.map +1 -0
- package/src/agents/AgentContext.test.js.map +1 -0
- package/src/agents/AgentContext.ts +321 -78
- package/src/agents/__tests__/AgentContext.cacheTtl.live.test.ts +259 -0
- package/src/agents/__tests__/AgentContext.crossAgentTier1.live.test.ts +264 -0
- package/src/agents/__tests__/AgentContext.crossUserCache.live.test.ts +342 -0
- package/src/agents/__tests__/AgentContext.test.js.map +1 -0
- package/src/agents/__tests__/AgentContext.test.ts +632 -0
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js.map +1 -0
- package/src/common/__tests__/enum.test.ts +7 -17
- package/src/common/enum.js.map +1 -0
- package/src/common/enum.ts +43 -12
- package/src/common/index.js.map +1 -0
- package/src/common/index.ts +0 -1
- package/src/events.js.map +1 -0
- package/src/graphs/Graph.js.map +1 -0
- package/src/graphs/Graph.ts +222 -2
- package/src/graphs/MultiAgentGraph.js.map +1 -0
- package/src/graphs/MultiAgentGraph.ts +154 -1466
- package/src/graphs/__tests__/MultiAgentGraph.test.ts +91 -0
- package/src/graphs/__tests__/structured-output.integration.test.js.map +1 -0
- package/src/graphs/__tests__/structured-output.test.js.map +1 -0
- package/src/graphs/contextManagement.e2e.test.js.map +1 -0
- package/src/graphs/contextManagement.test.js.map +1 -0
- package/src/graphs/handoffValidation.test.js.map +1 -0
- package/src/graphs/index.js.map +1 -0
- package/src/graphs/index.ts +0 -1
- package/src/hooks/HookRegistry.ts +208 -0
- package/src/hooks/__tests__/HookRegistry.test.ts +190 -0
- package/src/hooks/__tests__/compactHooks.test.ts +214 -0
- package/src/hooks/__tests__/executeHooks.test.ts +1013 -0
- package/src/hooks/__tests__/integration.test.ts +337 -0
- package/src/hooks/__tests__/matchers.test.ts +238 -0
- package/src/hooks/__tests__/toolHooks.test.ts +665 -0
- package/src/hooks/executeHooks.ts +375 -0
- package/src/hooks/index.ts +57 -0
- package/src/hooks/matchers.ts +280 -0
- package/src/hooks/types.ts +404 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +15 -24
- package/src/instrumentation.js.map +1 -0
- package/src/langchain/google-common.ts +1 -0
- package/src/langchain/index.ts +8 -0
- package/src/langchain/language_models/chat_models.ts +1 -0
- package/src/langchain/messages/tool.ts +5 -0
- package/src/langchain/messages.ts +21 -0
- package/src/langchain/openai.ts +1 -0
- package/src/langchain/prompts.ts +1 -0
- package/src/langchain/runnables.ts +7 -0
- package/src/langchain/tools.ts +8 -0
- package/src/langchain/utils/env.ts +1 -0
- package/src/llm/anthropic/index.js.map +1 -0
- package/src/llm/anthropic/types.js.map +1 -0
- package/src/llm/anthropic/utils/message_inputs.js.map +1 -0
- package/src/llm/anthropic/utils/message_inputs.ts +10 -1
- package/src/llm/anthropic/utils/message_outputs.js.map +1 -0
- package/src/llm/anthropic/utils/output_parsers.js.map +1 -0
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +436 -0
- package/src/llm/anthropic/utils/tools.js.map +1 -0
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js.map +1 -0
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +166 -18
- package/src/llm/bedrock/cacheSupport.test.ts +99 -0
- package/src/llm/bedrock/cacheSupport.ts +53 -0
- package/src/llm/bedrock/index.js.map +1 -0
- package/src/llm/bedrock/index.ts +116 -41
- package/src/llm/bedrock/types.js.map +1 -0
- package/src/llm/bedrock/utils/index.js.map +1 -0
- package/src/llm/bedrock/utils/message_inputs.js.map +1 -0
- package/src/llm/bedrock/utils/message_outputs.js.map +1 -0
- package/src/llm/fake.js.map +1 -0
- package/src/llm/google/index.js.map +1 -0
- package/src/llm/google/types.js.map +1 -0
- package/src/llm/google/utils/common.js.map +1 -0
- package/src/llm/google/utils/tools.js.map +1 -0
- package/src/llm/google/utils/zod_to_genai_parameters.js.map +1 -0
- package/src/llm/openai/index.js.map +1 -0
- package/src/llm/openai/types.js.map +1 -0
- package/src/llm/openai/utils/index.js.map +1 -0
- package/src/llm/openai/utils/index.ts +31 -14
- package/src/llm/openai/utils/isReasoningModel.test.js.map +1 -0
- package/src/llm/openrouter/index.js.map +1 -0
- package/src/llm/openrouter/reasoning.test.js.map +1 -0
- package/src/llm/providers.js.map +1 -0
- package/src/llm/text.js.map +1 -0
- package/src/llm/vertexai/index.js.map +1 -0
- package/src/messages/__tests__/contextPruning.test.ts +228 -0
- package/src/messages/__tests__/tools.test.js.map +1 -0
- package/src/messages/cache.js.map +1 -0
- package/src/messages/cache.test.js.map +1 -0
- package/src/messages/cache.test.ts +62 -24
- package/src/messages/cache.ts +112 -0
- package/src/messages/content.js.map +1 -0
- package/src/messages/content.test.js.map +1 -0
- package/src/messages/contextPruning.ts +191 -0
- package/src/messages/contextPruningSettings.ts +90 -0
- package/src/messages/core.js.map +1 -0
- package/src/messages/ensureThinkingBlock.test.js.map +1 -0
- package/src/messages/format.js.map +1 -0
- package/src/messages/format.ts +164 -12
- package/src/messages/formatAgentMessages.skills.test.ts +413 -0
- package/src/messages/formatAgentMessages.test.js.map +1 -0
- package/src/messages/formatAgentMessages.tools.test.js.map +1 -0
- package/src/messages/formatMessage.test.js.map +1 -0
- package/src/messages/ids.js.map +1 -0
- package/src/messages/index.js.map +1 -0
- package/src/messages/index.ts +2 -0
- package/src/messages/labelContentByAgent.test.js.map +1 -0
- package/src/messages/prune.js.map +1 -0
- package/src/messages/prune.ts +661 -4
- package/src/messages/reducer.js.map +1 -0
- package/src/messages/shiftIndexTokenCountMap.test.js.map +1 -0
- package/src/messages/summarize.js.map +1 -0
- package/src/messages/summarize.test.js.map +1 -0
- package/src/messages/tools.js.map +1 -0
- package/src/mockStream.js.map +1 -0
- package/src/prompts/collab.js.map +1 -0
- package/src/prompts/index.js.map +1 -0
- package/src/prompts/taskmanager.js.map +1 -0
- package/src/run.js.map +1 -0
- package/src/run.ts +155 -1
- package/src/schemas/index.js.map +1 -0
- package/src/schemas/schema-preparation.test.js.map +1 -0
- package/src/schemas/validate.js.map +1 -0
- package/src/schemas/validate.test.js.map +1 -0
- package/src/scripts/abort.js.map +1 -0
- package/src/scripts/ant_web_search.js.map +1 -0
- package/src/scripts/ant_web_search_edge_case.js.map +1 -0
- package/src/scripts/ant_web_search_error_edge_case.js.map +1 -0
- package/src/scripts/args.js.map +1 -0
- package/src/scripts/bedrock-cache-debug.js.map +1 -0
- package/src/scripts/bedrock-content-aggregation-test.js.map +1 -0
- package/src/scripts/bedrock-merge-test.js.map +1 -0
- package/src/scripts/bedrock-parallel-tools-test.js.map +1 -0
- package/src/scripts/caching.js.map +1 -0
- package/src/scripts/cli.js.map +1 -0
- package/src/scripts/cli2.js.map +1 -0
- package/src/scripts/cli3.js.map +1 -0
- package/src/scripts/cli4.js.map +1 -0
- package/src/scripts/cli5.js.map +1 -0
- package/src/scripts/code_exec.js.map +1 -0
- package/src/scripts/code_exec_files.js.map +1 -0
- package/src/scripts/code_exec_multi_session.js.map +1 -0
- package/src/scripts/code_exec_ptc.js.map +1 -0
- package/src/scripts/code_exec_session.js.map +1 -0
- package/src/scripts/code_exec_simple.js.map +1 -0
- package/src/scripts/content.js.map +1 -0
- package/src/scripts/empty_input.js.map +1 -0
- package/src/scripts/handoff-test.js.map +1 -0
- package/src/scripts/image.js.map +1 -0
- package/src/scripts/memory.js.map +1 -0
- package/src/scripts/multi-agent-chain.js.map +1 -0
- package/src/scripts/multi-agent-chain.ts +2 -2
- package/src/scripts/multi-agent-conditional.js.map +1 -0
- package/src/scripts/multi-agent-document-review-chain.js.map +1 -0
- package/src/scripts/multi-agent-document-review-chain.ts +2 -2
- package/src/scripts/multi-agent-hybrid-flow.js.map +1 -0
- package/src/scripts/multi-agent-hybrid-flow.ts +4 -4
- package/src/scripts/multi-agent-parallel-start.js.map +1 -0
- package/src/scripts/multi-agent-parallel.js.map +1 -0
- package/src/scripts/multi-agent-parallel.ts +3 -3
- package/src/scripts/multi-agent-sequence.js.map +1 -0
- package/src/scripts/multi-agent-sequence.ts +3 -3
- package/src/scripts/multi-agent-subagent.ts +246 -0
- package/src/scripts/multi-agent-supervisor.js.map +1 -0
- package/src/scripts/multi-agent-supervisor.ts +5 -5
- package/src/scripts/multi-agent-test.js.map +1 -0
- package/src/scripts/parallel-asymmetric-tools-test.js.map +1 -0
- package/src/scripts/parallel-full-metadata-test.js.map +1 -0
- package/src/scripts/parallel-tools-test.js.map +1 -0
- package/src/scripts/poc-multi-agent-comprehensive.ts +8 -8
- package/src/scripts/programmatic_exec.js.map +1 -0
- package/src/scripts/programmatic_exec_agent.js.map +1 -0
- package/src/scripts/search.js.map +1 -0
- package/src/scripts/sequential-full-metadata-test.js.map +1 -0
- package/src/scripts/sequential-full-metadata-test.ts +2 -2
- package/src/scripts/simple.js.map +1 -0
- package/src/scripts/single-agent-metadata-test.js.map +1 -0
- package/src/scripts/stream.js.map +1 -0
- package/src/scripts/subagent-event-driven-debug.ts +190 -0
- package/src/scripts/subagent-tools-debug.ts +160 -0
- package/src/scripts/test-custom-prompt-key.js.map +1 -0
- package/src/scripts/test-custom-prompt-key.ts +3 -3
- package/src/scripts/test-handoff-input.js.map +1 -0
- package/src/scripts/test-handoff-input.ts +1 -1
- package/src/scripts/test-handoff-preamble.js.map +1 -0
- package/src/scripts/test-handoff-steering.js.map +1 -0
- package/src/scripts/test-handoff-steering.ts +3 -3
- package/src/scripts/test-multi-agent-list-handoff.js.map +1 -0
- package/src/scripts/test-multi-agent-list-handoff.ts +1 -1
- package/src/scripts/test-parallel-agent-labeling.js.map +1 -0
- package/src/scripts/test-parallel-agent-labeling.ts +3 -3
- package/src/scripts/test-parallel-handoffs.js.map +1 -0
- package/src/scripts/test-parallel-handoffs.ts +2 -2
- package/src/scripts/test-thinking-handoff-bedrock.js.map +1 -0
- package/src/scripts/test-thinking-handoff-bedrock.ts +1 -1
- package/src/scripts/test-thinking-handoff.js.map +1 -0
- package/src/scripts/test-thinking-handoff.ts +1 -1
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js.map +1 -0
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +1 -1
- package/src/scripts/test-tool-before-handoff-role-order.js.map +1 -0
- package/src/scripts/test-tool-before-handoff-role-order.ts +1 -1
- package/src/scripts/test-tools-before-handoff.js.map +1 -0
- package/src/scripts/test-tools-before-handoff.ts +1 -1
- package/src/scripts/test_code_api.js.map +1 -0
- package/src/scripts/thinking-bedrock.js.map +1 -0
- package/src/scripts/thinking-vertexai.js.map +1 -0
- package/src/scripts/thinking.js.map +1 -0
- package/src/scripts/tool_search.js.map +1 -0
- package/src/scripts/tools.js.map +1 -0
- package/src/specs/agent-handoffs-bedrock.integration.test.js.map +1 -0
- package/src/specs/agent-handoffs.test.js.map +1 -0
- package/src/specs/agent-handoffs.test.ts +26 -483
- package/src/specs/anthropic.simple.test.js.map +1 -0
- package/src/specs/anthropic.simple.test.ts +61 -0
- package/src/specs/azure.simple.test.js.map +1 -0
- package/src/specs/cache.simple.test.js.map +1 -0
- package/src/specs/custom-event-await.test.js.map +1 -0
- package/src/specs/deepseek.simple.test.js.map +1 -0
- package/src/specs/emergency-prune.test.js.map +1 -0
- package/src/specs/moonshot.simple.test.js.map +1 -0
- package/src/specs/multi-agent-summarization.test.ts +396 -0
- package/src/specs/observability.integration.test.js.map +1 -0
- package/src/specs/openai.simple.test.js.map +1 -0
- package/src/specs/openrouter.simple.test.js.map +1 -0
- package/src/specs/prune.orphans.test.ts +248 -0
- package/src/specs/prune.test.js.map +1 -0
- package/src/specs/prune.test.ts +104 -16
- package/src/specs/reasoning.test.js.map +1 -0
- package/src/specs/spec.utils.js.map +1 -0
- package/src/specs/thinking-handoff.test.js.map +1 -0
- package/src/specs/thinking-handoff.test.ts +19 -19
- package/src/specs/thinking-prune.test.js.map +1 -0
- package/src/specs/token-distribution-edge-case.test.js.map +1 -0
- package/src/specs/token-memoization.test.js.map +1 -0
- package/src/specs/tokens.test.js.map +1 -0
- package/src/specs/tool-error.test.js.map +1 -0
- package/src/splitStream.js.map +1 -0
- package/src/splitStream.test.js.map +1 -0
- package/src/stream.js.map +1 -0
- package/src/stream.test.js.map +1 -0
- package/src/test/mockTools.js.map +1 -0
- package/src/tools/BashExecutor.ts +281 -0
- package/src/tools/BashProgrammaticToolCalling.ts +397 -0
- package/src/tools/BrowserTools.js.map +1 -0
- package/src/tools/Calculator.js.map +1 -0
- package/src/tools/Calculator.test.js.map +1 -0
- package/src/tools/CodeExecutor.js.map +1 -0
- package/src/tools/CodeExecutor.ts +62 -54
- package/src/tools/ProgrammaticToolCalling.js.map +1 -0
- package/src/tools/ProgrammaticToolCalling.ts +29 -14
- package/src/tools/ReadFile.ts +39 -0
- package/src/tools/SkillTool.ts +46 -0
- package/src/tools/StreamingToolCallBuffer.js.map +1 -0
- package/src/tools/SubagentTool.ts +100 -0
- package/src/tools/ToolNode.js.map +1 -0
- package/src/tools/ToolNode.ts +548 -26
- package/src/tools/ToolSearch.js.map +1 -0
- package/src/tools/__tests__/BashExecutor.test.ts +49 -0
- package/src/tools/__tests__/BrowserTools.test.js.map +1 -0
- package/src/tools/__tests__/CodeExecutor.test.ts +37 -36
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js.map +1 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js.map +1 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +60 -0
- package/src/tools/__tests__/ReadFile.test.ts +44 -0
- package/src/tools/__tests__/SkillTool.test.ts +442 -0
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js.map +1 -0
- package/src/tools/__tests__/SubagentExecutor.test.ts +1148 -0
- package/src/tools/__tests__/SubagentTool.test.ts +149 -0
- package/src/tools/__tests__/ToolApproval.test.js.map +1 -0
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +1438 -0
- package/src/tools/__tests__/ToolNode.recovery.test.js.map +1 -0
- package/src/tools/__tests__/ToolNode.session.test.js.map +1 -0
- package/src/tools/__tests__/ToolSearch.integration.test.js.map +1 -0
- package/src/tools/__tests__/ToolSearch.test.js.map +1 -0
- package/src/tools/__tests__/annotateMessagesForLLM.test.ts +479 -0
- package/src/tools/__tests__/handlers.test.js.map +1 -0
- package/src/tools/__tests__/skillCatalog.test.ts +161 -0
- package/src/tools/__tests__/subagentHooks.test.ts +210 -0
- package/src/tools/__tests__/toolOutputReferences.test.ts +415 -0
- package/src/tools/__tests__/truncation-recovery.integration.test.js.map +1 -0
- package/src/tools/handlers.js.map +1 -0
- package/src/tools/schema.js.map +1 -0
- package/src/tools/search/anthropic.js.map +1 -0
- package/src/tools/search/content.js.map +1 -0
- package/src/tools/search/content.test.js.map +1 -0
- package/src/tools/search/firecrawl.js.map +1 -0
- package/src/tools/search/format.js.map +1 -0
- package/src/tools/search/highlights.js.map +1 -0
- package/src/tools/search/index.js.map +1 -0
- package/src/tools/search/jina-reranker.test.js.map +1 -0
- package/src/tools/search/rerankers.js.map +1 -0
- package/src/tools/search/schema.js.map +1 -0
- package/src/tools/search/search.js.map +1 -0
- package/src/tools/search/search.ts +12 -2
- package/src/tools/search/serper-scraper.js.map +1 -0
- package/src/tools/search/tavily-scraper.ts +235 -0
- package/src/tools/search/tavily-search.ts +424 -0
- package/src/tools/search/tavily.test.ts +965 -0
- package/src/tools/search/test.js.map +1 -0
- package/src/tools/search/tool.js.map +1 -0
- package/src/tools/search/tool.ts +36 -2
- package/src/tools/search/types.js.map +1 -0
- package/src/tools/search/types.ts +133 -8
- package/src/tools/search/utils.js.map +1 -0
- package/src/tools/search/utils.ts +13 -5
- package/src/tools/skillCatalog.ts +126 -0
- package/src/tools/subagent/SubagentExecutor.ts +676 -0
- package/src/tools/subagent/index.ts +13 -0
- package/src/tools/subagent/types.test.ts +70 -0
- package/src/tools/subagent/types.ts +115 -0
- package/src/tools/toolOutputReferences.ts +825 -0
- package/src/types/agent-cache.ts +73 -0
- package/src/types/graph.js.map +1 -0
- package/src/types/graph.test.js.map +1 -0
- package/src/types/graph.ts +171 -20
- package/src/types/index.js.map +1 -0
- package/src/types/index.ts +3 -0
- package/src/types/llm.js.map +1 -0
- package/src/types/messages.js.map +1 -0
- package/src/types/messages.ts +27 -0
- package/src/types/run.js.map +1 -0
- package/src/types/run.ts +22 -0
- package/src/types/skill.ts +11 -0
- package/src/types/stream.js.map +1 -0
- package/src/types/tools.js.map +1 -0
- package/src/types/tools.ts +118 -0
- package/src/utils/__tests__/truncation.test.ts +66 -0
- package/src/utils/contextAnalytics.js.map +1 -0
- package/src/utils/contextAnalytics.test.js.map +1 -0
- package/src/utils/events.js.map +1 -0
- package/src/utils/graph.js.map +1 -0
- package/src/utils/handlers.js.map +1 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/index.ts +1 -3
- package/src/utils/llm.js.map +1 -0
- package/src/utils/llmConfig.js.map +1 -0
- package/src/utils/logging.js.map +1 -0
- package/src/utils/misc.js.map +1 -0
- package/src/utils/run.js.map +1 -0
- package/src/utils/schema.js.map +1 -0
- package/src/utils/title.js.map +1 -0
- package/src/utils/tokens.js.map +1 -0
- package/src/utils/toonFormat.js.map +1 -0
- package/src/utils/truncation.ts +154 -0
- package/dist/cjs/common/spawnPath.cjs +0 -104
- package/dist/cjs/common/spawnPath.cjs.map +0 -1
- package/dist/cjs/content/ArtifactStore.cjs +0 -579
- package/dist/cjs/content/ArtifactStore.cjs.map +0 -1
- package/dist/cjs/content/ContentStore.cjs +0 -638
- package/dist/cjs/content/ContentStore.cjs.map +0 -1
- package/dist/cjs/content/contentAnalyzer.cjs +0 -91
- package/dist/cjs/content/contentAnalyzer.cjs.map +0 -1
- package/dist/cjs/content/index.cjs +0 -20
- package/dist/cjs/content/index.cjs.map +0 -1
- package/dist/cjs/content/mcpAutoCache.cjs +0 -115
- package/dist/cjs/content/mcpAutoCache.cjs.map +0 -1
- package/dist/cjs/graphs/HandoffRegistry.cjs +0 -143
- package/dist/cjs/graphs/HandoffRegistry.cjs.map +0 -1
- package/dist/cjs/providers/a2a/A2ACapabilityProvider.cjs +0 -288
- package/dist/cjs/providers/a2a/A2ACapabilityProvider.cjs.map +0 -1
- package/dist/cjs/providers/a2a/client.cjs +0 -92
- package/dist/cjs/providers/a2a/client.cjs.map +0 -1
- package/dist/cjs/providers/a2a/config.cjs +0 -38
- package/dist/cjs/providers/a2a/config.cjs.map +0 -1
- package/dist/cjs/providers/capabilityNaming.cjs +0 -43
- package/dist/cjs/providers/capabilityNaming.cjs.map +0 -1
- package/dist/cjs/providers/mcp/MCPCapabilityProvider.cjs +0 -244
- package/dist/cjs/providers/mcp/MCPCapabilityProvider.cjs.map +0 -1
- package/dist/cjs/providers/mcp/config.cjs +0 -42
- package/dist/cjs/providers/mcp/config.cjs.map +0 -1
- package/dist/cjs/providers/mcp/transport.cjs +0 -65
- package/dist/cjs/providers/mcp/transport.cjs.map +0 -1
- package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs +0 -128
- package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs.map +0 -1
- package/dist/cjs/providers/types.cjs +0 -51
- package/dist/cjs/providers/types.cjs.map +0 -1
- package/dist/cjs/tools/artifacts/schema.cjs +0 -86
- package/dist/cjs/tools/artifacts/schema.cjs.map +0 -1
- package/dist/cjs/tools/artifacts/tool.cjs +0 -219
- package/dist/cjs/tools/artifacts/tool.cjs.map +0 -1
- package/dist/cjs/tools/fileSearch/formatter.cjs +0 -93
- package/dist/cjs/tools/fileSearch/formatter.cjs.map +0 -1
- package/dist/cjs/tools/fileSearch/ragClient.cjs +0 -102
- package/dist/cjs/tools/fileSearch/ragClient.cjs.map +0 -1
- package/dist/cjs/tools/fileSearch/schema.cjs +0 -18
- package/dist/cjs/tools/fileSearch/schema.cjs.map +0 -1
- package/dist/cjs/tools/fileSearch/tool.cjs +0 -155
- package/dist/cjs/tools/fileSearch/tool.cjs.map +0 -1
- package/dist/cjs/tools/proxyTool.cjs +0 -102
- package/dist/cjs/tools/proxyTool.cjs.map +0 -1
- package/dist/cjs/utils/childAgentContext.cjs +0 -242
- package/dist/cjs/utils/childAgentContext.cjs.map +0 -1
- package/dist/cjs/utils/credentials.cjs +0 -142
- package/dist/cjs/utils/credentials.cjs.map +0 -1
- package/dist/cjs/utils/httpClient.cjs +0 -74
- package/dist/cjs/utils/httpClient.cjs.map +0 -1
- package/dist/cjs/utils/toolManifest.cjs +0 -100
- package/dist/cjs/utils/toolManifest.cjs.map +0 -1
- package/dist/esm/common/spawnPath.mjs +0 -95
- package/dist/esm/common/spawnPath.mjs.map +0 -1
- package/dist/esm/content/ArtifactStore.mjs +0 -576
- package/dist/esm/content/ArtifactStore.mjs.map +0 -1
- package/dist/esm/content/ContentStore.mjs +0 -635
- package/dist/esm/content/ContentStore.mjs.map +0 -1
- package/dist/esm/content/contentAnalyzer.mjs +0 -87
- package/dist/esm/content/contentAnalyzer.mjs.map +0 -1
- package/dist/esm/content/index.mjs +0 -5
- package/dist/esm/content/mcpAutoCache.mjs +0 -111
- package/dist/esm/content/mcpAutoCache.mjs.map +0 -1
- package/dist/esm/graphs/HandoffRegistry.mjs +0 -141
- package/dist/esm/graphs/HandoffRegistry.mjs.map +0 -1
- package/dist/esm/providers/a2a/A2ACapabilityProvider.mjs +0 -281
- package/dist/esm/providers/a2a/A2ACapabilityProvider.mjs.map +0 -1
- package/dist/esm/providers/a2a/client.mjs +0 -88
- package/dist/esm/providers/a2a/client.mjs.map +0 -1
- package/dist/esm/providers/a2a/config.mjs +0 -35
- package/dist/esm/providers/a2a/config.mjs.map +0 -1
- package/dist/esm/providers/capabilityNaming.mjs +0 -39
- package/dist/esm/providers/capabilityNaming.mjs.map +0 -1
- package/dist/esm/providers/mcp/MCPCapabilityProvider.mjs +0 -240
- package/dist/esm/providers/mcp/MCPCapabilityProvider.mjs.map +0 -1
- package/dist/esm/providers/mcp/config.mjs +0 -39
- package/dist/esm/providers/mcp/config.mjs.map +0 -1
- package/dist/esm/providers/mcp/transport.mjs +0 -63
- package/dist/esm/providers/mcp/transport.mjs.map +0 -1
- package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs +0 -126
- package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs.map +0 -1
- package/dist/esm/providers/types.mjs +0 -51
- package/dist/esm/providers/types.mjs.map +0 -1
- package/dist/esm/tools/artifacts/schema.mjs +0 -79
- package/dist/esm/tools/artifacts/schema.mjs.map +0 -1
- package/dist/esm/tools/artifacts/tool.mjs +0 -213
- package/dist/esm/tools/artifacts/tool.mjs.map +0 -1
- package/dist/esm/tools/fileSearch/formatter.mjs +0 -90
- package/dist/esm/tools/fileSearch/formatter.mjs.map +0 -1
- package/dist/esm/tools/fileSearch/ragClient.mjs +0 -98
- package/dist/esm/tools/fileSearch/ragClient.mjs.map +0 -1
- package/dist/esm/tools/fileSearch/schema.mjs +0 -15
- package/dist/esm/tools/fileSearch/schema.mjs.map +0 -1
- package/dist/esm/tools/fileSearch/tool.mjs +0 -152
- package/dist/esm/tools/fileSearch/tool.mjs.map +0 -1
- package/dist/esm/tools/proxyTool.mjs +0 -100
- package/dist/esm/tools/proxyTool.mjs.map +0 -1
- package/dist/esm/utils/childAgentContext.mjs +0 -237
- package/dist/esm/utils/childAgentContext.mjs.map +0 -1
- package/dist/esm/utils/credentials.mjs +0 -135
- package/dist/esm/utils/credentials.mjs.map +0 -1
- package/dist/esm/utils/httpClient.mjs +0 -70
- package/dist/esm/utils/httpClient.mjs.map +0 -1
- package/dist/esm/utils/toolManifest.mjs +0 -96
- package/dist/esm/utils/toolManifest.mjs.map +0 -1
- package/dist/types/common/spawnPath.d.ts +0 -59
- package/dist/types/content/ArtifactStore.d.ts +0 -223
- package/dist/types/content/ContentStore.d.ts +0 -140
- package/dist/types/content/contentAnalyzer.d.ts +0 -38
- package/dist/types/content/index.d.ts +0 -24
- package/dist/types/content/mcpAutoCache.d.ts +0 -89
- package/dist/types/content/types.d.ts +0 -75
- package/dist/types/graphs/HandoffRegistry.d.ts +0 -97
- package/dist/types/providers/a2a/A2ACapabilityProvider.d.ts +0 -89
- package/dist/types/providers/a2a/client.d.ts +0 -47
- package/dist/types/providers/a2a/config.d.ts +0 -18
- package/dist/types/providers/a2a/index.d.ts +0 -6
- package/dist/types/providers/a2a/types.d.ts +0 -173
- package/dist/types/providers/capabilityNaming.d.ts +0 -25
- package/dist/types/providers/index.d.ts +0 -12
- package/dist/types/providers/mcp/MCPCapabilityProvider.d.ts +0 -54
- package/dist/types/providers/mcp/config.d.ts +0 -20
- package/dist/types/providers/mcp/index.d.ts +0 -5
- package/dist/types/providers/mcp/transport.d.ts +0 -18
- package/dist/types/providers/mcp/types.d.ts +0 -112
- package/dist/types/providers/tools-server/ToolsServerCapabilityProvider.d.ts +0 -59
- package/dist/types/providers/tools-server/index.d.ts +0 -1
- package/dist/types/providers/types.d.ts +0 -184
- package/dist/types/tools/artifacts/index.d.ts +0 -3
- package/dist/types/tools/artifacts/schema.d.ts +0 -63
- package/dist/types/tools/artifacts/tool.d.ts +0 -16
- package/dist/types/tools/artifacts/types.d.ts +0 -127
- package/dist/types/tools/fileSearch/formatter.d.ts +0 -25
- package/dist/types/tools/fileSearch/index.d.ts +0 -5
- package/dist/types/tools/fileSearch/ragClient.d.ts +0 -32
- package/dist/types/tools/fileSearch/schema.d.ts +0 -13
- package/dist/types/tools/fileSearch/tool.d.ts +0 -18
- package/dist/types/tools/fileSearch/types.d.ts +0 -139
- package/dist/types/tools/proxyTool.d.ts +0 -62
- package/dist/types/utils/childAgentContext.d.ts +0 -99
- package/dist/types/utils/credentials.d.ts +0 -77
- package/dist/types/utils/httpClient.d.ts +0 -46
- package/dist/types/utils/toolManifest.d.ts +0 -49
- package/src/common/__tests__/spawnPath.test.ts +0 -110
- package/src/common/spawnPath.ts +0 -101
- package/src/content/ArtifactStore.ts +0 -782
- package/src/content/ContentStore.ts +0 -753
- package/src/content/contentAnalyzer.ts +0 -105
- package/src/content/index.ts +0 -51
- package/src/content/mcpAutoCache.ts +0 -185
- package/src/content/types.ts +0 -82
- package/src/graphs/HandoffRegistry.ts +0 -199
- package/src/graphs/__tests__/HandoffRegistry.test.ts +0 -410
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +0 -458
- package/src/graphs/__tests__/multi-agent-edges.test.ts +0 -276
- package/src/graphs/__tests__/multi-agent-nested-subgraph.test.ts +0 -221
- package/src/graphs/handoffValidation.test.ts +0 -353
- package/src/providers/__tests__/ToolsServerCapabilityProvider.integration.spec.ts +0 -79
- package/src/providers/__tests__/ToolsServerCapabilityProvider.test.ts +0 -271
- package/src/providers/__tests__/types.test.ts +0 -64
- package/src/providers/a2a/A2ACapabilityProvider.ts +0 -384
- package/src/providers/a2a/__tests__/A2ACapabilityProvider.integration.spec.ts +0 -345
- package/src/providers/a2a/__tests__/A2ACapabilityProvider.test.ts +0 -460
- package/src/providers/a2a/client.ts +0 -115
- package/src/providers/a2a/config.ts +0 -40
- package/src/providers/a2a/index.ts +0 -29
- package/src/providers/a2a/types.ts +0 -191
- package/src/providers/capabilityNaming.ts +0 -42
- package/src/providers/index.ts +0 -68
- package/src/providers/mcp/MCPCapabilityProvider.ts +0 -345
- package/src/providers/mcp/__tests__/MCPCapabilityProvider.integration.spec.ts +0 -386
- package/src/providers/mcp/__tests__/MCPCapabilityProvider.test.ts +0 -371
- package/src/providers/mcp/config.ts +0 -45
- package/src/providers/mcp/index.ts +0 -21
- package/src/providers/mcp/transport.ts +0 -76
- package/src/providers/mcp/types.ts +0 -139
- package/src/providers/tools-server/ToolsServerCapabilityProvider.ts +0 -249
- package/src/providers/tools-server/index.ts +0 -1
- package/src/providers/types.ts +0 -204
- package/src/scripts/test-bedrock-handoff-autonomous.ts +0 -267
- package/src/scripts/test-handoff-preamble.ts +0 -278
- package/src/specs/agent-handoffs-bedrock.integration.test.ts +0 -415
- package/src/tools/artifacts/__tests__/tool.test.ts +0 -259
- package/src/tools/artifacts/index.ts +0 -33
- package/src/tools/artifacts/schema.ts +0 -99
- package/src/tools/artifacts/tool.ts +0 -289
- package/src/tools/artifacts/types.ts +0 -162
- package/src/tools/fileSearch/__tests__/tool.test.ts +0 -261
- package/src/tools/fileSearch/formatter.ts +0 -129
- package/src/tools/fileSearch/index.ts +0 -23
- package/src/tools/fileSearch/ragClient.ts +0 -137
- package/src/tools/fileSearch/schema.ts +0 -19
- package/src/tools/fileSearch/tool.ts +0 -207
- package/src/tools/fileSearch/types.ts +0 -149
- package/src/tools/proxyTool.ts +0 -166
- package/src/utils/__tests__/childAgentContext.test.ts +0 -217
- package/src/utils/__tests__/credentials.test.ts +0 -130
- package/src/utils/__tests__/httpClient.test.ts +0 -75
- package/src/utils/__tests__/toolManifest.test.ts +0 -116
- package/src/utils/childAgentContext.ts +0 -259
- package/src/utils/credentials.ts +0 -157
- package/src/utils/httpClient.ts +0 -92
- package/src/utils/toolManifest.ts +0 -109
- /package/dist/esm/{content → langchain}/index.mjs.map +0 -0
|
@@ -4,51 +4,32 @@ var tools = require('@langchain/core/tools');
|
|
|
4
4
|
var prompts = require('@langchain/core/prompts');
|
|
5
5
|
var messages = require('@langchain/core/messages');
|
|
6
6
|
var langgraph = require('@langchain/langgraph');
|
|
7
|
-
require('
|
|
8
|
-
require('nanoid');
|
|
7
|
+
var Graph = require('./Graph.cjs');
|
|
9
8
|
var _enum = require('../common/enum.cjs');
|
|
10
|
-
var spawnPath = require('../common/spawnPath.cjs');
|
|
11
9
|
require('../tools/approval/constants.cjs');
|
|
12
|
-
require('../utils/toonFormat.cjs');
|
|
13
|
-
var summarize = require('../messages/summarize.cjs');
|
|
14
|
-
var Graph = require('./Graph.cjs');
|
|
15
|
-
var events = require('../utils/events.cjs');
|
|
16
|
-
var logging = require('../utils/logging.cjs');
|
|
17
|
-
var childAgentContext = require('../utils/childAgentContext.cjs');
|
|
18
10
|
var ApprovalGateNode = require('../nodes/ApprovalGateNode.cjs');
|
|
19
11
|
|
|
20
|
-
// HandoffRegistry no longer needed — handoff tools use synchronous
|
|
21
|
-
// browser-tool callback pattern (spawn → wait → return result)
|
|
22
12
|
/** Pattern to extract instructions from transfer ToolMessage content */
|
|
23
|
-
const
|
|
13
|
+
const HANDOFF_INSTRUCTIONS_PATTERN = /(?:Instructions?|Context):\s*(.+)/is;
|
|
24
14
|
/**
|
|
25
15
|
* MultiAgentGraph extends StandardGraph to support dynamic multi-agent workflows
|
|
26
16
|
* with handoffs, fan-in/fan-out, and other composable patterns.
|
|
27
17
|
*
|
|
28
18
|
* Key behavior:
|
|
29
|
-
* - Agents with ONLY
|
|
30
|
-
* - Agents with ONLY
|
|
31
|
-
* - Agents with BOTH: Use Command for exclusive routing (
|
|
32
|
-
* - If
|
|
33
|
-
* - If no
|
|
19
|
+
* - Agents with ONLY handoff edges: Can dynamically route to any handoff destination
|
|
20
|
+
* - Agents with ONLY direct edges: Always follow their direct edges
|
|
21
|
+
* - Agents with BOTH: Use Command for exclusive routing (handoff OR direct, not both)
|
|
22
|
+
* - If handoff occurs: Only the handoff destination executes
|
|
23
|
+
* - If no handoff: Direct edges execute (potentially in parallel)
|
|
34
24
|
*
|
|
35
|
-
* This enables the common pattern where an agent either
|
|
36
|
-
* OR continues its workflow (
|
|
25
|
+
* This enables the common pattern where an agent either delegates (handoff)
|
|
26
|
+
* OR continues its workflow (direct edges), but not both simultaneously.
|
|
37
27
|
*/
|
|
38
28
|
class MultiAgentGraph extends Graph.StandardGraph {
|
|
39
29
|
edges;
|
|
40
30
|
startingNodes = new Set();
|
|
41
|
-
|
|
42
|
-
transferEdges = [];
|
|
31
|
+
directEdges = [];
|
|
43
32
|
handoffEdges = [];
|
|
44
|
-
/**
|
|
45
|
-
* Lazily populated registry of compiled subgraphs, keyed by agentId.
|
|
46
|
-
* Handoff tools are created in the constructor but reference subgraphs
|
|
47
|
-
* that are only created in createWorkflow(). This Map bridges that gap —
|
|
48
|
-
* tools capture the Map reference in their closure, and createWorkflow()
|
|
49
|
-
* populates it before any tool invocation occurs.
|
|
50
|
-
*/
|
|
51
|
-
subgraphRegistry = new Map();
|
|
52
33
|
/**
|
|
53
34
|
* Map of agentId to parallel group info.
|
|
54
35
|
* Contains groupId (incrementing number reflecting execution order) for agents in parallel groups.
|
|
@@ -60,63 +41,76 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
60
41
|
* - summarizer: undefined (sequential, order 2)
|
|
61
42
|
*/
|
|
62
43
|
agentParallelGroups = new Map();
|
|
63
|
-
/**
|
|
64
|
-
* Tracks the ID of the last agent that produced output.
|
|
65
|
-
* Used by auto-continuation to know which agent's context to preserve after handoff.
|
|
66
|
-
*/
|
|
67
|
-
lastActiveAgentId;
|
|
68
|
-
/**
|
|
69
|
-
* Registry for async handoff execution.
|
|
70
|
-
* Enables autonomous orchestration: spawn children non-blocking,
|
|
71
|
-
* orchestrator stays alive to reason and collect results when ready.
|
|
72
|
-
*/
|
|
73
|
-
// HandoffRegistry removed — handoff tools are synchronous (callback pattern)
|
|
74
|
-
/**
|
|
75
|
-
* When set, the graph routes START to this agent instead of the default starting nodes.
|
|
76
|
-
* Enables multi-turn resumption: follow-up messages go to the agent that last handled
|
|
77
|
-
* the conversation rather than restarting from the root/router agent.
|
|
78
|
-
*/
|
|
79
|
-
resumeFromAgentId;
|
|
80
44
|
constructor(input) {
|
|
81
45
|
super(input);
|
|
82
46
|
this.edges = input.edges;
|
|
83
|
-
this.
|
|
47
|
+
this.validateEdgeAgents();
|
|
84
48
|
this.categorizeEdges();
|
|
85
49
|
this.analyzeGraph();
|
|
86
|
-
this.createTransferTools();
|
|
87
50
|
this.createHandoffTools();
|
|
88
|
-
logging.mlog(`[MultiAgentGraph] Constructor complete: ${this.agentContexts.size} agents, ${this.edges.length} edges`);
|
|
89
51
|
}
|
|
90
52
|
/**
|
|
91
|
-
*
|
|
53
|
+
* Fails fast when an edge references an agent that is not in
|
|
54
|
+
* `agentContexts`. Without this check, the underlying LangGraph
|
|
55
|
+
* `StateGraph.compile()` would throw the opaque
|
|
56
|
+
* `Found edge ending at unknown node "<id>"` error after graph
|
|
57
|
+
* construction — far from the true root cause.
|
|
58
|
+
*
|
|
59
|
+
* This catches the common misuse of passing `edges` into a multi-agent
|
|
60
|
+
* config without also passing the corresponding sub-agent configs in
|
|
61
|
+
* `agents` (e.g. a host that forgot to pre-load handoff targets).
|
|
92
62
|
*/
|
|
93
|
-
|
|
63
|
+
validateEdgeAgents() {
|
|
64
|
+
const known = new Set(this.agentContexts.keys());
|
|
65
|
+
const unknown = new Set();
|
|
94
66
|
for (const edge of this.edges) {
|
|
95
|
-
|
|
96
|
-
|
|
67
|
+
const participants = [
|
|
68
|
+
...(Array.isArray(edge.from) ? edge.from : [edge.from]),
|
|
69
|
+
...(Array.isArray(edge.to) ? edge.to : [edge.to]),
|
|
70
|
+
];
|
|
71
|
+
for (const id of participants) {
|
|
72
|
+
if (typeof id === 'string' && !known.has(id)) {
|
|
73
|
+
unknown.add(id);
|
|
74
|
+
}
|
|
97
75
|
}
|
|
98
|
-
|
|
99
|
-
|
|
76
|
+
}
|
|
77
|
+
if (unknown.size === 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const missing = Array.from(unknown)
|
|
81
|
+
.map((id) => `"${id}"`)
|
|
82
|
+
.join(', ');
|
|
83
|
+
throw new Error(`MultiAgentGraph: edges reference agent(s) not present in agents: [${missing}]. ` +
|
|
84
|
+
'Ensure every agent referenced by an edge is also included in the `agents` array, ' +
|
|
85
|
+
'or filter orphaned edges before constructing the graph.');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Categorize edges into handoff and direct types
|
|
89
|
+
*/
|
|
90
|
+
categorizeEdges() {
|
|
91
|
+
for (const edge of this.edges) {
|
|
92
|
+
// Default behavior: edges with conditions or explicit 'handoff' type are handoff edges
|
|
93
|
+
// Edges with explicit 'direct' type or multi-destination without conditions are direct edges
|
|
94
|
+
if (edge.edgeType === _enum.EdgeType.DIRECT) {
|
|
95
|
+
this.directEdges.push(edge);
|
|
100
96
|
}
|
|
101
|
-
else if (edge.edgeType === _enum.EdgeType.
|
|
102
|
-
edge
|
|
103
|
-
this.transferEdges.push(edge);
|
|
97
|
+
else if (edge.edgeType === _enum.EdgeType.HANDOFF || edge.condition != null) {
|
|
98
|
+
this.handoffEdges.push(edge);
|
|
104
99
|
}
|
|
105
100
|
else {
|
|
106
|
-
// Default: single-to-single edges are
|
|
101
|
+
// Default: single-to-single edges are handoff, single-to-multiple are direct
|
|
107
102
|
const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
108
103
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
109
104
|
if (sources.length === 1 && destinations.length > 1) {
|
|
110
|
-
// Fan-out pattern defaults to
|
|
111
|
-
this.
|
|
105
|
+
// Fan-out pattern defaults to direct
|
|
106
|
+
this.directEdges.push(edge);
|
|
112
107
|
}
|
|
113
108
|
else {
|
|
114
|
-
// Everything else defaults to
|
|
115
|
-
this.
|
|
109
|
+
// Everything else defaults to handoff
|
|
110
|
+
this.handoffEdges.push(edge);
|
|
116
111
|
}
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
|
-
logging.mlog(`[MultiAgentGraph] Edge categorization: ${this.handoffEdges.length} handoff, ${this.transferEdges.length} transfer, ${this.sequenceEdges.length} sequence (of ${this.edges.length} total)`);
|
|
120
114
|
}
|
|
121
115
|
/**
|
|
122
116
|
* Analyze graph structure to determine starting nodes and connections
|
|
@@ -138,7 +132,6 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
138
132
|
if (this.startingNodes.size === 0 && this.agentContexts.size > 0) {
|
|
139
133
|
this.startingNodes.add(this.agentContexts.keys().next().value);
|
|
140
134
|
}
|
|
141
|
-
logging.mlog(`[MultiAgentGraph] Starting nodes identified: [${Array.from(this.startingNodes).join(', ')}]`);
|
|
142
135
|
// Determine if graph has parallel execution capability
|
|
143
136
|
this.computeParallelCapability();
|
|
144
137
|
}
|
|
@@ -174,8 +167,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
174
167
|
if (visited.has(current))
|
|
175
168
|
continue;
|
|
176
169
|
visited.add(current);
|
|
177
|
-
// Find
|
|
178
|
-
for (const edge of this.
|
|
170
|
+
// Find direct edges from this node
|
|
171
|
+
for (const edge of this.directEdges) {
|
|
179
172
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
180
173
|
if (!sources.includes(current))
|
|
181
174
|
continue;
|
|
@@ -202,8 +195,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
202
195
|
}
|
|
203
196
|
}
|
|
204
197
|
}
|
|
205
|
-
// Also follow
|
|
206
|
-
for (const edge of
|
|
198
|
+
// Also follow handoff edges for traversal (but they don't create parallel groups)
|
|
199
|
+
for (const edge of this.handoffEdges) {
|
|
207
200
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
208
201
|
if (!sources.includes(current))
|
|
209
202
|
continue;
|
|
@@ -224,14 +217,6 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
224
217
|
getParallelGroupId(agentId) {
|
|
225
218
|
return this.agentParallelGroups.get(agentId);
|
|
226
219
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Returns the ID of the last agent that produced output.
|
|
229
|
-
* Used by auto-continuation to determine which agent's context to preserve
|
|
230
|
-
* when a response is truncated after an agent handoff.
|
|
231
|
-
*/
|
|
232
|
-
getLastActiveAgentId() {
|
|
233
|
-
return this.lastActiveAgentId;
|
|
234
|
-
}
|
|
235
220
|
/**
|
|
236
221
|
* Override to indicate this is a multi-agent graph.
|
|
237
222
|
* Enables agentId to be included in RunStep for frontend agent labeling.
|
|
@@ -246,59 +231,45 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
246
231
|
return this.agentParallelGroups.get(agentId);
|
|
247
232
|
}
|
|
248
233
|
/**
|
|
249
|
-
* Create
|
|
250
|
-
* Transfer tools return Command for one-way routing — parent exits, child takes over.
|
|
234
|
+
* Create handoff tools for agents based on handoff edges only
|
|
251
235
|
*/
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
236
|
+
createHandoffTools() {
|
|
237
|
+
// Group handoff edges by source agent(s)
|
|
238
|
+
const handoffsByAgent = new Map();
|
|
239
|
+
// Only process handoff edges for tool creation
|
|
240
|
+
for (const edge of this.handoffEdges) {
|
|
255
241
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
256
242
|
sources.forEach((source) => {
|
|
257
|
-
if (!
|
|
258
|
-
|
|
243
|
+
if (!handoffsByAgent.has(source)) {
|
|
244
|
+
handoffsByAgent.set(source, []);
|
|
259
245
|
}
|
|
260
|
-
|
|
246
|
+
handoffsByAgent.get(source).push(edge);
|
|
261
247
|
});
|
|
262
248
|
}
|
|
263
|
-
|
|
249
|
+
// Create handoff tools for each agent
|
|
250
|
+
for (const [agentId, edges] of handoffsByAgent) {
|
|
264
251
|
const agentContext = this.agentContexts.get(agentId);
|
|
265
252
|
if (!agentContext)
|
|
266
253
|
continue;
|
|
267
|
-
|
|
254
|
+
// Create handoff tools for this agent's outgoing edges
|
|
255
|
+
const handoffTools = [];
|
|
268
256
|
const sourceAgentName = agentContext.name ?? agentId;
|
|
269
257
|
for (const edge of edges) {
|
|
270
|
-
|
|
258
|
+
handoffTools.push(...this.createHandoffToolsForEdge(edge, agentId, sourceAgentName));
|
|
271
259
|
}
|
|
272
260
|
if (!agentContext.graphTools) {
|
|
273
261
|
agentContext.graphTools = [];
|
|
274
262
|
}
|
|
275
|
-
agentContext.graphTools.push(...
|
|
276
|
-
logging.mlog(`[MultiAgentGraph] Transfer tools for "${agentId}": [${transferTools.map((t) => t.name).join(', ')}]`);
|
|
277
|
-
// Inject orchestration guidance for agents with transfer tools
|
|
278
|
-
const childDescs = edges.flatMap((e) => {
|
|
279
|
-
const dests = Array.isArray(e.to) ? e.to : [e.to];
|
|
280
|
-
return dests.map((d) => {
|
|
281
|
-
const ctx = this.agentContexts.get(d);
|
|
282
|
-
const name = ctx?.name ?? d;
|
|
283
|
-
const desc = ctx?.description ? ` — ${ctx.description}` : '';
|
|
284
|
-
return `${name}${desc}`;
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
const guidance = this.buildOrchestratorGuidance(childDescs, transferTools.length);
|
|
288
|
-
const existing = agentContext.additionalInstructions ?? '';
|
|
289
|
-
agentContext.additionalInstructions = existing
|
|
290
|
-
? `${existing}\n\n${guidance}`
|
|
291
|
-
: guidance;
|
|
263
|
+
agentContext.graphTools.push(...handoffTools);
|
|
292
264
|
}
|
|
293
265
|
}
|
|
294
266
|
/**
|
|
295
|
-
* Create
|
|
296
|
-
*
|
|
297
|
-
* @param
|
|
298
|
-
* @param sourceAgentId - The ID of the agent that will perform the transfer
|
|
267
|
+
* Create handoff tools for an edge (handles multiple destinations)
|
|
268
|
+
* @param edge - The graph edge defining the handoff
|
|
269
|
+
* @param sourceAgentId - The ID of the agent that will perform the handoff
|
|
299
270
|
* @param sourceAgentName - The human-readable name of the source agent
|
|
300
271
|
*/
|
|
301
|
-
|
|
272
|
+
createHandoffToolsForEdge(edge, sourceAgentId, sourceAgentName) {
|
|
302
273
|
const tools$1 = [];
|
|
303
274
|
const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
304
275
|
/** If there's a condition, create a single conditional handoff tool */
|
|
@@ -306,10 +277,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
306
277
|
const toolName = 'conditional_transfer';
|
|
307
278
|
const toolDescription = edge.description ?? 'Conditionally transfer control based on state';
|
|
308
279
|
/** Check if we have a prompt for handoff input */
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
? edge.prompt
|
|
312
|
-
: undefined;
|
|
280
|
+
const hasHandoffInput = edge.prompt != null && typeof edge.prompt === 'string';
|
|
281
|
+
const handoffInputDescription = hasHandoffInput ? edge.prompt : undefined;
|
|
313
282
|
const promptKey = edge.promptKey ?? 'instructions';
|
|
314
283
|
tools$1.push(tools.tool(async (rawInput, config) => {
|
|
315
284
|
const input = rawInput;
|
|
@@ -333,7 +302,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
333
302
|
destination = Array.isArray(result) ? result[0] : destinations[0];
|
|
334
303
|
}
|
|
335
304
|
let content = `Conditionally transferred to ${destination}`;
|
|
336
|
-
if (
|
|
305
|
+
if (hasHandoffInput &&
|
|
337
306
|
promptKey in input &&
|
|
338
307
|
input[promptKey] != null) {
|
|
339
308
|
content += `\n\n${promptKey.charAt(0).toUpperCase() + promptKey.slice(1)}: ${input[promptKey]}`;
|
|
@@ -356,13 +325,13 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
356
325
|
});
|
|
357
326
|
}, {
|
|
358
327
|
name: toolName,
|
|
359
|
-
schema:
|
|
328
|
+
schema: hasHandoffInput
|
|
360
329
|
? {
|
|
361
330
|
type: 'object',
|
|
362
331
|
properties: {
|
|
363
332
|
[promptKey]: {
|
|
364
333
|
type: 'string',
|
|
365
|
-
description:
|
|
334
|
+
description: handoffInputDescription,
|
|
366
335
|
},
|
|
367
336
|
},
|
|
368
337
|
required: [],
|
|
@@ -375,12 +344,10 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
375
344
|
/** Create individual tools for each destination */
|
|
376
345
|
for (const destination of destinations) {
|
|
377
346
|
const toolName = `${_enum.Constants.LC_TRANSFER_TO_}${destination}`;
|
|
378
|
-
const
|
|
379
|
-
const toolDescription = edge.description ??
|
|
380
|
-
this.buildDefaultTransferDescription(destContext, destination);
|
|
347
|
+
const toolDescription = edge.description ?? `Transfer control to agent '${destination}'`;
|
|
381
348
|
/** Check if we have a prompt for handoff input */
|
|
382
|
-
const
|
|
383
|
-
const
|
|
349
|
+
const hasHandoffInput = edge.prompt != null && typeof edge.prompt === 'string';
|
|
350
|
+
const handoffInputDescription = hasHandoffInput
|
|
384
351
|
? edge.prompt
|
|
385
352
|
: undefined;
|
|
386
353
|
const promptKey = edge.promptKey ?? 'instructions';
|
|
@@ -389,7 +356,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
389
356
|
const toolCallId = config?.toolCall?.id ??
|
|
390
357
|
'unknown';
|
|
391
358
|
let content = `Successfully transferred to ${destination}`;
|
|
392
|
-
if (
|
|
359
|
+
if (hasHandoffInput &&
|
|
393
360
|
promptKey in input &&
|
|
394
361
|
input[promptKey] != null) {
|
|
395
362
|
content += `\n\n${promptKey.charAt(0).toUpperCase() + promptKey.slice(1)}: ${input[promptKey]}`;
|
|
@@ -466,13 +433,13 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
466
433
|
});
|
|
467
434
|
}, {
|
|
468
435
|
name: toolName,
|
|
469
|
-
schema:
|
|
436
|
+
schema: hasHandoffInput
|
|
470
437
|
? {
|
|
471
438
|
type: 'object',
|
|
472
439
|
properties: {
|
|
473
440
|
[promptKey]: {
|
|
474
441
|
type: 'string',
|
|
475
|
-
description:
|
|
442
|
+
description: handoffInputDescription,
|
|
476
443
|
},
|
|
477
444
|
},
|
|
478
445
|
required: [],
|
|
@@ -484,630 +451,12 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
484
451
|
}
|
|
485
452
|
return tools$1;
|
|
486
453
|
}
|
|
487
|
-
/**
|
|
488
|
-
* Builds orchestration guidance injected into the system message of agents
|
|
489
|
-
* that have handoff or transfer tools (i.e., orchestrator agents).
|
|
490
|
-
*
|
|
491
|
-
* Implements two orchestration primitives:
|
|
492
|
-
* - Execution bias guidance injected into the system prompt
|
|
493
|
-
* - Multi-round autonomous execution for dependent tasks
|
|
494
|
-
*
|
|
495
|
-
* Handoff tools are synchronous (browser-tool callback pattern): spawn the
|
|
496
|
-
* child, await completion, return the real text as the tool output. Parallel
|
|
497
|
-
* handoff tool calls in one turn run concurrently via LangGraph's ToolNode,
|
|
498
|
-
* so independent children run in parallel without explicit orchestration.
|
|
499
|
-
*
|
|
500
|
-
* @param childDescs - Display names (with optional descriptions) of child agents
|
|
501
|
-
* @param toolCount - Number of handoff/transfer tools available
|
|
502
|
-
*/
|
|
503
|
-
buildOrchestratorGuidance(childDescs, toolCount) {
|
|
504
|
-
return [
|
|
505
|
-
'## Agent Orchestration',
|
|
506
|
-
'',
|
|
507
|
-
`You have ${toolCount} specialist agent(s) available for delegation:`,
|
|
508
|
-
...childDescs.map((d) => `- ${d}`),
|
|
509
|
-
'',
|
|
510
|
-
'## Execution Bias',
|
|
511
|
-
'If the user asks you to do the work, start doing it in the same turn.',
|
|
512
|
-
'Use a real tool call or concrete action first when the task is actionable; do not stop at a plan or promise-to-act reply.',
|
|
513
|
-
'Commentary-only turns are incomplete when tools are available and the next action is clear.',
|
|
514
|
-
'If the work will take multiple steps or a while to finish, send one short progress update before or while acting.',
|
|
515
|
-
'',
|
|
516
|
-
'## How Delegation Works',
|
|
517
|
-
'Each handoff tool call spawns a sub-agent, waits for it to complete, and returns the real result directly — like a function call.',
|
|
518
|
-
'Independent tasks MAY be called in parallel (multiple handoff tool calls in one turn). They run concurrently and all results return together.',
|
|
519
|
-
'Dependent tasks MUST be sequential: call one agent, get the result, then call the next agent using that real data.',
|
|
520
|
-
'',
|
|
521
|
-
'## Agent Isolation',
|
|
522
|
-
"Sub-agents CANNOT see your conversation or the user's original message. They ONLY see what you write in the `instructions` parameter.",
|
|
523
|
-
"When writing instructions, include ALL data the agent needs. Copy exact values from the user's message — email addresses, names, URLs, dates, numbers.",
|
|
524
|
-
'When delegating follow-up work, include the real data from prior agent results directly in the instructions text.',
|
|
525
|
-
'Do NOT re-delegate a task that was already completed. If you have the data, pass it directly.',
|
|
526
|
-
].join('\n');
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Builds subagent context instructions injected into child agents that are
|
|
530
|
-
* handoff destinations. This tells the child agent it is a subagent with
|
|
531
|
-
* a focused task.
|
|
532
|
-
*
|
|
533
|
-
* @param orchestratorName - Display name of the parent orchestrator agent
|
|
534
|
-
*/
|
|
535
|
-
buildChildAgentContext(orchestratorName) {
|
|
536
|
-
return [
|
|
537
|
-
'# Subagent Context',
|
|
538
|
-
'',
|
|
539
|
-
`You are a **subagent** spawned by the ${orchestratorName} for a specific task.`,
|
|
540
|
-
'',
|
|
541
|
-
'## Your Role',
|
|
542
|
-
"- Complete this task. That's your entire purpose.",
|
|
543
|
-
`- You are NOT the ${orchestratorName}. Don't try to be.`,
|
|
544
|
-
'',
|
|
545
|
-
'## Rules',
|
|
546
|
-
'1. **Stay focused** - Do your assigned task, nothing else',
|
|
547
|
-
`2. **Complete the task** - Your final message will be automatically reported to the ${orchestratorName}`,
|
|
548
|
-
"3. **Don't initiate** - No heartbeats, no proactive actions, no side quests",
|
|
549
|
-
"4. **Be ephemeral** - You may be terminated after task completion. That's fine.",
|
|
550
|
-
'',
|
|
551
|
-
'## Output Format',
|
|
552
|
-
'When complete, your final response should include:',
|
|
553
|
-
'- What you accomplished or found',
|
|
554
|
-
`- Any relevant details the ${orchestratorName} should know`,
|
|
555
|
-
'- Keep it concise but informative',
|
|
556
|
-
'',
|
|
557
|
-
"## What You DON'T Do",
|
|
558
|
-
`- NO user conversations (that's ${orchestratorName}'s job)`,
|
|
559
|
-
'- NO external messages (email, tweets, etc.) unless explicitly tasked with a specific recipient/channel',
|
|
560
|
-
'- NO cron jobs or persistent state',
|
|
561
|
-
`- NO pretending to be the ${orchestratorName}`,
|
|
562
|
-
].join('\n');
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Builds a meaningful default description for a transfer tool when no explicit
|
|
566
|
-
* edge.description is provided. Uses the destination agent's name and description
|
|
567
|
-
* so the LLM can make informed routing decisions.
|
|
568
|
-
* @param destContext - AgentContext of the destination agent (may be undefined)
|
|
569
|
-
* @param destinationId - Raw agent ID (fallback when context unavailable)
|
|
570
|
-
*/
|
|
571
|
-
buildDefaultTransferDescription(destContext, destinationId) {
|
|
572
|
-
const displayName = destContext?.name ?? destinationId;
|
|
573
|
-
const agentDescription = destContext?.description;
|
|
574
|
-
if (agentDescription != null && agentDescription !== '') {
|
|
575
|
-
return `Transfer to "${displayName}": ${agentDescription}`;
|
|
576
|
-
}
|
|
577
|
-
return `Transfer control to "${displayName}"`;
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Create handoff tools for agents based on handoff edges.
|
|
581
|
-
* Handoff tools invoke child agent subgraphs inline and return the result
|
|
582
|
-
* as a string to the parent agent's context. Unlike transfer tools (which
|
|
583
|
-
* return Command for one-way routing), handoff tools execute the child,
|
|
584
|
-
* extract the final text, and return it within the parent's agent loop.
|
|
585
|
-
*
|
|
586
|
-
* This enables the supervisor pattern: parent calls child → gets result → thinks → calls another.
|
|
587
|
-
*/
|
|
588
|
-
createHandoffTools() {
|
|
589
|
-
const handoffsByAgent = new Map();
|
|
590
|
-
for (const edge of this.handoffEdges) {
|
|
591
|
-
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
592
|
-
sources.forEach((source) => {
|
|
593
|
-
if (!handoffsByAgent.has(source)) {
|
|
594
|
-
handoffsByAgent.set(source, []);
|
|
595
|
-
}
|
|
596
|
-
handoffsByAgent.get(source).push(edge);
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
for (const [agentId, edges] of handoffsByAgent) {
|
|
600
|
-
const agentContext = this.agentContexts.get(agentId);
|
|
601
|
-
if (!agentContext)
|
|
602
|
-
continue;
|
|
603
|
-
const handoffTools = [];
|
|
604
|
-
for (const edge of edges) {
|
|
605
|
-
handoffTools.push(...this.createHandoffToolsForEdge(edge, agentId));
|
|
606
|
-
}
|
|
607
|
-
if (!agentContext.graphTools) {
|
|
608
|
-
agentContext.graphTools = [];
|
|
609
|
-
}
|
|
610
|
-
agentContext.graphTools.push(...handoffTools);
|
|
611
|
-
// No collect_results tool needed — handoff tools use the browser-tool
|
|
612
|
-
// callback pattern: spawn child, wait for completion, return real result.
|
|
613
|
-
// The LLM naturally gets child results as tool return values.
|
|
614
|
-
logging.mlog(`[MultiAgentGraph] Handoff tools for "${agentId}": [${handoffTools.map((t) => t.name).join(', ')}]`);
|
|
615
|
-
// Inject autonomous orchestration guidance for agents with handoff tools.
|
|
616
|
-
const childDescs = edges.flatMap((e) => {
|
|
617
|
-
const dests = Array.isArray(e.to) ? e.to : [e.to];
|
|
618
|
-
return dests.map((d) => {
|
|
619
|
-
const ctx = this.agentContexts.get(d);
|
|
620
|
-
const name = ctx?.name ?? d;
|
|
621
|
-
const desc = ctx?.description ? ` — ${ctx.description}` : '';
|
|
622
|
-
return `${name}${desc}`;
|
|
623
|
-
});
|
|
624
|
-
});
|
|
625
|
-
const orchestrationGuidance = this.buildOrchestratorGuidance(childDescs, handoffTools.length);
|
|
626
|
-
const existing = agentContext.additionalInstructions ?? '';
|
|
627
|
-
agentContext.additionalInstructions = existing
|
|
628
|
-
? `${existing}\n\n${orchestrationGuidance}`
|
|
629
|
-
: orchestrationGuidance;
|
|
630
|
-
// Inject subagent context into each child/destination agent.
|
|
631
|
-
// This tells child agents they are subagents with a focused task — stay focused,
|
|
632
|
-
// execute (don't plan), and return results to the orchestrator.
|
|
633
|
-
const orchestratorName = agentContext.name ?? agentId;
|
|
634
|
-
const childAgentContext = this.buildChildAgentContext(orchestratorName);
|
|
635
|
-
for (const edge of edges) {
|
|
636
|
-
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
637
|
-
for (const destId of dests) {
|
|
638
|
-
const destCtx = this.agentContexts.get(destId);
|
|
639
|
-
if (!destCtx)
|
|
640
|
-
continue;
|
|
641
|
-
const existingChild = destCtx.additionalInstructions ?? '';
|
|
642
|
-
// Avoid duplicate injection if agent is destination of multiple edges
|
|
643
|
-
if (existingChild.includes('# Subagent Context'))
|
|
644
|
-
continue;
|
|
645
|
-
destCtx.additionalInstructions = existingChild
|
|
646
|
-
? `${existingChild}\n\n${childAgentContext}`
|
|
647
|
-
: childAgentContext;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Create handoff tools for an edge (handles multiple destinations).
|
|
654
|
-
* Each handoff tool spawns the child agent's compiled subgraph asynchronously
|
|
655
|
-
* and returns immediately. The orchestrator uses `collect_results` to retrieve
|
|
656
|
-
* outputs and `check_agents` to monitor status — a push-based autonomous
|
|
657
|
-
* orchestration pattern.
|
|
658
|
-
*
|
|
659
|
-
* @param edge - The graph edge defining the handoff
|
|
660
|
-
* @param sourceAgentId - The ID of the parent/supervisor agent
|
|
661
|
-
*/
|
|
662
|
-
createHandoffToolsForEdge(edge, sourceAgentId) {
|
|
663
|
-
const tools$1 = [];
|
|
664
|
-
const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
665
|
-
const maxResultChars = edge.maxResultChars ?? _enum.DEFAULT_HANDOFF_MAX_RESULT_CHARS;
|
|
666
|
-
for (const destination of destinations) {
|
|
667
|
-
const toolName = `${_enum.Constants.LC_HANDOFF_TO_}${destination}`;
|
|
668
|
-
const destContext = this.agentContexts.get(destination);
|
|
669
|
-
const toolDescription = edge.description ??
|
|
670
|
-
this.buildDefaultHandoffDescription(destContext, destination);
|
|
671
|
-
/**
|
|
672
|
-
* Always include an instructions parameter so the orchestrator can
|
|
673
|
-
* pass scoped task descriptions to each child agent. Without this,
|
|
674
|
-
* the child gets no context about what to do.
|
|
675
|
-
*/
|
|
676
|
-
const promptKey = edge.promptKey ?? 'instructions';
|
|
677
|
-
const destDesc = destContext?.description;
|
|
678
|
-
const promptInputDescription = edge.prompt ??
|
|
679
|
-
(destDesc
|
|
680
|
-
? `Task instructions for this agent (${destDesc}). Describe exactly what it should do.`
|
|
681
|
-
: 'Specific task instructions for this agent. Describe exactly what it should do and what data to use.');
|
|
682
|
-
/** Capture registry reference — Map populated in createWorkflow() */
|
|
683
|
-
const subgraphReg = this.subgraphRegistry;
|
|
684
|
-
tools$1.push(tools.tool(async (rawInput, config) => {
|
|
685
|
-
const input = rawInput;
|
|
686
|
-
const subgraph = subgraphReg.get(destination);
|
|
687
|
-
if (!subgraph) {
|
|
688
|
-
throw new Error(`Handoff target "${destination}" subgraph not found in registry. ` +
|
|
689
|
-
'This is a bug: createWorkflow() should have populated the subgraph registry.');
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Per-spawn unique key = the orchestrator's tool_call.id.
|
|
693
|
-
* LangChain's ToolNode passes `config.toolCall.id` to the tool
|
|
694
|
-
* function; this is the same id the frontend sees on the parent's
|
|
695
|
-
* handoff content part, so the UI can match each AgentHandoff
|
|
696
|
-
* indicator to its own sidebar task without collision when the
|
|
697
|
-
* same agent is invoked multiple times.
|
|
698
|
-
*/
|
|
699
|
-
const toolCallCfg = config?.toolCall;
|
|
700
|
-
const spawnKey = toolCallCfg?.id ??
|
|
701
|
-
`${destination}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
702
|
-
/**
|
|
703
|
-
* Hierarchical spawnPath: parent's spawnPath (from metadata) + this spawnKey.
|
|
704
|
-
* Root invocations have empty parentSpawnPath. Threaded through childConfig
|
|
705
|
-
* so nested handoffs/sequences inherit the full ancestry.
|
|
706
|
-
* See docs/multi-agent-nesting-architecture.md §4.
|
|
707
|
-
*/
|
|
708
|
-
const parentMetadata = config?.metadata;
|
|
709
|
-
const parentSpawnPath = typeof parentMetadata?.spawnPath === 'string'
|
|
710
|
-
? parentMetadata.spawnPath
|
|
711
|
-
: '';
|
|
712
|
-
const childSpawnPath = spawnPath.buildSpawnPath(parentSpawnPath, spawnKey);
|
|
713
|
-
const childDepth = spawnPath.spawnPathDepth(childSpawnPath);
|
|
714
|
-
/**
|
|
715
|
-
* Child agent message construction — three modes:
|
|
716
|
-
*
|
|
717
|
-
* 1. Default (isolated-session pattern): Child gets ONLY the orchestrator's
|
|
718
|
-
* task instructions as a single HumanMessage. No parent conversation
|
|
719
|
-
* leaks. Orchestrator controls exactly what context the child sees.
|
|
720
|
-
*
|
|
721
|
-
* 2. Passthrough (edge.passthrough = true): Child gets the full parent
|
|
722
|
-
* conversation + orchestrator's instructions appended. Use this when
|
|
723
|
-
* the child needs the full user context (e.g., a transfer-like handoff).
|
|
724
|
-
*
|
|
725
|
-
* 3. Fallback: If no instructions provided AND not passthrough, child
|
|
726
|
-
* gets the agent's description as its task.
|
|
727
|
-
*/
|
|
728
|
-
const taskDescription = promptKey in input && input[promptKey] != null
|
|
729
|
-
? String(input[promptKey])
|
|
730
|
-
: '';
|
|
731
|
-
let childMessages;
|
|
732
|
-
if (edge.passthrough) {
|
|
733
|
-
// Passthrough: full parent context + instructions appended
|
|
734
|
-
const state = langgraph.getCurrentTaskInput();
|
|
735
|
-
childMessages = MultiAgentGraph.prepareHandoffMessages([
|
|
736
|
-
...state.messages,
|
|
737
|
-
]);
|
|
738
|
-
if (taskDescription) {
|
|
739
|
-
childMessages.push(new messages.HumanMessage(taskDescription));
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
else {
|
|
743
|
-
// Default: isolated — only orchestrator's instructions
|
|
744
|
-
const fallbackTask = destContext?.description ?? 'Complete your assigned task.';
|
|
745
|
-
childMessages = [
|
|
746
|
-
new messages.HumanMessage(taskDescription || fallbackTask),
|
|
747
|
-
];
|
|
748
|
-
}
|
|
749
|
-
const childState = {
|
|
750
|
-
messages: childMessages,
|
|
751
|
-
};
|
|
752
|
-
const childContext = this.agentContexts.get(destination);
|
|
753
|
-
const destName = destContext?.name ?? destination;
|
|
754
|
-
logging.mlog(`[MultiAgentGraph] Handoff "${sourceAgentId}" -> "${destination}" SPAWN (async)\n` +
|
|
755
|
-
` messages: ${childMessages.length}\n` +
|
|
756
|
-
` childTools: ${childContext?.tools?.length ?? 0} instances\n` +
|
|
757
|
-
` childToolDefs: ${childContext?.toolDefinitions?.length ?? 0} definitions`);
|
|
758
|
-
/**
|
|
759
|
-
* Dispatch transition BEFORE spawning the child subgraph so that
|
|
760
|
-
* callbacks.js sets multiAgentTrace.isMultiAgent = true before the
|
|
761
|
-
* child's ON_RUN_STEP events fire. spawnKey lets the UI create a
|
|
762
|
-
* distinct sidebar task for this specific invocation.
|
|
763
|
-
*/
|
|
764
|
-
logging.mlog(`[MultiAgentGraph] Handoff SPAWN "${sourceAgentId}" -> "${destination}" spawnKey=${spawnKey}`);
|
|
765
|
-
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
766
|
-
sourceAgentId: sourceAgentId,
|
|
767
|
-
sourceAgentName: this.agentContexts.get(sourceAgentId)?.name ?? sourceAgentId,
|
|
768
|
-
destinationAgentId: destination,
|
|
769
|
-
destinationAgentName: destName,
|
|
770
|
-
edgeType: _enum.EdgeType.HANDOFF,
|
|
771
|
-
timestamp: Date.now(),
|
|
772
|
-
spawnKey,
|
|
773
|
-
spawnPath: childSpawnPath,
|
|
774
|
-
parentSpawnPath: parentSpawnPath || null,
|
|
775
|
-
spawnDepth: childDepth,
|
|
776
|
-
}, config);
|
|
777
|
-
/**
|
|
778
|
-
* Child events need to carry spawnKey so callbacks.js can route
|
|
779
|
-
* them to the correct child aggregator. LangChain propagates
|
|
780
|
-
* `metadata` and `tags` from the parent config to all descendants,
|
|
781
|
-
* so everything dispatched inside subgraph.invoke will have
|
|
782
|
-
* metadata.spawnKey populated on the event's runtime metadata.
|
|
783
|
-
*/
|
|
784
|
-
const childConfig = {
|
|
785
|
-
...(config ?? {}),
|
|
786
|
-
metadata: {
|
|
787
|
-
...(config?.metadata ?? {}),
|
|
788
|
-
spawnKey,
|
|
789
|
-
spawnAgentId: destination,
|
|
790
|
-
/** Hierarchical identity — see spawnPath.ts */
|
|
791
|
-
spawnPath: childSpawnPath,
|
|
792
|
-
parentSpawnPath: parentSpawnPath || null,
|
|
793
|
-
spawnDepth: childDepth,
|
|
794
|
-
},
|
|
795
|
-
tags: [
|
|
796
|
-
...(config?.tags ?? []),
|
|
797
|
-
`spawn:${spawnKey}`,
|
|
798
|
-
`depth:${childDepth}`,
|
|
799
|
-
],
|
|
800
|
-
};
|
|
801
|
-
/**
|
|
802
|
-
* Callback pattern: spawn child, WAIT for completion, return real
|
|
803
|
-
* result. The parent naturally sees child results in its tool
|
|
804
|
-
* return, so no manual "collect_results" step is needed.
|
|
805
|
-
*
|
|
806
|
-
* Parallelism still works: when the LLM emits multiple handoff
|
|
807
|
-
* tool calls in one response, LangGraph runs all tool functions
|
|
808
|
-
* concurrently. Each waits for its child. All results land in
|
|
809
|
-
* the LLM's next turn together.
|
|
810
|
-
*/
|
|
811
|
-
const spawnedAt = Date.now();
|
|
812
|
-
try {
|
|
813
|
-
const result = await subgraph.invoke(childState, childConfig);
|
|
814
|
-
const durationMs = Date.now() - spawnedAt;
|
|
815
|
-
const resultText = MultiAgentGraph.extractHandoffResult(result.messages, destination);
|
|
816
|
-
const truncated = MultiAgentGraph.truncateHandoffResult(resultText, maxResultChars);
|
|
817
|
-
logging.mlog(`[MultiAgentGraph] Handoff COMPLETED "${sourceAgentId}" -> "${destination}" ` +
|
|
818
|
-
`spawnKey=${spawnKey} (${durationMs}ms, ${truncated.length} chars)`);
|
|
819
|
-
/** Dispatch completion event for UI update — carries spawnKey so
|
|
820
|
-
* the frontend can mark the correct sidebar task as completed. */
|
|
821
|
-
events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
822
|
-
sourceAgentId: destination,
|
|
823
|
-
sourceAgentName: destName,
|
|
824
|
-
destinationAgentId: sourceAgentId,
|
|
825
|
-
destinationAgentName: this.agentContexts.get(sourceAgentId)?.name ??
|
|
826
|
-
sourceAgentId,
|
|
827
|
-
edgeType: _enum.EdgeType.HANDOFF,
|
|
828
|
-
timestamp: Date.now(),
|
|
829
|
-
isCompletion: true,
|
|
830
|
-
durationMs,
|
|
831
|
-
resultLength: truncated.length,
|
|
832
|
-
spawnKey,
|
|
833
|
-
spawnPath: childSpawnPath,
|
|
834
|
-
parentSpawnPath: parentSpawnPath || null,
|
|
835
|
-
spawnDepth: childDepth,
|
|
836
|
-
}, config).catch(() => {
|
|
837
|
-
/* best-effort event dispatch */
|
|
838
|
-
});
|
|
839
|
-
return truncated;
|
|
840
|
-
}
|
|
841
|
-
catch (err) {
|
|
842
|
-
const durationMs = Date.now() - spawnedAt;
|
|
843
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
844
|
-
// EPIPE from console.debug is non-fatal
|
|
845
|
-
if (errMsg.includes('EPIPE')) {
|
|
846
|
-
logging.mwarn(`[MultiAgentGraph] Child "${destination}" hit EPIPE (non-fatal) spawnKey=${spawnKey}`);
|
|
847
|
-
events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
848
|
-
sourceAgentId: destination,
|
|
849
|
-
sourceAgentName: destName,
|
|
850
|
-
destinationAgentId: sourceAgentId,
|
|
851
|
-
destinationAgentName: this.agentContexts.get(sourceAgentId)?.name ??
|
|
852
|
-
sourceAgentId,
|
|
853
|
-
edgeType: _enum.EdgeType.HANDOFF,
|
|
854
|
-
timestamp: Date.now(),
|
|
855
|
-
isCompletion: true,
|
|
856
|
-
durationMs,
|
|
857
|
-
spawnKey,
|
|
858
|
-
spawnPath: childSpawnPath,
|
|
859
|
-
parentSpawnPath: parentSpawnPath || null,
|
|
860
|
-
spawnDepth: childDepth,
|
|
861
|
-
}, config).catch(() => {
|
|
862
|
-
/* best-effort */
|
|
863
|
-
});
|
|
864
|
-
return `Agent "${destName}" completed but output was lost due to stream closure.`;
|
|
865
|
-
}
|
|
866
|
-
console.error(`[MultiAgentGraph] Handoff FAILED "${sourceAgentId}" -> "${destination}" ` +
|
|
867
|
-
`spawnKey=${spawnKey} (${durationMs}ms): ${errMsg}`);
|
|
868
|
-
events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
869
|
-
sourceAgentId: destination,
|
|
870
|
-
sourceAgentName: destName,
|
|
871
|
-
destinationAgentId: sourceAgentId,
|
|
872
|
-
destinationAgentName: this.agentContexts.get(sourceAgentId)?.name ??
|
|
873
|
-
sourceAgentId,
|
|
874
|
-
edgeType: _enum.EdgeType.HANDOFF,
|
|
875
|
-
timestamp: Date.now(),
|
|
876
|
-
isCompletion: true,
|
|
877
|
-
durationMs,
|
|
878
|
-
spawnKey,
|
|
879
|
-
spawnPath: childSpawnPath,
|
|
880
|
-
parentSpawnPath: parentSpawnPath || null,
|
|
881
|
-
spawnDepth: childDepth,
|
|
882
|
-
error: errMsg,
|
|
883
|
-
}, config).catch(() => {
|
|
884
|
-
/* best-effort */
|
|
885
|
-
});
|
|
886
|
-
return `Agent "${destName}" failed after ${durationMs}ms: ${errMsg}`;
|
|
887
|
-
}
|
|
888
|
-
}, {
|
|
889
|
-
name: toolName,
|
|
890
|
-
schema: {
|
|
891
|
-
type: 'object',
|
|
892
|
-
properties: {
|
|
893
|
-
[promptKey]: {
|
|
894
|
-
type: 'string',
|
|
895
|
-
description: promptInputDescription,
|
|
896
|
-
},
|
|
897
|
-
},
|
|
898
|
-
required: [promptKey],
|
|
899
|
-
},
|
|
900
|
-
description: toolDescription,
|
|
901
|
-
}));
|
|
902
|
-
}
|
|
903
|
-
return tools$1;
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Extract the final text result from a child agent's output messages.
|
|
907
|
-
* Walks backwards to find the last AIMessage with text content.
|
|
908
|
-
* Handles both string content and array content (multi-modal messages).
|
|
909
|
-
* @param messages - The child agent's output messages
|
|
910
|
-
* @param agentId - The child agent ID (for fallback message)
|
|
911
|
-
*/
|
|
912
|
-
static extractHandoffResult(messages, agentId) {
|
|
913
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
914
|
-
const msg = messages[i];
|
|
915
|
-
if (msg.getType() !== 'ai')
|
|
916
|
-
continue;
|
|
917
|
-
const content = msg.content;
|
|
918
|
-
if (typeof content === 'string' && content.trim()) {
|
|
919
|
-
return content.trim();
|
|
920
|
-
}
|
|
921
|
-
/** Handle array content (multi-modal messages with text blocks) */
|
|
922
|
-
if (Array.isArray(content)) {
|
|
923
|
-
const textParts = content
|
|
924
|
-
.filter((block) => typeof block === 'object' &&
|
|
925
|
-
block !== null &&
|
|
926
|
-
'type' in block &&
|
|
927
|
-
block.type === 'text' &&
|
|
928
|
-
'text' in block &&
|
|
929
|
-
typeof block.text === 'string')
|
|
930
|
-
.map((block) => block.text);
|
|
931
|
-
const text = textParts.join('\n').trim();
|
|
932
|
-
if (text)
|
|
933
|
-
return text;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
return `[Agent "${agentId}" completed but produced no text output]`;
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Truncate handoff result using head/tail strategy (60/40 split).
|
|
940
|
-
* Preserves the beginning (key findings) and end (conclusions).
|
|
941
|
-
* Matches the TaskTool.truncateResult pattern used by host orchestrators.
|
|
942
|
-
* @param result - The full result text
|
|
943
|
-
* @param maxChars - Maximum allowed characters
|
|
944
|
-
*/
|
|
945
|
-
static truncateHandoffResult(result, maxChars) {
|
|
946
|
-
if (!result || result.length <= maxChars) {
|
|
947
|
-
return result;
|
|
948
|
-
}
|
|
949
|
-
const truncationNotice = '\n\n[... handoff output truncated — middle section omitted to fit parent context ...]\n\n';
|
|
950
|
-
const available = maxChars - truncationNotice.length;
|
|
951
|
-
if (available <= 0) {
|
|
952
|
-
return result.substring(0, maxChars);
|
|
953
|
-
}
|
|
954
|
-
const headSize = Math.floor(available * 0.6);
|
|
955
|
-
const tailSize = available - headSize;
|
|
956
|
-
return (result.substring(0, headSize) +
|
|
957
|
-
truncationNotice +
|
|
958
|
-
result.substring(result.length - tailSize));
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Build a meaningful default description for a handoff tool.
|
|
962
|
-
* @param destContext - AgentContext of the destination agent
|
|
963
|
-
* @param destinationId - Raw agent ID (fallback)
|
|
964
|
-
*/
|
|
965
|
-
buildDefaultHandoffDescription(destContext, destinationId) {
|
|
966
|
-
const displayName = destContext?.name ?? destinationId;
|
|
967
|
-
const agentDescription = destContext?.description;
|
|
968
|
-
if (agentDescription != null && agentDescription !== '') {
|
|
969
|
-
return `Hand off task to "${displayName}": ${agentDescription}. The agent will execute and return its result.`;
|
|
970
|
-
}
|
|
971
|
-
return `Hand off task to "${displayName}" and receive its result.`;
|
|
972
|
-
}
|
|
973
454
|
/**
|
|
974
455
|
* Create a complete agent subgraph (similar to createReactAgent)
|
|
975
456
|
*/
|
|
976
457
|
createAgentSubgraph(agentId) {
|
|
977
|
-
/**
|
|
978
|
-
|
|
979
|
-
*
|
|
980
|
-
* If the handoff target has outgoing sequence/transfer edges (e.g. a
|
|
981
|
-
* "researcher" agent with its own sequence `[researcher → prod_assistant]`),
|
|
982
|
-
* we compile a mini-StateGraph containing the agent and all agents reachable
|
|
983
|
-
* from it via non-handoff edges. This way, when the parent hands off to
|
|
984
|
-
* researcher via `subgraph.invoke()`, the nested sequence runs to completion
|
|
985
|
-
* before the result is returned to the parent.
|
|
986
|
-
*
|
|
987
|
-
* Fast path: if no downstream agents are reachable, fall back to the
|
|
988
|
-
* previous single-node behavior (`createAgentNode`).
|
|
989
|
-
*
|
|
990
|
-
* See docs/multi-agent-nesting-architecture.md §6.
|
|
991
|
-
*/
|
|
992
|
-
const reachable = this.computeReachableViaNonHandoff(agentId);
|
|
993
|
-
if (reachable.size === 1) {
|
|
994
|
-
return this.createAgentNode(agentId);
|
|
995
|
-
}
|
|
996
|
-
logging.mlog(`[MultiAgentGraph] Scoped subgraph for "${agentId}": ${reachable.size} nodes [${Array.from(reachable).join(', ')}]`);
|
|
997
|
-
return this.buildScopedSubgraph(agentId, reachable);
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* BFS from `rootAgentId` across sequence + transfer edges (NOT handoff edges).
|
|
1001
|
-
* Returns the set of agents reachable in this agent's "local workflow".
|
|
1002
|
-
*/
|
|
1003
|
-
computeReachableViaNonHandoff(rootAgentId) {
|
|
1004
|
-
const reachable = new Set([rootAgentId]);
|
|
1005
|
-
const queue = [rootAgentId];
|
|
1006
|
-
const localEdges = [...this.sequenceEdges, ...this.transferEdges];
|
|
1007
|
-
while (queue.length > 0) {
|
|
1008
|
-
const current = queue.shift();
|
|
1009
|
-
for (const edge of localEdges) {
|
|
1010
|
-
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1011
|
-
if (!sources.includes(current))
|
|
1012
|
-
continue;
|
|
1013
|
-
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1014
|
-
for (const dest of dests) {
|
|
1015
|
-
if (!reachable.has(dest) && this.agentContexts.has(dest)) {
|
|
1016
|
-
reachable.add(dest);
|
|
1017
|
-
queue.push(dest);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
return reachable;
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Build a compiled scoped StateGraph containing `agentIds` as nodes, rooted
|
|
1026
|
-
* at `rootAgentId`. Linear sequence edges where both endpoints are in scope
|
|
1027
|
-
* are wired directly; nodes with no outgoing in-scope edges route to END.
|
|
1028
|
-
*
|
|
1029
|
-
* Each node is wrapped around the per-agent `createAgentNode` compiled
|
|
1030
|
-
* workflow (agent + tools loop) to preserve isolated tool context.
|
|
1031
|
-
*/
|
|
1032
|
-
buildScopedSubgraph(rootAgentId, agentIds) {
|
|
1033
|
-
const StateAnnotation = langgraph.Annotation.Root({
|
|
1034
|
-
messages: langgraph.Annotation({
|
|
1035
|
-
reducer: langgraph.messagesStateReducer,
|
|
1036
|
-
default: () => [],
|
|
1037
|
-
}),
|
|
1038
|
-
});
|
|
1039
|
-
const builder = new langgraph.StateGraph(StateAnnotation);
|
|
1040
|
-
// Precompile each scoped agent's inner workflow and wrap as a node.
|
|
1041
|
-
//
|
|
1042
|
-
// Two different isolation strategies depending on position:
|
|
1043
|
-
//
|
|
1044
|
-
// • ROOT node (the handoff target itself): receives the parent
|
|
1045
|
-
// orchestrator's handoff frame. Use `prepareHandoffMessages` — drops
|
|
1046
|
-
// orphaned tool_use, compacts paired tool calls, guarantees trailing
|
|
1047
|
-
// HumanMessage for Bedrock/VertexAI compatibility. The root needs
|
|
1048
|
-
// orchestrator context because it's responding to the handoff.
|
|
1049
|
-
//
|
|
1050
|
-
// • DOWNSTREAM nodes (sequence targets of the root): run as FULLY
|
|
1051
|
-
// ISOLATED child sessions. They receive only:
|
|
1052
|
-
// [original user request, synthetic HumanMessage describing what
|
|
1053
|
-
// the upstream agent produced and asking them to act]
|
|
1054
|
-
// No raw tool_use / tool_result blocks from the upstream agent —
|
|
1055
|
-
// prevents schema confusion when a downstream agent sees noisy
|
|
1056
|
-
// upstream context and produces malformed tool_use JSON.
|
|
1057
|
-
//
|
|
1058
|
-
// Each wrapper returns only the DELTA (new messages produced by the
|
|
1059
|
-
// inner invoke), not the prepared input — otherwise messagesStateReducer
|
|
1060
|
-
// would double-append the synthetic instruction into the scoped state.
|
|
1061
|
-
for (const aid of agentIds) {
|
|
1062
|
-
const inner = this.createAgentNode(aid);
|
|
1063
|
-
const isRoot = aid === rootAgentId;
|
|
1064
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1065
|
-
builder.addNode(aid, async (state, config) => {
|
|
1066
|
-
const prepared = isRoot
|
|
1067
|
-
? MultiAgentGraph.prepareHandoffMessages(state.messages)
|
|
1068
|
-
: MultiAgentGraph.prepareIsolatedChildMessages(state.messages);
|
|
1069
|
-
logging.mlog(`[MultiAgentGraph] scoped node "${aid}" entering (isRoot=${isRoot}, stateMessages=${state.messages.length}, prepared=${prepared.length})`);
|
|
1070
|
-
const result = await inner.invoke({ ...state, messages: prepared }, config);
|
|
1071
|
-
// Return only the messages the inner node appended beyond its input,
|
|
1072
|
-
// so messagesStateReducer doesn't duplicate the synthetic wrapper
|
|
1073
|
-
// prompt into the scoped state.
|
|
1074
|
-
const delta = result.messages.length > prepared.length
|
|
1075
|
-
? result.messages.slice(prepared.length)
|
|
1076
|
-
: result.messages;
|
|
1077
|
-
return { messages: delta };
|
|
1078
|
-
});
|
|
1079
|
-
}
|
|
1080
|
-
// START → root
|
|
1081
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1082
|
-
// @ts-ignore — LangGraph string typing is too strict for dynamic agent ids
|
|
1083
|
-
builder.addEdge(langgraph.START, rootAgentId);
|
|
1084
|
-
// Wire sequence edges in scope (linear chain support)
|
|
1085
|
-
const hasOutgoing = new Set();
|
|
1086
|
-
for (const edge of this.sequenceEdges) {
|
|
1087
|
-
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1088
|
-
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1089
|
-
for (const source of sources) {
|
|
1090
|
-
if (!agentIds.has(source))
|
|
1091
|
-
continue;
|
|
1092
|
-
for (const dest of dests) {
|
|
1093
|
-
if (!agentIds.has(dest))
|
|
1094
|
-
continue;
|
|
1095
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1096
|
-
// @ts-ignore
|
|
1097
|
-
builder.addEdge(source, dest);
|
|
1098
|
-
hasOutgoing.add(source);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
// Leaves (no outgoing in-scope edges) route to END
|
|
1103
|
-
for (const aid of agentIds) {
|
|
1104
|
-
if (!hasOutgoing.has(aid)) {
|
|
1105
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1106
|
-
// @ts-ignore
|
|
1107
|
-
builder.addEdge(aid, langgraph.END);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
return builder.compile(this.compileOptions);
|
|
458
|
+
/** This is essentially the same as `createAgentNode` from `StandardGraph` */
|
|
459
|
+
return this.createAgentNode(agentId);
|
|
1111
460
|
}
|
|
1112
461
|
/**
|
|
1113
462
|
* Detects if the current agent is receiving a handoff and processes the messages accordingly.
|
|
@@ -1121,23 +470,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1121
470
|
* @param agentId - The agent ID to check for handoff reception
|
|
1122
471
|
* @returns Object with filtered messages, extracted instructions, source agent, and parallel siblings
|
|
1123
472
|
*/
|
|
1124
|
-
|
|
1125
|
-
* Prepare messages for a handoff child agent. See
|
|
1126
|
-
* {@link prepareHandoffMessagesUtil} for the full implementation and
|
|
1127
|
-
* semantics — this static method is a thin delegate preserved for
|
|
1128
|
-
* backward compatibility with existing call sites and unit tests.
|
|
1129
|
-
*/
|
|
1130
|
-
static prepareHandoffMessages(messages) {
|
|
1131
|
-
return childAgentContext.prepareHandoffMessages(messages);
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Build an isolated message context for a downstream scoped-subgraph
|
|
1135
|
-
* node. See {@link prepareIsolatedChildMessagesUtil} for details.
|
|
1136
|
-
*/
|
|
1137
|
-
static prepareIsolatedChildMessages(messages) {
|
|
1138
|
-
return childAgentContext.prepareIsolatedChildMessages(messages);
|
|
1139
|
-
}
|
|
1140
|
-
processTransferReception(messages$1, agentId) {
|
|
473
|
+
processHandoffReception(messages$1, agentId) {
|
|
1141
474
|
if (messages$1.length === 0)
|
|
1142
475
|
return null;
|
|
1143
476
|
/**
|
|
@@ -1166,9 +499,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1166
499
|
destinationAgent = toolName.replace(_enum.Constants.LC_TRANSFER_TO_, '');
|
|
1167
500
|
}
|
|
1168
501
|
else if (isConditionalTransfer) {
|
|
1169
|
-
const
|
|
1170
|
-
destinationAgent =
|
|
1171
|
-
typeof transferDest === 'string' ? transferDest : null;
|
|
502
|
+
const handoffDest = candidateMsg.additional_kwargs.handoff_destination;
|
|
503
|
+
destinationAgent = typeof handoffDest === 'string' ? handoffDest : null;
|
|
1172
504
|
}
|
|
1173
505
|
/** Check if this transfer targets our agent */
|
|
1174
506
|
if (destinationAgent === agentId) {
|
|
@@ -1184,7 +516,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1184
516
|
const contentStr = typeof toolMessage.content === 'string'
|
|
1185
517
|
? toolMessage.content
|
|
1186
518
|
: JSON.stringify(toolMessage.content);
|
|
1187
|
-
const instructionsMatch = contentStr.match(
|
|
519
|
+
const instructionsMatch = contentStr.match(HANDOFF_INSTRUCTIONS_PATTERN);
|
|
1188
520
|
const instructions = instructionsMatch?.[1]?.trim() ?? null;
|
|
1189
521
|
/** Extract source agent name from additional_kwargs */
|
|
1190
522
|
const handoffSourceName = toolMessage.additional_kwargs.handoff_source_name;
|
|
@@ -1242,13 +574,9 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1242
574
|
if (hasTransferCalls) {
|
|
1243
575
|
if (remainingToolCalls.length > 0 ||
|
|
1244
576
|
(typeof aiMsg.content === 'string' && aiMsg.content.trim())) {
|
|
1245
|
-
/** Keep the message but without transfer tool calls
|
|
1246
|
-
* Trim trailing whitespace to prevent Bedrock validation errors. */
|
|
1247
|
-
const trimmedContent = typeof aiMsg.content === 'string'
|
|
1248
|
-
? aiMsg.content.trimEnd()
|
|
1249
|
-
: aiMsg.content;
|
|
577
|
+
/** Keep the message but without transfer tool calls */
|
|
1250
578
|
const filteredAiMsg = new messages.AIMessage({
|
|
1251
|
-
content:
|
|
579
|
+
content: aiMsg.content,
|
|
1252
580
|
tool_calls: remainingToolCalls,
|
|
1253
581
|
id: aiMsg.id,
|
|
1254
582
|
});
|
|
@@ -1262,107 +590,15 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1262
590
|
/** Keep all other messages */
|
|
1263
591
|
filteredMessages.push(msg);
|
|
1264
592
|
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Flatten tool call/result pairs into text summaries for handoff.
|
|
1267
|
-
*
|
|
1268
|
-
* When agent A uses tools and then hands off to agent B, agent B may not
|
|
1269
|
-
* have the same tools configured. Providers like Bedrock require toolConfig
|
|
1270
|
-
* when tool_use/tool_result blocks are in the message history. Converting
|
|
1271
|
-
* tool interactions to text summaries avoids this and reduces context bloat.
|
|
1272
|
-
*
|
|
1273
|
-
* Strategy: Walk through messages and merge each (AIMessage-with-tool_calls +
|
|
1274
|
-
* following ToolMessages) group into a single AIMessage containing the original
|
|
1275
|
-
* text plus a textual summary of the tool interaction. This preserves proper
|
|
1276
|
-
* message role ordering (human/assistant alternation).
|
|
1277
|
-
*/
|
|
1278
|
-
const compactedMessages = [];
|
|
1279
|
-
for (let i = 0; i < filteredMessages.length; i++) {
|
|
1280
|
-
const msg = filteredMessages[i];
|
|
1281
|
-
const msgType = msg.getType();
|
|
1282
|
-
if (msgType === 'ai') {
|
|
1283
|
-
const aiMsg = msg;
|
|
1284
|
-
const toolCalls = aiMsg.tool_calls;
|
|
1285
|
-
if (toolCalls && toolCalls.length > 0) {
|
|
1286
|
-
/** Extract text content from the AIMessage */
|
|
1287
|
-
const textContent = typeof aiMsg.content === 'string'
|
|
1288
|
-
? aiMsg.content
|
|
1289
|
-
: Array.isArray(aiMsg.content)
|
|
1290
|
-
? aiMsg.content
|
|
1291
|
-
.filter((b) => typeof b === 'object' &&
|
|
1292
|
-
b.type === 'text' &&
|
|
1293
|
-
'text' in b)
|
|
1294
|
-
.map((b) => b.text)
|
|
1295
|
-
.join('\n')
|
|
1296
|
-
: '';
|
|
1297
|
-
/** Collect tool_call_ids so we can match following ToolMessages */
|
|
1298
|
-
const callIds = new Set(toolCalls.map((tc) => tc.id).filter(Boolean));
|
|
1299
|
-
/** Build summary of what tools were called */
|
|
1300
|
-
const callSummaries = toolCalls.map((tc) => `[Called "${tc.name}"]`);
|
|
1301
|
-
/** Consume following ToolMessages that belong to this AI message */
|
|
1302
|
-
const resultSummaries = [];
|
|
1303
|
-
while (i + 1 < filteredMessages.length) {
|
|
1304
|
-
const next = filteredMessages[i + 1];
|
|
1305
|
-
if (next.getType() !== 'tool')
|
|
1306
|
-
break;
|
|
1307
|
-
const toolMsg = next;
|
|
1308
|
-
if (!callIds.has(toolMsg.tool_call_id))
|
|
1309
|
-
break;
|
|
1310
|
-
/** Extract and summarize the tool result */
|
|
1311
|
-
const rawContent = typeof toolMsg.content === 'string'
|
|
1312
|
-
? toolMsg.content
|
|
1313
|
-
: Array.isArray(toolMsg.content)
|
|
1314
|
-
? toolMsg.content
|
|
1315
|
-
.filter((b) => typeof b === 'object' &&
|
|
1316
|
-
'text' in b &&
|
|
1317
|
-
typeof b.text ===
|
|
1318
|
-
'string')
|
|
1319
|
-
.map((b) => b.text)
|
|
1320
|
-
.join('\n')
|
|
1321
|
-
: JSON.stringify(toolMsg.content);
|
|
1322
|
-
const summary = rawContent.length > 500
|
|
1323
|
-
? rawContent.split('\n')[0] + ' [truncated for handoff]'
|
|
1324
|
-
: rawContent;
|
|
1325
|
-
resultSummaries.push(`[Tool "${toolMsg.name}" returned: ${summary}]`);
|
|
1326
|
-
i++; // Skip this ToolMessage in the outer loop
|
|
1327
|
-
}
|
|
1328
|
-
/** Merge everything into a single AIMessage */
|
|
1329
|
-
const parts = [
|
|
1330
|
-
textContent,
|
|
1331
|
-
...callSummaries,
|
|
1332
|
-
...resultSummaries,
|
|
1333
|
-
].filter(Boolean);
|
|
1334
|
-
/** Bedrock rejects messages with trailing whitespace */
|
|
1335
|
-
const mergedContent = (parts.join('\n') || '[Agent processed tools]').trimEnd();
|
|
1336
|
-
compactedMessages.push(new messages.AIMessage({
|
|
1337
|
-
content: mergedContent,
|
|
1338
|
-
id: aiMsg.id,
|
|
1339
|
-
}));
|
|
1340
|
-
continue;
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
/** Skip orphaned ToolMessages (their AI parent was already handled above,
|
|
1344
|
-
* or they belong to a transfer that was already filtered out) */
|
|
1345
|
-
if (msgType === 'tool') {
|
|
1346
|
-
continue;
|
|
1347
|
-
}
|
|
1348
|
-
/** Trim trailing whitespace on AI messages to prevent Bedrock validation errors */
|
|
1349
|
-
if (msgType === 'ai' &&
|
|
1350
|
-
typeof msg.content === 'string' &&
|
|
1351
|
-
msg.content !== msg.content.trimEnd()) {
|
|
1352
|
-
compactedMessages.push(new messages.AIMessage({ content: msg.content.trimEnd(), id: msg.id }));
|
|
1353
|
-
continue;
|
|
1354
|
-
}
|
|
1355
|
-
compactedMessages.push(msg);
|
|
1356
|
-
}
|
|
1357
593
|
return {
|
|
1358
|
-
filteredMessages
|
|
594
|
+
filteredMessages,
|
|
1359
595
|
instructions,
|
|
1360
596
|
sourceAgentName,
|
|
1361
597
|
parallelSiblings,
|
|
1362
598
|
};
|
|
1363
599
|
}
|
|
1364
600
|
/**
|
|
1365
|
-
* Create the multi-agent workflow with handoffs
|
|
601
|
+
* Create the multi-agent workflow with dynamic handoffs
|
|
1366
602
|
*/
|
|
1367
603
|
createWorkflow() {
|
|
1368
604
|
const StateAnnotation = langgraph.Annotation.Root({
|
|
@@ -1385,119 +621,53 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1385
621
|
}),
|
|
1386
622
|
});
|
|
1387
623
|
const builder = new langgraph.StateGraph(StateAnnotation);
|
|
1388
|
-
|
|
1389
|
-
* Identify agents that are ONLY handoff destinations (not transfer/sequence
|
|
1390
|
-
* destinations and not starting nodes). These agents are invoked inline via
|
|
1391
|
-
* subgraph.invoke() inside handoff tools — they must NOT be added as
|
|
1392
|
-
* top-level nodes in the parent graph because LangGraph validates that all
|
|
1393
|
-
* nodes are reachable from START via edges.
|
|
1394
|
-
*/
|
|
1395
|
-
const handoffOnlyDestinations = new Set();
|
|
1396
|
-
const transferOrSequenceDestinations = new Set();
|
|
1397
|
-
for (const edge of this.handoffEdges) {
|
|
1398
|
-
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1399
|
-
dests.forEach((d) => handoffOnlyDestinations.add(d));
|
|
1400
|
-
}
|
|
1401
|
-
for (const edge of [...this.transferEdges, ...this.sequenceEdges]) {
|
|
1402
|
-
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1403
|
-
dests.forEach((d) => transferOrSequenceDestinations.add(d));
|
|
1404
|
-
}
|
|
1405
|
-
// Remove agents that are also transfer/sequence destinations or starting nodes
|
|
1406
|
-
for (const d of transferOrSequenceDestinations) {
|
|
1407
|
-
handoffOnlyDestinations.delete(d);
|
|
1408
|
-
}
|
|
1409
|
-
for (const startNode of this.startingNodes) {
|
|
1410
|
-
handoffOnlyDestinations.delete(startNode);
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Nested-sequence expansion: for each handoff-only target, its downstream
|
|
1414
|
-
* sequence/transfer agents MUST also become handoff-only — they exist only
|
|
1415
|
-
* inside the target's scoped subgraph, not at top level. Without this,
|
|
1416
|
-
* those downstream nodes would be added as top-level orphans and LangGraph
|
|
1417
|
-
* would fail compilation (UNREACHABLE_NODE).
|
|
1418
|
-
*
|
|
1419
|
-
* See docs/multi-agent-nesting-architecture.md §6.
|
|
1420
|
-
*/
|
|
1421
|
-
const nestedHandoffOnly = new Set();
|
|
1422
|
-
for (const target of handoffOnlyDestinations) {
|
|
1423
|
-
const reachable = this.computeReachableViaNonHandoff(target);
|
|
1424
|
-
for (const agent of reachable) {
|
|
1425
|
-
if (agent === target)
|
|
1426
|
-
continue;
|
|
1427
|
-
// Skip if this agent is legitimately a top-level starting node
|
|
1428
|
-
if (this.startingNodes.has(agent))
|
|
1429
|
-
continue;
|
|
1430
|
-
nestedHandoffOnly.add(agent);
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
for (const agent of nestedHandoffOnly) {
|
|
1434
|
-
handoffOnlyDestinations.add(agent);
|
|
1435
|
-
}
|
|
1436
|
-
if (nestedHandoffOnly.size > 0) {
|
|
1437
|
-
logging.mlog(`[MultiAgentGraph] Nested handoff-only (scoped subgraph downstream): [${Array.from(nestedHandoffOnly).join(', ')}]`);
|
|
1438
|
-
}
|
|
1439
|
-
if (handoffOnlyDestinations.size > 0) {
|
|
1440
|
-
logging.mlog(`[MultiAgentGraph] Handoff-only children (subgraph only, no top-level node): [${Array.from(handoffOnlyDestinations).join(', ')}]`);
|
|
1441
|
-
}
|
|
1442
|
-
// Add agents as nodes — skip handoff-only children (they exist as subgraphs only)
|
|
624
|
+
// Add all agents as complete subgraphs
|
|
1443
625
|
for (const [agentId] of this.agentContexts) {
|
|
1444
626
|
// Get all possible destinations for this agent
|
|
1445
|
-
const
|
|
1446
|
-
const
|
|
1447
|
-
// Check
|
|
1448
|
-
for (const edge of this.
|
|
627
|
+
const handoffDestinations = new Set();
|
|
628
|
+
const directDestinations = new Set();
|
|
629
|
+
// Check handoff edges for destinations
|
|
630
|
+
for (const edge of this.handoffEdges) {
|
|
1449
631
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1450
632
|
if (sources.includes(agentId) === true) {
|
|
1451
633
|
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1452
|
-
dests.forEach((dest) =>
|
|
634
|
+
dests.forEach((dest) => handoffDestinations.add(dest));
|
|
1453
635
|
}
|
|
1454
636
|
}
|
|
1455
|
-
// Check
|
|
1456
|
-
for (const edge of this.
|
|
637
|
+
// Check direct edges for destinations
|
|
638
|
+
for (const edge of this.directEdges) {
|
|
1457
639
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1458
640
|
if (sources.includes(agentId) === true) {
|
|
1459
641
|
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1460
|
-
dests.forEach((dest) =>
|
|
642
|
+
dests.forEach((dest) => directDestinations.add(dest));
|
|
1461
643
|
}
|
|
1462
644
|
}
|
|
1463
|
-
/** Check if this agent has BOTH
|
|
1464
|
-
const
|
|
1465
|
-
const
|
|
1466
|
-
const needsCommandRouting =
|
|
645
|
+
/** Check if this agent has BOTH handoff and direct edges */
|
|
646
|
+
const hasHandoffEdges = handoffDestinations.size > 0;
|
|
647
|
+
const hasDirectEdges = directDestinations.size > 0;
|
|
648
|
+
const needsCommandRouting = hasHandoffEdges && hasDirectEdges;
|
|
1467
649
|
/** Collect all possible destinations for this agent */
|
|
1468
650
|
const allDestinations = new Set([
|
|
1469
|
-
...
|
|
1470
|
-
...
|
|
651
|
+
...handoffDestinations,
|
|
652
|
+
...directDestinations,
|
|
1471
653
|
]);
|
|
1472
|
-
if (
|
|
654
|
+
if (handoffDestinations.size > 0 || directDestinations.size === 0) {
|
|
1473
655
|
allDestinations.add(langgraph.END);
|
|
1474
656
|
}
|
|
1475
657
|
/** Agent subgraph (includes agent + tools) */
|
|
1476
658
|
const agentSubgraph = this.createAgentSubgraph(agentId);
|
|
1477
|
-
/** Register subgraph for handoff tools (lazy reference resolution) */
|
|
1478
|
-
this.subgraphRegistry.set(agentId, agentSubgraph);
|
|
1479
|
-
/**
|
|
1480
|
-
* Handoff-only children are invoked inline via subgraph.invoke() — they
|
|
1481
|
-
* don't need a top-level node. Adding them would cause LangGraph to reject
|
|
1482
|
-
* the graph because no edge routes to them (UNREACHABLE_NODE).
|
|
1483
|
-
*/
|
|
1484
|
-
if (handoffOnlyDestinations.has(agentId)) {
|
|
1485
|
-
continue;
|
|
1486
|
-
}
|
|
1487
659
|
/** Wrapper function that handles agentMessages channel, handoff reception, and conditional routing */
|
|
1488
660
|
const agentWrapper = async (state, config) => {
|
|
1489
|
-
logging.mlog(`[MultiAgentGraph] Agent "${agentId}" wrapper ENTRY (messages: ${state.messages.length}, needsCommandRouting: ${needsCommandRouting})`);
|
|
1490
661
|
let result;
|
|
1491
662
|
/**
|
|
1492
|
-
* Check if this agent is receiving a
|
|
663
|
+
* Check if this agent is receiving a handoff.
|
|
1493
664
|
* If so, filter out the transfer messages and inject instructions as preamble.
|
|
1494
665
|
* This prevents the receiving agent from seeing the transfer as "completed work"
|
|
1495
666
|
* and prematurely producing an end token.
|
|
1496
667
|
*/
|
|
1497
|
-
const
|
|
1498
|
-
if (
|
|
1499
|
-
const { filteredMessages, instructions, sourceAgentName, parallelSiblings, } =
|
|
1500
|
-
logging.mlog(`[MultiAgentGraph] Agent "${agentId}" receiving transfer from "${sourceAgentName}" (instructions: ${instructions != null}, parallelSiblings: ${parallelSiblings.length})`);
|
|
668
|
+
const handoffContext = this.processHandoffReception(state.messages, agentId);
|
|
669
|
+
if (handoffContext !== null) {
|
|
670
|
+
const { filteredMessages, instructions, sourceAgentName, parallelSiblings, } = handoffContext;
|
|
1501
671
|
/**
|
|
1502
672
|
* Set handoff context on the receiving agent.
|
|
1503
673
|
* Uses pre-computed graph position for depth and parallel info.
|
|
@@ -1611,124 +781,24 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1611
781
|
else {
|
|
1612
782
|
result = await agentSubgraph.invoke(state, config);
|
|
1613
783
|
}
|
|
1614
|
-
/**
|
|
1615
|
-
this.lastActiveAgentId = agentId;
|
|
1616
|
-
logging.mlog(`[MultiAgentGraph] Agent "${agentId}" wrapper EXIT (result messages: ${result.messages.length})`);
|
|
1617
|
-
/** If agent has both transfer and sequence edges, use Command for exclusive routing */
|
|
784
|
+
/** If agent has both handoff and direct edges, use Command for exclusive routing */
|
|
1618
785
|
if (needsCommandRouting) {
|
|
1619
|
-
/** Check if a
|
|
786
|
+
/** Check if a handoff occurred */
|
|
1620
787
|
const lastMessage = result.messages[result.messages.length - 1];
|
|
1621
788
|
if (lastMessage != null &&
|
|
1622
789
|
lastMessage.getType() === 'tool' &&
|
|
1623
790
|
typeof lastMessage.name === 'string' &&
|
|
1624
791
|
lastMessage.name.startsWith(_enum.Constants.LC_TRANSFER_TO_)) {
|
|
1625
|
-
/**
|
|
1626
|
-
const
|
|
1627
|
-
logging.mlog(`[MultiAgentGraph] Command routing: "${agentId}" -> transfer to "${transferDest}" (sequence edges skipped: [${Array.from(sequenceDestinations).join(', ')}])`);
|
|
1628
|
-
/** Validate destination agent exists */
|
|
1629
|
-
if (!this.agentContexts.has(transferDest)) {
|
|
1630
|
-
const availableAgents = Array.from(this.agentContexts.keys()).join(', ');
|
|
1631
|
-
console.error(`[MultiAgentGraph] Transfer to non-existent agent "${transferDest}". Available: ${availableAgents}`);
|
|
1632
|
-
/** Return error to model so it can self-correct */
|
|
1633
|
-
const errorMsg = new messages.ToolMessage({
|
|
1634
|
-
content: `Transfer failed: agent "${transferDest}" does not exist. Available agents: ${availableAgents}. Please choose a valid agent to transfer to.`,
|
|
1635
|
-
tool_call_id: lastMessage.tool_call_id,
|
|
1636
|
-
name: lastMessage.name,
|
|
1637
|
-
});
|
|
1638
|
-
errorMsg.status = 'error';
|
|
1639
|
-
return {
|
|
1640
|
-
messages: [...result.messages, errorMsg],
|
|
1641
|
-
};
|
|
1642
|
-
}
|
|
1643
|
-
/** Pre-handoff context compaction: if receiving agent has smaller budget */
|
|
1644
|
-
const receiverContext = this.agentContexts.get(transferDest);
|
|
1645
|
-
const senderContext = this.agentContexts.get(agentId);
|
|
1646
|
-
if (receiverContext?.maxContextTokens != null &&
|
|
1647
|
-
senderContext?.tokenCounter != null &&
|
|
1648
|
-
receiverContext.maxContextTokens > 0) {
|
|
1649
|
-
let currentSize = 0;
|
|
1650
|
-
for (const msg of result.messages) {
|
|
1651
|
-
currentSize += senderContext.tokenCounter(msg);
|
|
1652
|
-
}
|
|
1653
|
-
const receiverBudget = receiverContext.maxContextTokens;
|
|
1654
|
-
if (currentSize > receiverBudget * 0.7) {
|
|
1655
|
-
logging.mwarn(`[MultiAgentGraph] Pre-handoff compaction: context (${currentSize} tokens) exceeds ` +
|
|
1656
|
-
`70% of receiver "${transferDest}" budget (${receiverBudget} tokens)`);
|
|
1657
|
-
/** Generate handoff briefing */
|
|
1658
|
-
const senderName = senderContext.name ?? agentId;
|
|
1659
|
-
if (senderContext.summarizeCallback) {
|
|
1660
|
-
try {
|
|
1661
|
-
const briefingResult = await summarize.summarize(result.messages, async (prompt, _maxTokens) => senderContext.summarizeCallback([
|
|
1662
|
-
new messages.HumanMessage(prompt),
|
|
1663
|
-
]), {
|
|
1664
|
-
tokenCounter: senderContext.tokenCounter,
|
|
1665
|
-
summaryBudget: Math.floor(receiverBudget * 0.2),
|
|
1666
|
-
isMultiAgent: true,
|
|
1667
|
-
agentWorkflowState: {
|
|
1668
|
-
currentAgentId: transferDest,
|
|
1669
|
-
agentChain: [agentId, transferDest],
|
|
1670
|
-
pendingAgents: [],
|
|
1671
|
-
},
|
|
1672
|
-
});
|
|
1673
|
-
const briefingMsg = new messages.SystemMessage(`[Handoff Briefing from "${senderName}"]\n${briefingResult.summary}`);
|
|
1674
|
-
/** Replace messages with briefing + last 3 messages */
|
|
1675
|
-
const keepCount = Math.min(3, result.messages.length);
|
|
1676
|
-
result = {
|
|
1677
|
-
...result,
|
|
1678
|
-
messages: [
|
|
1679
|
-
briefingMsg,
|
|
1680
|
-
...result.messages.slice(result.messages.length - keepCount),
|
|
1681
|
-
],
|
|
1682
|
-
};
|
|
1683
|
-
console.info(`[MultiAgentGraph] Pre-handoff compaction complete: ${currentSize} tokens → briefing + ${keepCount} messages`);
|
|
1684
|
-
}
|
|
1685
|
-
catch (compactErr) {
|
|
1686
|
-
console.error('[MultiAgentGraph] Pre-handoff compaction failed:', compactErr);
|
|
1687
|
-
/** Continue without compaction — let receiver handle the overflow */
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
else {
|
|
1691
|
-
/** No summary callback — use emergency summary */
|
|
1692
|
-
const emergencySummary = summarize.createEmergencySummary(result.messages);
|
|
1693
|
-
const briefingMsg = new messages.SystemMessage(`[Handoff Briefing from "${senderName}" — Emergency]\n${emergencySummary}`);
|
|
1694
|
-
const keepCount = Math.min(3, result.messages.length);
|
|
1695
|
-
result = {
|
|
1696
|
-
...result,
|
|
1697
|
-
messages: [
|
|
1698
|
-
briefingMsg,
|
|
1699
|
-
...result.messages.slice(result.messages.length - keepCount),
|
|
1700
|
-
],
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
1706
|
-
sourceAgentId: agentId,
|
|
1707
|
-
sourceAgentName: this.agentContexts.get(agentId)?.name ?? agentId,
|
|
1708
|
-
destinationAgentId: transferDest,
|
|
1709
|
-
destinationAgentName: this.agentContexts.get(transferDest)?.name ?? transferDest,
|
|
1710
|
-
edgeType: _enum.EdgeType.TRANSFER,
|
|
1711
|
-
timestamp: Date.now(),
|
|
1712
|
-
}, config);
|
|
792
|
+
/** Handoff occurred - extract destination and navigate there exclusively */
|
|
793
|
+
const handoffDest = lastMessage.name.replace(_enum.Constants.LC_TRANSFER_TO_, '');
|
|
1713
794
|
return new langgraph.Command({
|
|
1714
795
|
update: result,
|
|
1715
|
-
goto:
|
|
796
|
+
goto: handoffDest,
|
|
1716
797
|
});
|
|
1717
798
|
}
|
|
1718
799
|
else {
|
|
1719
|
-
/** No
|
|
1720
|
-
|
|
1721
|
-
const directDests = Array.from(sequenceDestinations);
|
|
1722
|
-
for (const dest of directDests) {
|
|
1723
|
-
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
1724
|
-
sourceAgentId: agentId,
|
|
1725
|
-
sourceAgentName: this.agentContexts.get(agentId)?.name ?? agentId,
|
|
1726
|
-
destinationAgentId: dest,
|
|
1727
|
-
destinationAgentName: this.agentContexts.get(dest)?.name ?? dest,
|
|
1728
|
-
edgeType: _enum.EdgeType.SEQUENCE,
|
|
1729
|
-
timestamp: Date.now(),
|
|
1730
|
-
}, config);
|
|
1731
|
-
}
|
|
800
|
+
/** No handoff - proceed with direct edges */
|
|
801
|
+
const directDests = Array.from(directDestinations);
|
|
1732
802
|
if (directDests.length === 1) {
|
|
1733
803
|
return new langgraph.Command({
|
|
1734
804
|
update: result,
|
|
@@ -1744,30 +814,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1744
814
|
}
|
|
1745
815
|
}
|
|
1746
816
|
}
|
|
1747
|
-
/**
|
|
1748
|
-
* No Command routing needed — dispatch ON_AGENT_TRANSITION for all
|
|
1749
|
-
* destinations so callbacks.js can register child agents for event
|
|
1750
|
-
* isolation BEFORE they start streaming.
|
|
1751
|
-
*/
|
|
1752
|
-
const allDests = new Set([
|
|
1753
|
-
...transferDestinations,
|
|
1754
|
-
...sequenceDestinations,
|
|
1755
|
-
]);
|
|
1756
|
-
if (allDests.size > 0) {
|
|
1757
|
-
const edgeType = hasTransferEdges
|
|
1758
|
-
? _enum.EdgeType.TRANSFER
|
|
1759
|
-
: _enum.EdgeType.SEQUENCE;
|
|
1760
|
-
for (const dest of allDests) {
|
|
1761
|
-
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
|
|
1762
|
-
sourceAgentId: agentId,
|
|
1763
|
-
sourceAgentName: this.agentContexts.get(agentId)?.name ?? agentId,
|
|
1764
|
-
destinationAgentId: dest,
|
|
1765
|
-
destinationAgentName: this.agentContexts.get(dest)?.name ?? dest,
|
|
1766
|
-
edgeType,
|
|
1767
|
-
timestamp: Date.now(),
|
|
1768
|
-
}, config);
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
817
|
+
/** No special routing needed - return state normally */
|
|
1771
818
|
return result;
|
|
1772
819
|
};
|
|
1773
820
|
/** Wrapped agent as a node with its possible destinations */
|
|
@@ -1775,85 +822,36 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1775
822
|
ends: Array.from(allDestinations),
|
|
1776
823
|
});
|
|
1777
824
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
* follow-up messages continue where the previous turn left off.
|
|
1784
|
-
*
|
|
1785
|
-
* Default behavior (no resume): static edges to all starting nodes,
|
|
1786
|
-
* preserving parallel execution for graphs with multiple entry points.
|
|
1787
|
-
*/
|
|
1788
|
-
const validResumeAgent = this.resumeFromAgentId != null &&
|
|
1789
|
-
this.agentContexts.has(this.resumeFromAgentId);
|
|
1790
|
-
if (validResumeAgent) {
|
|
1791
|
-
const resumeAgentId = this.resumeFromAgentId;
|
|
1792
|
-
logging.mlog(`[MultiAgentGraph] Multi-turn resumption: routing START → "${resumeAgentId}" (skipping default starting nodes: [${Array.from(this.startingNodes).join(', ')}])`);
|
|
1793
|
-
/**
|
|
1794
|
-
* Build route map containing both the resume agent and default starting
|
|
1795
|
-
* nodes. This is required by LangGraph — all possible destinations must
|
|
1796
|
-
* be declared even if the router always picks one.
|
|
1797
|
-
*/
|
|
1798
|
-
const allPossibleStarts = new Set([...this.startingNodes, resumeAgentId]);
|
|
1799
|
-
const routeMap = {};
|
|
1800
|
-
for (const nodeId of allPossibleStarts) {
|
|
1801
|
-
routeMap[nodeId] = nodeId;
|
|
1802
|
-
}
|
|
1803
|
-
builder.addConditionalEdges(langgraph.START, () => resumeAgentId, routeMap);
|
|
1804
|
-
}
|
|
1805
|
-
else {
|
|
1806
|
-
if (this.resumeFromAgentId != null) {
|
|
1807
|
-
logging.mwarn(`[MultiAgentGraph] resumeFromAgentId "${this.resumeFromAgentId}" not found in graph — falling back to default starting nodes`);
|
|
1808
|
-
}
|
|
1809
|
-
for (const startNode of this.startingNodes) {
|
|
1810
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1811
|
-
/** @ts-ignore */
|
|
1812
|
-
builder.addEdge(langgraph.START, startNode);
|
|
1813
|
-
}
|
|
825
|
+
// Add starting edges for all starting nodes
|
|
826
|
+
for (const startNode of this.startingNodes) {
|
|
827
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
828
|
+
/** @ts-ignore */
|
|
829
|
+
builder.addEdge(langgraph.START, startNode);
|
|
1814
830
|
}
|
|
1815
831
|
/**
|
|
1816
|
-
* Add approval
|
|
1817
|
-
*
|
|
1818
|
-
*
|
|
832
|
+
* Add approval-gate nodes for sequence edges that declare an approvalGate
|
|
833
|
+
* config (Ranger-only feature, not present upstream). Gates fire
|
|
834
|
+
* regardless of ExecutionContext and sit between source and destination.
|
|
1819
835
|
*/
|
|
1820
836
|
const gatedEdges = new Set();
|
|
1821
|
-
for (const edge of this.
|
|
1822
|
-
if (!edge.approvalGate)
|
|
837
|
+
for (const edge of this.directEdges) {
|
|
838
|
+
if (!edge.approvalGate)
|
|
1823
839
|
continue;
|
|
1824
|
-
}
|
|
1825
840
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1826
841
|
const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1827
842
|
for (const source of sources) {
|
|
1828
843
|
for (const dest of destinations) {
|
|
1829
844
|
const gateNodeId = ApprovalGateNode.getApprovalGateNodeId(edge.approvalGate.gateId);
|
|
1830
|
-
const onDeny = edge.approvalGate.onDeny ?? 'stop';
|
|
1831
|
-
// Add the gate node
|
|
1832
845
|
const gateNode = ApprovalGateNode.createApprovalGateNode(edge.approvalGate, source, dest);
|
|
1833
846
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1834
847
|
/** @ts-ignore */
|
|
1835
848
|
builder.addNode(gateNodeId, gateNode);
|
|
1836
|
-
// Wire: source → gate
|
|
1837
849
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1838
850
|
/** @ts-ignore */
|
|
1839
851
|
builder.addEdge(source, gateNodeId);
|
|
1840
|
-
//
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
// and the gate returns empty state)
|
|
1844
|
-
if (onDeny === 'skip') {
|
|
1845
|
-
// Conditional edge: approved → destination, denied → END
|
|
1846
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1847
|
-
/** @ts-ignore */
|
|
1848
|
-
builder.addEdge(gateNodeId, dest);
|
|
1849
|
-
}
|
|
1850
|
-
else {
|
|
1851
|
-
// Direct edge to destination — denial stops via non-resume or
|
|
1852
|
-
// the host terminates the graph
|
|
1853
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1854
|
-
/** @ts-ignore */
|
|
1855
|
-
builder.addEdge(gateNodeId, dest);
|
|
1856
|
-
}
|
|
852
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
853
|
+
/** @ts-ignore */
|
|
854
|
+
builder.addEdge(gateNodeId, dest);
|
|
1857
855
|
}
|
|
1858
856
|
}
|
|
1859
857
|
gatedEdges.add(edge);
|
|
@@ -1861,26 +859,14 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1861
859
|
/**
|
|
1862
860
|
* Add sequence edges for automatic transitions
|
|
1863
861
|
* Group edges by destination to handle fan-in scenarios
|
|
1864
|
-
* Skip edges that have approval
|
|
862
|
+
* (Skip edges that already have an approval gate above.)
|
|
1865
863
|
*/
|
|
1866
864
|
const edgesByDestination = new Map();
|
|
1867
|
-
for (const edge of this.
|
|
1868
|
-
if (gatedEdges.has(edge))
|
|
1869
|
-
continue;
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Skip sequence edges where either endpoint lives only inside a scoped
|
|
1873
|
-
* handoff subgraph. Those edges are wired inside `buildScopedSubgraph`,
|
|
1874
|
-
* not at the top level — adding them here would reference non-existent
|
|
1875
|
-
* top-level nodes and fail compilation.
|
|
1876
|
-
*/
|
|
1877
|
-
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1878
|
-
const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
1879
|
-
const anyEndpointHandoffOnly = [...sources, ...dests].some((n) => handoffOnlyDestinations.has(n));
|
|
1880
|
-
if (anyEndpointHandoffOnly) {
|
|
865
|
+
for (const edge of this.directEdges) {
|
|
866
|
+
if (gatedEdges.has(edge))
|
|
1881
867
|
continue;
|
|
1882
|
-
|
|
1883
|
-
for (const destination of
|
|
868
|
+
const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
|
|
869
|
+
for (const destination of destinations) {
|
|
1884
870
|
if (!edgesByDestination.has(destination)) {
|
|
1885
871
|
edgesByDestination.set(destination, []);
|
|
1886
872
|
}
|
|
@@ -1967,18 +953,17 @@ class MultiAgentGraph extends Graph.StandardGraph {
|
|
|
1967
953
|
for (const edge of edges) {
|
|
1968
954
|
const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
|
|
1969
955
|
for (const source of sources) {
|
|
1970
|
-
/** Check if this source node has both
|
|
1971
|
-
const
|
|
956
|
+
/** Check if this source node has both handoff and direct edges */
|
|
957
|
+
const sourceHandoffEdges = this.handoffEdges.filter((e) => {
|
|
1972
958
|
const eSources = Array.isArray(e.from) ? e.from : [e.from];
|
|
1973
959
|
return eSources.includes(source);
|
|
1974
960
|
});
|
|
1975
|
-
const
|
|
961
|
+
const sourceDirectEdges = this.directEdges.filter((e) => {
|
|
1976
962
|
const eSources = Array.isArray(e.from) ? e.from : [e.from];
|
|
1977
963
|
return eSources.includes(source);
|
|
1978
964
|
});
|
|
1979
965
|
/** Skip adding edge if source uses Command routing (has both types) */
|
|
1980
|
-
if (
|
|
1981
|
-
sourceSequenceEdges.length > 0) {
|
|
966
|
+
if (sourceHandoffEdges.length > 0 && sourceDirectEdges.length > 0) {
|
|
1982
967
|
continue;
|
|
1983
968
|
}
|
|
1984
969
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|