@illuma-ai/agents 1.1.14 → 1.1.15

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.
@@ -86,6 +86,8 @@ exports.EdgeType = void 0;
86
86
  EdgeType["HANDOFF"] = "handoff";
87
87
  /** Creates direct edges for automatic sequential/parallel transitions */
88
88
  EdgeType["DIRECT"] = "direct";
89
+ /** Creates delegate tools that invoke child subgraph inline and return result to parent */
90
+ EdgeType["DELEGATE"] = "delegate";
89
91
  })(exports.EdgeType || (exports.EdgeType = {}));
90
92
  exports.GraphNodeKeys = void 0;
91
93
  (function (GraphNodeKeys) {
@@ -168,6 +170,8 @@ exports.Constants = void 0;
168
170
  Constants["WEB_SEARCH"] = "web_search";
169
171
  Constants["CONTENT_AND_ARTIFACT"] = "content_and_artifact";
170
172
  Constants["LC_TRANSFER_TO_"] = "lc_transfer_to_";
173
+ /** Prefix for delegate tool names: lc_delegate_to_{agentId} */
174
+ Constants["LC_DELEGATE_TO_"] = "lc_delegate_to_";
171
175
  /** Tool name for the AskUser structured question tool */
172
176
  Constants["ASK_USER"] = "ask_user";
173
177
  /** Delimiter for MCP tools: toolName_mcp_serverName */
@@ -219,4 +223,11 @@ exports.MessageTypes = void 0;
219
223
  MessageTypes["DEVELOPER"] = "developer";
220
224
  MessageTypes["REMOVE"] = "remove";
221
225
  })(exports.MessageTypes || (exports.MessageTypes = {}));
226
+ /** Default max characters for delegate results returned to parent (~8192 tokens at ~4 chars/token) */
227
+ const DEFAULT_DELEGATE_MAX_RESULT_CHARS = 32768;
228
+ /** Default timeout for delegate sub-agent execution in milliseconds (5 minutes) */
229
+ const DELEGATE_TIMEOUT_MS = 300_000;
230
+
231
+ exports.DEFAULT_DELEGATE_MAX_RESULT_CHARS = DEFAULT_DELEGATE_MAX_RESULT_CHARS;
232
+ exports.DELEGATE_TIMEOUT_MS = DELEGATE_TIMEOUT_MS;
222
233
  //# sourceMappingURL=enum.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum.cjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Agent update event in multi-agent graph/workflow */\n ON_AGENT_UPDATE = 'on_agent_update',\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n /** [Custom] Reasoning Delta events for messages */\n ON_REASONING_DELTA = 'on_reasoning_delta',\n /** [Custom] Context analytics event for traces */\n ON_CONTEXT_ANALYTICS = 'on_context_analytics',\n /** [Custom] Structured output event - emitted when agent returns structured JSON */\n ON_STRUCTURED_OUTPUT = 'on_structured_output',\n /** [Custom] Request to execute tools - dispatched by ToolNode, handled by host */\n ON_TOOL_EXECUTE = 'on_tool_execute',\n /** [Custom] Context pressure event for monitoring compaction triggers */\n ON_CONTEXT_PRESSURE = 'on_context_pressure',\n /** [Custom] Tool requires human approval before execution - dispatched by ToolNode HITL */\n ON_TOOL_APPROVAL_REQUIRED = 'on_tool_approval_required',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end',\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n MISTRAL = 'mistral',\n GOOGLE = 'google',\n AZURE = 'azureOpenAI',\n DEEPSEEK = 'deepseek',\n OPENROUTER = 'openrouter',\n XAI = 'xai',\n MOONSHOT = 'moonshot',\n}\n\nexport enum EdgeType {\n /** Creates handoff tools for dynamic agent routing (default for single-to-single edges) */\n HANDOFF = 'handoff',\n /** Creates direct edges for automatic sequential/parallel transitions */\n DIRECT = 'direct',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools=',\n AGENT = 'agent=',\n ROUTER = 'router',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation',\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n ERROR = 'error',\n THINK = 'think',\n TOOL_CALL = 'tool_call',\n IMAGE_URL = 'image_url',\n IMAGE_FILE = 'image_file',\n /** Anthropic */\n THINKING = 'thinking',\n /** Vertex AI / Google Common */\n REASONING = 'reasoning',\n /** Multi-Agent Switch */\n AGENT_UPDATE = 'agent_update',\n /** Bedrock */\n REASONING_CONTENT = 'reasoning_content',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n CUSTOM_EVENT = 'handleCustomEvent',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.illuma.ai/v1',\n EXECUTE_CODE = 'execute_code',\n TOOL_SEARCH = 'tool_search',\n PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code',\n WEB_SEARCH = 'web_search',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n LC_TRANSFER_TO_ = 'lc_transfer_to_',\n /** Tool name for the AskUser structured question tool */\n ASK_USER = 'ask_user',\n /** Delimiter for MCP tools: toolName_mcp_serverName */\n MCP_DELIMITER = '_mcp_',\n}\n\nexport enum TitleMethod {\n STRUCTURED = 'structured',\n FUNCTIONS = 'functions',\n COMPLETION = 'completion',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'CODE_EXECUTOR_API_KEY',\n CODE_BASEURL = 'CODE_EXECUTOR_BASEURL',\n}\n\n/**\n * Normalized LLM finish/stop reasons across providers.\n * Used by toolCallContinuation to detect max_tokens truncation.\n */\nexport enum FinishReasons {\n /** Anthropic / Bedrock stop reason for token limit */\n MAX_TOKENS = 'max_tokens',\n /** OpenAI / Azure finish reason for token limit */\n LENGTH = 'length',\n /** Normal completion */\n STOP = 'stop',\n /** Anthropic / Bedrock stop reason for normal completion */\n END_TURN = 'end_turn',\n /** Model chose to call tools */\n TOOL_USE = 'tool_use',\n /** OpenAI finish reason for tool calls */\n TOOL_CALLS = 'tool_calls',\n}\n\n/**\n * Message type identifiers used by LangChain's BaseMessage.getType().\n * Use these constants instead of instanceof checks to avoid module mismatch issues\n * when different copies of @langchain/core/messages are loaded.\n */\nexport enum MessageTypes {\n HUMAN = 'human',\n AI = 'ai',\n SYSTEM = 'system',\n TOOL = 'tool',\n FUNCTION = 'function',\n GENERIC = 'generic',\n DEVELOPER = 'developer',\n REMOVE = 'remove',\n}\n"],"names":["GraphEvents","Providers","EdgeType","GraphNodeKeys","GraphNodeActions","CommonEvents","StepTypes","ContentTypes","ToolCallTypes","Callback","Constants","TitleMethod","EnvVar","FinishReasons","MessageTypes"],"mappings":";;AAAA;;;;;AAKG;AACSA;AAAZ,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC;;AAEnC,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;;AAE3B,IAAA,WAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC;;AAEvC,IAAA,WAAA,CAAA,uBAAA,CAAA,GAAA,uBAA+C;;AAE/C,IAAA,WAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC;;AAErC,IAAA,WAAA,CAAA,oBAAA,CAAA,GAAA,oBA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WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,YAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EATWA,oBAAY,KAAZA,oBAAY,GAAA,EAAA,CAAA,CAAA;;"}
1
+ {"version":3,"file":"enum.cjs","sources":["../../../src/common/enum.ts"],"sourcesContent":["/**\n * Enum representing the various event types emitted during the execution of runnables.\n * These events provide real-time information about the progress and state of different components.\n *\n * @enum {string}\n */\nexport enum GraphEvents {\n /* Custom Events */\n\n /** [Custom] Agent update event in multi-agent graph/workflow */\n ON_AGENT_UPDATE = 'on_agent_update',\n /** [Custom] Delta event for run steps (message creation and tool calls) */\n ON_RUN_STEP = 'on_run_step',\n /** [Custom] Delta event for run steps (tool calls) */\n ON_RUN_STEP_DELTA = 'on_run_step_delta',\n /** [Custom] Completed event for run steps (tool calls) */\n ON_RUN_STEP_COMPLETED = 'on_run_step_completed',\n /** [Custom] Delta events for messages */\n ON_MESSAGE_DELTA = 'on_message_delta',\n /** [Custom] Reasoning Delta events for messages */\n ON_REASONING_DELTA = 'on_reasoning_delta',\n /** [Custom] Context analytics event for traces */\n ON_CONTEXT_ANALYTICS = 'on_context_analytics',\n /** [Custom] Structured output event - emitted when agent returns structured JSON */\n ON_STRUCTURED_OUTPUT = 'on_structured_output',\n /** [Custom] Request to execute tools - dispatched by ToolNode, handled by host */\n ON_TOOL_EXECUTE = 'on_tool_execute',\n /** [Custom] Context pressure event for monitoring compaction triggers */\n ON_CONTEXT_PRESSURE = 'on_context_pressure',\n /** [Custom] Tool requires human approval before execution - dispatched by ToolNode HITL */\n ON_TOOL_APPROVAL_REQUIRED = 'on_tool_approval_required',\n\n /* Official Events */\n\n /** Custom event, emitted by system */\n ON_CUSTOM_EVENT = 'on_custom_event',\n /** Emitted when a chat model starts processing. */\n CHAT_MODEL_START = 'on_chat_model_start',\n\n /** Emitted when a chat model streams a chunk of its response. */\n CHAT_MODEL_STREAM = 'on_chat_model_stream',\n\n /** Emitted when a chat model completes its processing. */\n CHAT_MODEL_END = 'on_chat_model_end',\n\n /** Emitted when a language model starts processing. */\n LLM_START = 'on_llm_start',\n\n /** Emitted when a language model streams a chunk of its response. */\n LLM_STREAM = 'on_llm_stream',\n\n /** Emitted when a language model completes its processing. */\n LLM_END = 'on_llm_end',\n\n /** Emitted when a chain starts processing. */\n CHAIN_START = 'on_chain_start',\n\n /** Emitted when a chain streams a chunk of its output. */\n CHAIN_STREAM = 'on_chain_stream',\n\n /** Emitted when a chain completes its processing. */\n CHAIN_END = 'on_chain_end',\n\n /** Emitted when a tool starts its operation. */\n TOOL_START = 'on_tool_start',\n\n /** Emitted when a tool completes its operation. */\n TOOL_END = 'on_tool_end',\n\n /** Emitted when a retriever starts its operation. */\n RETRIEVER_START = 'on_retriever_start',\n\n /** Emitted when a retriever completes its operation. */\n RETRIEVER_END = 'on_retriever_end',\n\n /** Emitted when a prompt starts processing. */\n PROMPT_START = 'on_prompt_start',\n\n /** Emitted when a prompt completes its processing. */\n PROMPT_END = 'on_prompt_end',\n}\n\nexport enum Providers {\n OPENAI = 'openAI',\n VERTEXAI = 'vertexai',\n BEDROCK = 'bedrock',\n ANTHROPIC = 'anthropic',\n MISTRALAI = 'mistralai',\n MISTRAL = 'mistral',\n GOOGLE = 'google',\n AZURE = 'azureOpenAI',\n DEEPSEEK = 'deepseek',\n OPENROUTER = 'openrouter',\n XAI = 'xai',\n MOONSHOT = 'moonshot',\n}\n\nexport enum EdgeType {\n /** Creates handoff tools for dynamic agent routing (default for single-to-single edges) */\n HANDOFF = 'handoff',\n /** Creates direct edges for automatic sequential/parallel transitions */\n DIRECT = 'direct',\n /** Creates delegate tools that invoke child subgraph inline and return result to parent */\n DELEGATE = 'delegate',\n}\n\nexport enum GraphNodeKeys {\n TOOLS = 'tools=',\n AGENT = 'agent=',\n ROUTER = 'router',\n PRE_TOOLS = 'pre_tools',\n POST_TOOLS = 'post_tools',\n}\n\nexport enum GraphNodeActions {\n TOOL_NODE = 'tool_node',\n CALL_MODEL = 'call_model',\n ROUTE_MESSAGE = 'route_message',\n}\n\nexport enum CommonEvents {\n LANGGRAPH = 'LangGraph',\n}\n\nexport enum StepTypes {\n TOOL_CALLS = 'tool_calls',\n MESSAGE_CREATION = 'message_creation',\n}\n\nexport enum ContentTypes {\n TEXT = 'text',\n ERROR = 'error',\n THINK = 'think',\n TOOL_CALL = 'tool_call',\n IMAGE_URL = 'image_url',\n IMAGE_FILE = 'image_file',\n /** Anthropic */\n THINKING = 'thinking',\n /** Vertex AI / Google Common */\n REASONING = 'reasoning',\n /** Multi-Agent Switch */\n AGENT_UPDATE = 'agent_update',\n /** Bedrock */\n REASONING_CONTENT = 'reasoning_content',\n}\n\nexport enum ToolCallTypes {\n FUNCTION = 'function',\n RETRIEVAL = 'retrieval',\n FILE_SEARCH = 'file_search',\n CODE_INTERPRETER = 'code_interpreter',\n /* Agents Tool Call */\n TOOL_CALL = 'tool_call',\n}\n\nexport enum Callback {\n TOOL_ERROR = 'handleToolError',\n TOOL_START = 'handleToolStart',\n TOOL_END = 'handleToolEnd',\n CUSTOM_EVENT = 'handleCustomEvent',\n /*\n LLM_START = 'handleLLMStart',\n LLM_NEW_TOKEN = 'handleLLMNewToken',\n LLM_ERROR = 'handleLLMError',\n LLM_END = 'handleLLMEnd',\n CHAT_MODEL_START = 'handleChatModelStart',\n CHAIN_START = 'handleChainStart',\n CHAIN_ERROR = 'handleChainError',\n CHAIN_END = 'handleChainEnd',\n TEXT = 'handleText',\n AGENT_ACTION = 'handleAgentAction',\n AGENT_END = 'handleAgentEnd',\n RETRIEVER_START = 'handleRetrieverStart',\n RETRIEVER_END = 'handleRetrieverEnd',\n RETRIEVER_ERROR = 'handleRetrieverError',\n */\n}\n\nexport enum Constants {\n OFFICIAL_CODE_BASEURL = 'https://api.illuma.ai/v1',\n EXECUTE_CODE = 'execute_code',\n TOOL_SEARCH = 'tool_search',\n PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code',\n WEB_SEARCH = 'web_search',\n CONTENT_AND_ARTIFACT = 'content_and_artifact',\n LC_TRANSFER_TO_ = 'lc_transfer_to_',\n /** Prefix for delegate tool names: lc_delegate_to_{agentId} */\n LC_DELEGATE_TO_ = 'lc_delegate_to_',\n /** Tool name for the AskUser structured question tool */\n ASK_USER = 'ask_user',\n /** Delimiter for MCP tools: toolName_mcp_serverName */\n MCP_DELIMITER = '_mcp_',\n}\n\nexport enum TitleMethod {\n STRUCTURED = 'structured',\n FUNCTIONS = 'functions',\n COMPLETION = 'completion',\n}\n\nexport enum EnvVar {\n CODE_API_KEY = 'CODE_EXECUTOR_API_KEY',\n CODE_BASEURL = 'CODE_EXECUTOR_BASEURL',\n}\n\n/**\n * Normalized LLM finish/stop reasons across providers.\n * Used by toolCallContinuation to detect max_tokens truncation.\n */\nexport enum FinishReasons {\n /** Anthropic / Bedrock stop reason for token limit */\n MAX_TOKENS = 'max_tokens',\n /** OpenAI / Azure finish reason for token limit */\n LENGTH = 'length',\n /** Normal completion */\n STOP = 'stop',\n /** Anthropic / Bedrock stop reason for normal completion */\n END_TURN = 'end_turn',\n /** Model chose to call tools */\n TOOL_USE = 'tool_use',\n /** OpenAI finish reason for tool calls */\n TOOL_CALLS = 'tool_calls',\n}\n\n/**\n * Message type identifiers used by LangChain's BaseMessage.getType().\n * Use these constants instead of instanceof checks to avoid module mismatch issues\n * when different copies of @langchain/core/messages are loaded.\n */\nexport enum MessageTypes {\n HUMAN = 'human',\n AI = 'ai',\n SYSTEM = 'system',\n TOOL = 'tool',\n FUNCTION = 'function',\n GENERIC = 'generic',\n DEVELOPER = 'developer',\n REMOVE = 'remove',\n}\n\n/** Default max characters for delegate results returned to parent (~8192 tokens at ~4 chars/token) */\nexport const DEFAULT_DELEGATE_MAX_RESULT_CHARS = 32768;\n\n/** Default timeout for delegate sub-agent execution in milliseconds (5 minutes) */\nexport const DELEGATE_TIMEOUT_MS = 300_000;\n"],"names":["GraphEvents","Providers","EdgeType","GraphNodeKeys","GraphNodeActions","CommonEvents","StepTypes","Content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,GAAA,UAAqB;;AAErB,IAAA,aAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;;AAErB,IAAA,aAAA,CAAA,YAAA,CAAA,GAAA,YAAyB;AAC3B,CAAC,EAbWA,qBAAa,KAAbA,qBAAa,GAAA,EAAA,CAAA,CAAA;AAezB;;;;AAIG;AACSC;AAAZ,CAAA,UAAY,YAAY,EAAA;AACtB,IAAA,YAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,YAAA,CAAA,IAAA,CAAA,GAAA,IAAS;AACT,IAAA,YAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACjB,IAAA,YAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,YAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,YAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,YAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AACvB,IAAA,YAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EATWA,oBAAY,KAAZA,oBAAY,GAAA,EAAA,CAAA,CAAA;AAWxB;AACO,MAAM,iCAAiC,GAAG;AAEjD;AACO,MAAM,mBAAmB,GAAG;;;;;"}
@@ -33,6 +33,15 @@ class MultiAgentGraph extends Graph.StandardGraph {
33
33
  startingNodes = new Set();
34
34
  directEdges = [];
35
35
  handoffEdges = [];
36
+ delegateEdges = [];
37
+ /**
38
+ * Lazily populated registry of compiled subgraphs, keyed by agentId.
39
+ * Delegate tools are created in the constructor but reference subgraphs
40
+ * that are only created in createWorkflow(). This Map bridges that gap —
41
+ * tools capture the Map reference in their closure, and createWorkflow()
42
+ * populates it before any tool invocation occurs.
43
+ */
44
+ subgraphRegistry = new Map();
36
45
  /**
37
46
  * Map of agentId to parallel group info.
38
47
  * Contains groupId (incrementing number reflecting execution order) for agents in parallel groups.
@@ -55,6 +64,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
55
64
  this.categorizeEdges();
56
65
  this.analyzeGraph();
57
66
  this.createHandoffTools();
67
+ this.createDelegateTools();
58
68
  console.debug(`[MultiAgentGraph] Constructor complete: ${this.agentContexts.size} agents, ${this.edges.length} edges`);
59
69
  }
60
70
  /**
@@ -64,7 +74,10 @@ class MultiAgentGraph extends Graph.StandardGraph {
64
74
  for (const edge of this.edges) {
65
75
  // Default behavior: edges with conditions or explicit 'handoff' type are handoff edges
66
76
  // Edges with explicit 'direct' type or multi-destination without conditions are direct edges
67
- if (edge.edgeType === _enum.EdgeType.DIRECT) {
77
+ if (edge.edgeType === _enum.EdgeType.DELEGATE) {
78
+ this.delegateEdges.push(edge);
79
+ }
80
+ else if (edge.edgeType === _enum.EdgeType.DIRECT) {
68
81
  this.directEdges.push(edge);
69
82
  }
70
83
  else if (edge.edgeType === _enum.EdgeType.HANDOFF || edge.condition != null) {
@@ -84,7 +97,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
84
97
  }
85
98
  }
86
99
  }
87
- console.debug(`[MultiAgentGraph] Edge categorization: ${this.handoffEdges.length} handoff, ${this.directEdges.length} direct (of ${this.edges.length} total)`);
100
+ console.debug(`[MultiAgentGraph] Edge categorization: ${this.handoffEdges.length} handoff, ${this.directEdges.length} direct, ${this.delegateEdges.length} delegate (of ${this.edges.length} total)`);
88
101
  }
89
102
  /**
90
103
  * Analyze graph structure to determine starting nodes and connections
@@ -170,8 +183,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
170
183
  }
171
184
  }
172
185
  }
173
- // Also follow handoff edges for traversal (but they don't create parallel groups)
174
- for (const edge of this.handoffEdges) {
186
+ // Also follow handoff and delegate edges for traversal (they don't create parallel groups)
187
+ for (const edge of [...this.handoffEdges, ...this.delegateEdges]) {
175
188
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
176
189
  if (!sources.includes(current))
177
190
  continue;
@@ -452,6 +465,193 @@ class MultiAgentGraph extends Graph.StandardGraph {
452
465
  }
453
466
  return `Transfer control to "${displayName}"`;
454
467
  }
468
+ /**
469
+ * Create delegate tools for agents based on delegate edges.
470
+ * Delegate tools invoke child agent subgraphs inline and return the result
471
+ * as a string to the parent agent's context. Unlike handoff tools (which
472
+ * return Command for fire-and-forget routing), delegate tools execute the
473
+ * child, extract the final text, and return it within the parent's agent loop.
474
+ *
475
+ * This enables the supervisor pattern: parent calls child → gets result → thinks → calls another.
476
+ */
477
+ createDelegateTools() {
478
+ const delegatesByAgent = new Map();
479
+ for (const edge of this.delegateEdges) {
480
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
481
+ sources.forEach((source) => {
482
+ if (!delegatesByAgent.has(source)) {
483
+ delegatesByAgent.set(source, []);
484
+ }
485
+ delegatesByAgent.get(source).push(edge);
486
+ });
487
+ }
488
+ for (const [agentId, edges] of delegatesByAgent) {
489
+ const agentContext = this.agentContexts.get(agentId);
490
+ if (!agentContext)
491
+ continue;
492
+ const delegateTools = [];
493
+ for (const edge of edges) {
494
+ delegateTools.push(...this.createDelegateToolsForEdge(edge, agentId));
495
+ }
496
+ if (!agentContext.graphTools) {
497
+ agentContext.graphTools = [];
498
+ }
499
+ agentContext.graphTools.push(...delegateTools);
500
+ console.debug(`[MultiAgentGraph] Delegate tools for "${agentId}": [${delegateTools.map((t) => t.name).join(', ')}]`);
501
+ }
502
+ }
503
+ /**
504
+ * Create delegate tools for an edge (handles multiple destinations).
505
+ * Each delegate tool invokes the child agent's compiled subgraph inline,
506
+ * extracts the final AI message text, truncates it, and returns it as
507
+ * a string (which becomes a ToolMessage in the parent's context).
508
+ *
509
+ * @param edge - The graph edge defining the delegation
510
+ * @param sourceAgentId - The ID of the parent/supervisor agent
511
+ */
512
+ createDelegateToolsForEdge(edge, sourceAgentId) {
513
+ const tools$1 = [];
514
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
515
+ const maxResultChars = edge.maxResultChars ?? _enum.DEFAULT_DELEGATE_MAX_RESULT_CHARS;
516
+ for (const destination of destinations) {
517
+ const toolName = `${_enum.Constants.LC_DELEGATE_TO_}${destination}`;
518
+ const destContext = this.agentContexts.get(destination);
519
+ const toolDescription = edge.description ??
520
+ this.buildDefaultDelegateDescription(destContext, destination);
521
+ const hasPromptInput = edge.prompt != null && typeof edge.prompt === 'string';
522
+ const promptInputDescription = hasPromptInput ? edge.prompt : undefined;
523
+ const promptKey = edge.promptKey ?? 'instructions';
524
+ /** Capture registry reference — Map populated in createWorkflow() */
525
+ const registry = this.subgraphRegistry;
526
+ tools$1.push(tools.tool(async (rawInput, config) => {
527
+ const input = rawInput;
528
+ const subgraph = registry.get(destination);
529
+ if (!subgraph) {
530
+ throw new Error(`Delegate target "${destination}" subgraph not found in registry. ` +
531
+ 'This is a bug: createWorkflow() should have populated the subgraph registry.');
532
+ }
533
+ const state = langgraph.getCurrentTaskInput();
534
+ let childMessages = [...state.messages];
535
+ /** Inject instructions as HumanMessage if provided by the parent LLM */
536
+ if (hasPromptInput &&
537
+ promptKey in input &&
538
+ input[promptKey] != null) {
539
+ childMessages = [
540
+ ...childMessages,
541
+ new messages.HumanMessage(String(input[promptKey])),
542
+ ];
543
+ }
544
+ const childState = {
545
+ messages: childMessages,
546
+ };
547
+ console.debug(`[MultiAgentGraph] Delegate "${sourceAgentId}" -> "${destination}" START ` +
548
+ `(messages: ${childMessages.length})`);
549
+ try {
550
+ /**
551
+ * Invoke the child subgraph with config propagation.
552
+ * Config carries callbacks (for SSE streaming), abort signal,
553
+ * and configurable data (thread_id, user_id) to the child.
554
+ */
555
+ const result = await subgraph.invoke(childState, config);
556
+ const resultText = MultiAgentGraph.extractDelegateResult(result.messages, destination);
557
+ const truncatedResult = MultiAgentGraph.truncateDelegateResult(resultText, maxResultChars);
558
+ console.debug(`[MultiAgentGraph] Delegate "${sourceAgentId}" -> "${destination}" DONE ` +
559
+ `(result: ${resultText.length} chars` +
560
+ `${truncatedResult.length < resultText.length ? `, truncated to ${truncatedResult.length}` : ''})`);
561
+ return truncatedResult;
562
+ }
563
+ catch (err) {
564
+ const errorMessage = err instanceof Error ? err.message : String(err);
565
+ console.error(`[MultiAgentGraph] Delegate "${sourceAgentId}" -> "${destination}" ERROR:`, errorMessage);
566
+ return `[Delegate to "${destination}" failed: ${errorMessage}]`;
567
+ }
568
+ }, {
569
+ name: toolName,
570
+ schema: hasPromptInput
571
+ ? {
572
+ type: 'object',
573
+ properties: {
574
+ [promptKey]: {
575
+ type: 'string',
576
+ description: promptInputDescription,
577
+ },
578
+ },
579
+ required: [],
580
+ }
581
+ : { type: 'object', properties: {}, required: [] },
582
+ description: toolDescription,
583
+ }));
584
+ }
585
+ return tools$1;
586
+ }
587
+ /**
588
+ * Extract the final text result from a child agent's output messages.
589
+ * Walks backwards to find the last AIMessage with text content.
590
+ * Handles both string content and array content (multi-modal messages).
591
+ * @param messages - The child agent's output messages
592
+ * @param agentId - The child agent ID (for fallback message)
593
+ */
594
+ static extractDelegateResult(messages, agentId) {
595
+ for (let i = messages.length - 1; i >= 0; i--) {
596
+ const msg = messages[i];
597
+ if (msg.getType() !== 'ai')
598
+ continue;
599
+ const content = msg.content;
600
+ if (typeof content === 'string' && content.trim()) {
601
+ return content.trim();
602
+ }
603
+ /** Handle array content (multi-modal messages with text blocks) */
604
+ if (Array.isArray(content)) {
605
+ const textParts = content
606
+ .filter((block) => typeof block === 'object' &&
607
+ block !== null &&
608
+ 'type' in block &&
609
+ block.type === 'text' &&
610
+ 'text' in block &&
611
+ typeof block.text === 'string')
612
+ .map((block) => block.text);
613
+ const text = textParts.join('\n').trim();
614
+ if (text)
615
+ return text;
616
+ }
617
+ }
618
+ return `[Agent "${agentId}" completed but produced no text output]`;
619
+ }
620
+ /**
621
+ * Truncate delegate result using head/tail strategy (60/40 split).
622
+ * Preserves the beginning (key findings) and end (conclusions).
623
+ * Matches the TaskTool.truncateResult pattern from Ranger.
624
+ * @param result - The full result text
625
+ * @param maxChars - Maximum allowed characters
626
+ */
627
+ static truncateDelegateResult(result, maxChars) {
628
+ if (!result || result.length <= maxChars) {
629
+ return result;
630
+ }
631
+ const truncationNotice = '\n\n[... delegate output truncated — middle section omitted to fit parent context ...]\n\n';
632
+ const available = maxChars - truncationNotice.length;
633
+ if (available <= 0) {
634
+ return result.substring(0, maxChars);
635
+ }
636
+ const headSize = Math.floor(available * 0.6);
637
+ const tailSize = available - headSize;
638
+ return (result.substring(0, headSize) +
639
+ truncationNotice +
640
+ result.substring(result.length - tailSize));
641
+ }
642
+ /**
643
+ * Build a meaningful default description for a delegate tool.
644
+ * @param destContext - AgentContext of the destination agent
645
+ * @param destinationId - Raw agent ID (fallback)
646
+ */
647
+ buildDefaultDelegateDescription(destContext, destinationId) {
648
+ const displayName = destContext?.name ?? destinationId;
649
+ const agentDescription = destContext?.description;
650
+ if (agentDescription != null && agentDescription !== '') {
651
+ return `Delegate task to "${displayName}": ${agentDescription}. The agent will execute and return its result.`;
652
+ }
653
+ return `Delegate task to "${displayName}" and receive its result.`;
654
+ }
455
655
  /**
456
656
  * Create a complete agent subgraph (similar to createReactAgent)
457
657
  */
@@ -753,6 +953,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
753
953
  }
754
954
  /** Agent subgraph (includes agent + tools) */
755
955
  const agentSubgraph = this.createAgentSubgraph(agentId);
956
+ /** Register subgraph for delegate tools (lazy reference resolution) */
957
+ this.subgraphRegistry.set(agentId, agentSubgraph);
756
958
  /** Wrapper function that handles agentMessages channel, handoff reception, and conditional routing */
757
959
  const agentWrapper = async (state, config) => {
758
960
  console.debug(`[MultiAgentGraph] Agent "${agentId}" wrapper ENTRY (messages: ${state.messages.length}, needsCommandRouting: ${needsCommandRouting})`);