@illuma-ai/agents 1.1.22 → 1.1.24

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.
@@ -550,6 +550,20 @@ class MultiAgentGraph extends StandardGraph {
550
550
  console.debug(`[MultiAgentGraph] Handoff "${sourceAgentId}" -> "${destination}" START ` +
551
551
  `(messages: ${childMessages.length})`);
552
552
  try {
553
+ /**
554
+ * Dispatch transition BEFORE invoking the child subgraph so that
555
+ * callbacks.js sets multiAgentTrace.isMultiAgent = true before the
556
+ * child's ON_RUN_STEP events fire. This ensures child tool calls
557
+ * are attributed to the correct agent in admin traces.
558
+ */
559
+ await safeDispatchCustomEvent(GraphEvents.ON_AGENT_TRANSITION, {
560
+ sourceAgentId: sourceAgentId,
561
+ sourceAgentName: this.agentContexts.get(sourceAgentId)?.name ?? sourceAgentId,
562
+ destinationAgentId: destination,
563
+ destinationAgentName: destContext?.name ?? destination,
564
+ edgeType: EdgeType.HANDOFF,
565
+ timestamp: Date.now(),
566
+ }, config);
553
567
  /**
554
568
  * Invoke the child subgraph with config propagation.
555
569
  * Config carries callbacks (for SSE streaming), abort signal,
@@ -561,14 +575,6 @@ class MultiAgentGraph extends StandardGraph {
561
575
  console.debug(`[MultiAgentGraph] Handoff "${sourceAgentId}" -> "${destination}" DONE ` +
562
576
  `(result: ${resultText.length} chars` +
563
577
  `${truncatedResult.length < resultText.length ? `, truncated to ${truncatedResult.length}` : ''})`);
564
- await safeDispatchCustomEvent(GraphEvents.ON_AGENT_TRANSITION, {
565
- sourceAgentId: sourceAgentId,
566
- sourceAgentName: this.agentContexts.get(sourceAgentId)?.name ?? sourceAgentId,
567
- destinationAgentId: destination,
568
- destinationAgentName: destContext?.name ?? destination,
569
- edgeType: EdgeType.HANDOFF,
570
- timestamp: Date.now(),
571
- }, config);
572
578
  return truncatedResult;
573
579
  }
574
580
  catch (err) {
@@ -764,6 +770,26 @@ class MultiAgentGraph extends StandardGraph {
764
770
  }));
765
771
  }
766
772
  }
773
+ /**
774
+ * Ensure messages end with a HumanMessage.
775
+ * After stripping tool artifacts, the last message may be an AIMessage
776
+ * (orchestrator's reasoning before the handoff). Some providers (Bedrock,
777
+ * Google/VertexAI) reject conversations ending with an assistant message.
778
+ * Convert the trailing AIMessage to a HumanMessage to preserve any useful
779
+ * context (e.g., compacted tool summaries) while satisfying the API requirement.
780
+ */
781
+ if (cleaned.length > 0 && cleaned[cleaned.length - 1].getType() === 'ai') {
782
+ const lastAI = cleaned[cleaned.length - 1];
783
+ const content = typeof lastAI.content === 'string'
784
+ ? lastAI.content
785
+ : '';
786
+ if (content.trim()) {
787
+ cleaned[cleaned.length - 1] = new HumanMessage(`[Context from orchestrator]: ${content}`);
788
+ }
789
+ else {
790
+ cleaned.pop();
791
+ }
792
+ }
767
793
  return cleaned;
768
794
  }
769
795
  processTransferReception(messages, agentId) {