@librechat/agents 3.0.65 → 3.0.66

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.
@@ -497,15 +497,15 @@ export class MultiAgentGraph extends StandardGraph {
497
497
 
498
498
  /**
499
499
  * Detects if the current agent is receiving a handoff and processes the messages accordingly.
500
- * Returns filtered messages with the transfer tool call/message removed, plus any instructions
501
- * and source agent information extracted from the transfer.
500
+ * Returns filtered messages with the transfer tool call/message removed, plus any instructions,
501
+ * source agent, and parallel sibling information extracted from the transfer.
502
502
  *
503
503
  * Supports both single handoffs (last message is the transfer) and parallel handoffs
504
504
  * (multiple transfer ToolMessages, need to find the one targeting this agent).
505
505
  *
506
506
  * @param messages - Current state messages
507
507
  * @param agentId - The agent ID to check for handoff reception
508
- * @returns Object with filtered messages, extracted instructions, and source agent, or null if not a handoff
508
+ * @returns Object with filtered messages, extracted instructions, source agent, and parallel siblings
509
509
  */
510
510
  private processHandoffReception(
511
511
  messages: BaseMessage[],
@@ -514,6 +514,7 @@ export class MultiAgentGraph extends StandardGraph {
514
514
  filteredMessages: BaseMessage[];
515
515
  instructions: string | null;
516
516
  sourceAgentName: string | null;
517
+ parallelSiblings: string[];
517
518
  } | null {
518
519
  if (messages.length === 0) return null;
519
520
 
@@ -575,6 +576,17 @@ export class MultiAgentGraph extends StandardGraph {
575
576
  const sourceAgentName =
576
577
  typeof handoffSourceName === 'string' ? handoffSourceName : null;
577
578
 
579
+ /** Extract parallel siblings (set by ToolNode for parallel handoffs) */
580
+ const rawSiblings = toolMessage.additional_kwargs.handoff_parallel_siblings;
581
+ const siblingIds: string[] = Array.isArray(rawSiblings)
582
+ ? rawSiblings.filter((s): s is string => typeof s === 'string')
583
+ : [];
584
+ /** Convert IDs to display names */
585
+ const parallelSiblings = siblingIds.map((id) => {
586
+ const ctx = this.agentContexts.get(id);
587
+ return ctx?.name ?? id;
588
+ });
589
+
578
590
  /** Get the tool_call_id to find and filter the AI message's tool call */
579
591
  const toolCallId = toolMessage.tool_call_id;
580
592
 
@@ -648,7 +660,12 @@ export class MultiAgentGraph extends StandardGraph {
648
660
  filteredMessages.push(msg);
649
661
  }
650
662
 
651
- return { filteredMessages, instructions, sourceAgentName };
663
+ return {
664
+ filteredMessages,
665
+ instructions,
666
+ sourceAgentName,
667
+ parallelSiblings,
668
+ };
652
669
  }
653
670
 
654
671
  /**
@@ -736,12 +753,16 @@ export class MultiAgentGraph extends StandardGraph {
736
753
  );
737
754
 
738
755
  if (handoffContext !== null) {
739
- const { filteredMessages, instructions, sourceAgentName } =
740
- handoffContext;
756
+ const {
757
+ filteredMessages,
758
+ instructions,
759
+ sourceAgentName,
760
+ parallelSiblings,
761
+ } = handoffContext;
741
762
 
742
763
  /**
743
764
  * Set handoff context on the receiving agent.
744
- * This updates the system message to include agent identity info.
765
+ * Uses pre-computed graph position for depth and parallel info.
745
766
  */
746
767
  const agentContext = this.agentContexts.get(agentId);
747
768
  if (
@@ -749,7 +770,7 @@ export class MultiAgentGraph extends StandardGraph {
749
770
  sourceAgentName != null &&
750
771
  sourceAgentName !== ''
751
772
  ) {
752
- agentContext.setHandoffContext(sourceAgentName);
773
+ agentContext.setHandoffContext(sourceAgentName, parallelSiblings);
753
774
  }
754
775
 
755
776
  /** Build messages for the receiving agent */
@@ -346,11 +346,29 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
346
346
  * This enables LLM-initiated parallel execution when calling multiple
347
347
  * transfer tools simultaneously.
348
348
  */
349
- const sends = handoffCommands.map((cmd) => {
350
- /** Extract destination - handle both string and array formats */
349
+
350
+ /** Collect all destinations for sibling tracking */
351
+ const allDestinations = handoffCommands.map((cmd) => {
351
352
  const goto = cmd.goto;
352
- const destination =
353
- typeof goto === 'string' ? goto : (goto as string[])[0];
353
+ return typeof goto === 'string' ? goto : (goto as string[])[0];
354
+ });
355
+
356
+ const sends = handoffCommands.map((cmd, idx) => {
357
+ const destination = allDestinations[idx];
358
+ /** Get siblings (other destinations, not this one) */
359
+ const siblings = allDestinations.filter((d) => d !== destination);
360
+
361
+ /** Add siblings to ToolMessage additional_kwargs */
362
+ const update = cmd.update as { messages?: BaseMessage[] } | undefined;
363
+ if (update && update.messages) {
364
+ for (const msg of update.messages) {
365
+ if (msg.getType() === 'tool') {
366
+ (msg as ToolMessage).additional_kwargs.handoff_parallel_siblings =
367
+ siblings;
368
+ }
369
+ }
370
+ }
371
+
354
372
  return new Send(destination, cmd.update);
355
373
  });
356
374