@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.
@@ -84,6 +84,8 @@ var EdgeType;
84
84
  EdgeType["HANDOFF"] = "handoff";
85
85
  /** Creates direct edges for automatic sequential/parallel transitions */
86
86
  EdgeType["DIRECT"] = "direct";
87
+ /** Creates delegate tools that invoke child subgraph inline and return result to parent */
88
+ EdgeType["DELEGATE"] = "delegate";
87
89
  })(EdgeType || (EdgeType = {}));
88
90
  var GraphNodeKeys;
89
91
  (function (GraphNodeKeys) {
@@ -166,6 +168,8 @@ var Constants;
166
168
  Constants["WEB_SEARCH"] = "web_search";
167
169
  Constants["CONTENT_AND_ARTIFACT"] = "content_and_artifact";
168
170
  Constants["LC_TRANSFER_TO_"] = "lc_transfer_to_";
171
+ /** Prefix for delegate tool names: lc_delegate_to_{agentId} */
172
+ Constants["LC_DELEGATE_TO_"] = "lc_delegate_to_";
169
173
  /** Tool name for the AskUser structured question tool */
170
174
  Constants["ASK_USER"] = "ask_user";
171
175
  /** Delimiter for MCP tools: toolName_mcp_serverName */
@@ -217,6 +221,10 @@ var MessageTypes;
217
221
  MessageTypes["DEVELOPER"] = "developer";
218
222
  MessageTypes["REMOVE"] = "remove";
219
223
  })(MessageTypes || (MessageTypes = {}));
224
+ /** Default max characters for delegate results returned to parent (~8192 tokens at ~4 chars/token) */
225
+ const DEFAULT_DELEGATE_MAX_RESULT_CHARS = 32768;
226
+ /** Default timeout for delegate sub-agent execution in milliseconds (5 minutes) */
227
+ const DELEGATE_TIMEOUT_MS = 300_000;
220
228
 
221
- export { Callback, CommonEvents, Constants, ContentTypes, EdgeType, EnvVar, FinishReasons, GraphEvents, GraphNodeActions, GraphNodeKeys, MessageTypes, Providers, StepTypes, TitleMethod, ToolCallTypes };
229
+ export { Callback, CommonEvents, Constants, ContentTypes, DEFAULT_DELEGATE_MAX_RESULT_CHARS, DELEGATE_TIMEOUT_MS, EdgeType, EnvVar, FinishReasons, GraphEvents, GraphNodeActions, GraphNodeKeys, MessageTypes, Providers, StepTypes, TitleMethod, ToolCallTypes };
222
230
  //# sourceMappingURL=enum.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum.mjs","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":[],"mappings":"AAAA;;;;;AAKG;IACS;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,oBAA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,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EATW,YAAY,KAAZ,YAAY,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"enum.mjs","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":[],"mappings":"AAAA;;;;;AAKG;IACS;AAAZ,CAAA,UAAY,WAAW,EAAA;;;AAIrB,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBA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,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,EATW,YAAY,KAAZ,YAAY,GAAA,EAAA,CAAA,CAAA;AAWxB;AACO,MAAM,iCAAiC,GAAG;AAEjD;AACO,MAAM,mBAAmB,GAAG;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { tool } from '@langchain/core/tools';
2
2
  import { PromptTemplate } from '@langchain/core/prompts';
3
- import { ToolMessage, AIMessage, getBufferString, HumanMessage, SystemMessage } from '@langchain/core/messages';
3
+ import { ToolMessage, AIMessage, HumanMessage, getBufferString, SystemMessage } from '@langchain/core/messages';
4
4
  import { getCurrentTaskInput, Command, Annotation, messagesStateReducer, StateGraph, END, START } from '@langchain/langgraph';
5
5
  import '../messages/core.mjs';
6
6
  import 'nanoid';
7
- import { EdgeType, Constants } from '../common/enum.mjs';
7
+ import { EdgeType, Constants, DEFAULT_DELEGATE_MAX_RESULT_CHARS } from '../common/enum.mjs';
8
8
  import '../tools/approval/constants.mjs';
9
9
  import '../utils/toonFormat.mjs';
10
10
  import { summarize, createEmergencySummary } from '../messages/summarize.mjs';
@@ -31,6 +31,15 @@ class MultiAgentGraph extends StandardGraph {
31
31
  startingNodes = new Set();
32
32
  directEdges = [];
33
33
  handoffEdges = [];
34
+ delegateEdges = [];
35
+ /**
36
+ * Lazily populated registry of compiled subgraphs, keyed by agentId.
37
+ * Delegate tools are created in the constructor but reference subgraphs
38
+ * that are only created in createWorkflow(). This Map bridges that gap —
39
+ * tools capture the Map reference in their closure, and createWorkflow()
40
+ * populates it before any tool invocation occurs.
41
+ */
42
+ subgraphRegistry = new Map();
34
43
  /**
35
44
  * Map of agentId to parallel group info.
36
45
  * Contains groupId (incrementing number reflecting execution order) for agents in parallel groups.
@@ -53,6 +62,7 @@ class MultiAgentGraph extends StandardGraph {
53
62
  this.categorizeEdges();
54
63
  this.analyzeGraph();
55
64
  this.createHandoffTools();
65
+ this.createDelegateTools();
56
66
  console.debug(`[MultiAgentGraph] Constructor complete: ${this.agentContexts.size} agents, ${this.edges.length} edges`);
57
67
  }
58
68
  /**
@@ -62,7 +72,10 @@ class MultiAgentGraph extends StandardGraph {
62
72
  for (const edge of this.edges) {
63
73
  // Default behavior: edges with conditions or explicit 'handoff' type are handoff edges
64
74
  // Edges with explicit 'direct' type or multi-destination without conditions are direct edges
65
- if (edge.edgeType === EdgeType.DIRECT) {
75
+ if (edge.edgeType === EdgeType.DELEGATE) {
76
+ this.delegateEdges.push(edge);
77
+ }
78
+ else if (edge.edgeType === EdgeType.DIRECT) {
66
79
  this.directEdges.push(edge);
67
80
  }
68
81
  else if (edge.edgeType === EdgeType.HANDOFF || edge.condition != null) {
@@ -82,7 +95,7 @@ class MultiAgentGraph extends StandardGraph {
82
95
  }
83
96
  }
84
97
  }
85
- console.debug(`[MultiAgentGraph] Edge categorization: ${this.handoffEdges.length} handoff, ${this.directEdges.length} direct (of ${this.edges.length} total)`);
98
+ console.debug(`[MultiAgentGraph] Edge categorization: ${this.handoffEdges.length} handoff, ${this.directEdges.length} direct, ${this.delegateEdges.length} delegate (of ${this.edges.length} total)`);
86
99
  }
87
100
  /**
88
101
  * Analyze graph structure to determine starting nodes and connections
@@ -168,8 +181,8 @@ class MultiAgentGraph extends StandardGraph {
168
181
  }
169
182
  }
170
183
  }
171
- // Also follow handoff edges for traversal (but they don't create parallel groups)
172
- for (const edge of this.handoffEdges) {
184
+ // Also follow handoff and delegate edges for traversal (they don't create parallel groups)
185
+ for (const edge of [...this.handoffEdges, ...this.delegateEdges]) {
173
186
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
174
187
  if (!sources.includes(current))
175
188
  continue;
@@ -450,6 +463,193 @@ class MultiAgentGraph extends StandardGraph {
450
463
  }
451
464
  return `Transfer control to "${displayName}"`;
452
465
  }
466
+ /**
467
+ * Create delegate tools for agents based on delegate edges.
468
+ * Delegate tools invoke child agent subgraphs inline and return the result
469
+ * as a string to the parent agent's context. Unlike handoff tools (which
470
+ * return Command for fire-and-forget routing), delegate tools execute the
471
+ * child, extract the final text, and return it within the parent's agent loop.
472
+ *
473
+ * This enables the supervisor pattern: parent calls child → gets result → thinks → calls another.
474
+ */
475
+ createDelegateTools() {
476
+ const delegatesByAgent = new Map();
477
+ for (const edge of this.delegateEdges) {
478
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
479
+ sources.forEach((source) => {
480
+ if (!delegatesByAgent.has(source)) {
481
+ delegatesByAgent.set(source, []);
482
+ }
483
+ delegatesByAgent.get(source).push(edge);
484
+ });
485
+ }
486
+ for (const [agentId, edges] of delegatesByAgent) {
487
+ const agentContext = this.agentContexts.get(agentId);
488
+ if (!agentContext)
489
+ continue;
490
+ const delegateTools = [];
491
+ for (const edge of edges) {
492
+ delegateTools.push(...this.createDelegateToolsForEdge(edge, agentId));
493
+ }
494
+ if (!agentContext.graphTools) {
495
+ agentContext.graphTools = [];
496
+ }
497
+ agentContext.graphTools.push(...delegateTools);
498
+ console.debug(`[MultiAgentGraph] Delegate tools for "${agentId}": [${delegateTools.map((t) => t.name).join(', ')}]`);
499
+ }
500
+ }
501
+ /**
502
+ * Create delegate tools for an edge (handles multiple destinations).
503
+ * Each delegate tool invokes the child agent's compiled subgraph inline,
504
+ * extracts the final AI message text, truncates it, and returns it as
505
+ * a string (which becomes a ToolMessage in the parent's context).
506
+ *
507
+ * @param edge - The graph edge defining the delegation
508
+ * @param sourceAgentId - The ID of the parent/supervisor agent
509
+ */
510
+ createDelegateToolsForEdge(edge, sourceAgentId) {
511
+ const tools = [];
512
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
513
+ const maxResultChars = edge.maxResultChars ?? DEFAULT_DELEGATE_MAX_RESULT_CHARS;
514
+ for (const destination of destinations) {
515
+ const toolName = `${Constants.LC_DELEGATE_TO_}${destination}`;
516
+ const destContext = this.agentContexts.get(destination);
517
+ const toolDescription = edge.description ??
518
+ this.buildDefaultDelegateDescription(destContext, destination);
519
+ const hasPromptInput = edge.prompt != null && typeof edge.prompt === 'string';
520
+ const promptInputDescription = hasPromptInput ? edge.prompt : undefined;
521
+ const promptKey = edge.promptKey ?? 'instructions';
522
+ /** Capture registry reference — Map populated in createWorkflow() */
523
+ const registry = this.subgraphRegistry;
524
+ tools.push(tool(async (rawInput, config) => {
525
+ const input = rawInput;
526
+ const subgraph = registry.get(destination);
527
+ if (!subgraph) {
528
+ throw new Error(`Delegate target "${destination}" subgraph not found in registry. ` +
529
+ 'This is a bug: createWorkflow() should have populated the subgraph registry.');
530
+ }
531
+ const state = getCurrentTaskInput();
532
+ let childMessages = [...state.messages];
533
+ /** Inject instructions as HumanMessage if provided by the parent LLM */
534
+ if (hasPromptInput &&
535
+ promptKey in input &&
536
+ input[promptKey] != null) {
537
+ childMessages = [
538
+ ...childMessages,
539
+ new HumanMessage(String(input[promptKey])),
540
+ ];
541
+ }
542
+ const childState = {
543
+ messages: childMessages,
544
+ };
545
+ console.debug(`[MultiAgentGraph] Delegate "${sourceAgentId}" -> "${destination}" START ` +
546
+ `(messages: ${childMessages.length})`);
547
+ try {
548
+ /**
549
+ * Invoke the child subgraph with config propagation.
550
+ * Config carries callbacks (for SSE streaming), abort signal,
551
+ * and configurable data (thread_id, user_id) to the child.
552
+ */
553
+ const result = await subgraph.invoke(childState, config);
554
+ const resultText = MultiAgentGraph.extractDelegateResult(result.messages, destination);
555
+ const truncatedResult = MultiAgentGraph.truncateDelegateResult(resultText, maxResultChars);
556
+ console.debug(`[MultiAgentGraph] Delegate "${sourceAgentId}" -> "${destination}" DONE ` +
557
+ `(result: ${resultText.length} chars` +
558
+ `${truncatedResult.length < resultText.length ? `, truncated to ${truncatedResult.length}` : ''})`);
559
+ return truncatedResult;
560
+ }
561
+ catch (err) {
562
+ const errorMessage = err instanceof Error ? err.message : String(err);
563
+ console.error(`[MultiAgentGraph] Delegate "${sourceAgentId}" -> "${destination}" ERROR:`, errorMessage);
564
+ return `[Delegate to "${destination}" failed: ${errorMessage}]`;
565
+ }
566
+ }, {
567
+ name: toolName,
568
+ schema: hasPromptInput
569
+ ? {
570
+ type: 'object',
571
+ properties: {
572
+ [promptKey]: {
573
+ type: 'string',
574
+ description: promptInputDescription,
575
+ },
576
+ },
577
+ required: [],
578
+ }
579
+ : { type: 'object', properties: {}, required: [] },
580
+ description: toolDescription,
581
+ }));
582
+ }
583
+ return tools;
584
+ }
585
+ /**
586
+ * Extract the final text result from a child agent's output messages.
587
+ * Walks backwards to find the last AIMessage with text content.
588
+ * Handles both string content and array content (multi-modal messages).
589
+ * @param messages - The child agent's output messages
590
+ * @param agentId - The child agent ID (for fallback message)
591
+ */
592
+ static extractDelegateResult(messages, agentId) {
593
+ for (let i = messages.length - 1; i >= 0; i--) {
594
+ const msg = messages[i];
595
+ if (msg.getType() !== 'ai')
596
+ continue;
597
+ const content = msg.content;
598
+ if (typeof content === 'string' && content.trim()) {
599
+ return content.trim();
600
+ }
601
+ /** Handle array content (multi-modal messages with text blocks) */
602
+ if (Array.isArray(content)) {
603
+ const textParts = content
604
+ .filter((block) => typeof block === 'object' &&
605
+ block !== null &&
606
+ 'type' in block &&
607
+ block.type === 'text' &&
608
+ 'text' in block &&
609
+ typeof block.text === 'string')
610
+ .map((block) => block.text);
611
+ const text = textParts.join('\n').trim();
612
+ if (text)
613
+ return text;
614
+ }
615
+ }
616
+ return `[Agent "${agentId}" completed but produced no text output]`;
617
+ }
618
+ /**
619
+ * Truncate delegate result using head/tail strategy (60/40 split).
620
+ * Preserves the beginning (key findings) and end (conclusions).
621
+ * Matches the TaskTool.truncateResult pattern from Ranger.
622
+ * @param result - The full result text
623
+ * @param maxChars - Maximum allowed characters
624
+ */
625
+ static truncateDelegateResult(result, maxChars) {
626
+ if (!result || result.length <= maxChars) {
627
+ return result;
628
+ }
629
+ const truncationNotice = '\n\n[... delegate output truncated — middle section omitted to fit parent context ...]\n\n';
630
+ const available = maxChars - truncationNotice.length;
631
+ if (available <= 0) {
632
+ return result.substring(0, maxChars);
633
+ }
634
+ const headSize = Math.floor(available * 0.6);
635
+ const tailSize = available - headSize;
636
+ return (result.substring(0, headSize) +
637
+ truncationNotice +
638
+ result.substring(result.length - tailSize));
639
+ }
640
+ /**
641
+ * Build a meaningful default description for a delegate tool.
642
+ * @param destContext - AgentContext of the destination agent
643
+ * @param destinationId - Raw agent ID (fallback)
644
+ */
645
+ buildDefaultDelegateDescription(destContext, destinationId) {
646
+ const displayName = destContext?.name ?? destinationId;
647
+ const agentDescription = destContext?.description;
648
+ if (agentDescription != null && agentDescription !== '') {
649
+ return `Delegate task to "${displayName}": ${agentDescription}. The agent will execute and return its result.`;
650
+ }
651
+ return `Delegate task to "${displayName}" and receive its result.`;
652
+ }
453
653
  /**
454
654
  * Create a complete agent subgraph (similar to createReactAgent)
455
655
  */
@@ -751,6 +951,8 @@ class MultiAgentGraph extends StandardGraph {
751
951
  }
752
952
  /** Agent subgraph (includes agent + tools) */
753
953
  const agentSubgraph = this.createAgentSubgraph(agentId);
954
+ /** Register subgraph for delegate tools (lazy reference resolution) */
955
+ this.subgraphRegistry.set(agentId, agentSubgraph);
754
956
  /** Wrapper function that handles agentMessages channel, handoff reception, and conditional routing */
755
957
  const agentWrapper = async (state, config) => {
756
958
  console.debug(`[MultiAgentGraph] Agent "${agentId}" wrapper ENTRY (messages: ${state.messages.length}, needsCommandRouting: ${needsCommandRouting})`);