@librechat/agents 3.9.2 → 3.9.3

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.
Files changed (43) hide show
  1. package/dist/cjs/graphs/Graph.cjs +13 -4
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/graphs/MultiAgentGraph.cjs +97 -5
  4. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  5. package/dist/cjs/graphs/handoff.cjs +195 -0
  6. package/dist/cjs/graphs/handoff.cjs.map +1 -0
  7. package/dist/cjs/graphs/index.cjs +1 -0
  8. package/dist/cjs/main.cjs +2 -0
  9. package/dist/cjs/run.cjs +33 -3
  10. package/dist/cjs/run.cjs.map +1 -1
  11. package/dist/cjs/tools/ToolNode.cjs +4 -1
  12. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  13. package/dist/esm/graphs/Graph.mjs +13 -4
  14. package/dist/esm/graphs/Graph.mjs.map +1 -1
  15. package/dist/esm/graphs/MultiAgentGraph.mjs +97 -5
  16. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  17. package/dist/esm/graphs/handoff.mjs +193 -0
  18. package/dist/esm/graphs/handoff.mjs.map +1 -0
  19. package/dist/esm/graphs/index.mjs +1 -0
  20. package/dist/esm/main.mjs +2 -1
  21. package/dist/esm/run.mjs +33 -3
  22. package/dist/esm/run.mjs.map +1 -1
  23. package/dist/esm/tools/ToolNode.mjs +4 -1
  24. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  25. package/dist/types/graphs/Graph.d.ts +2 -0
  26. package/dist/types/graphs/MultiAgentGraph.d.ts +3 -0
  27. package/dist/types/graphs/handoff.d.ts +28 -0
  28. package/dist/types/graphs/index.d.ts +1 -0
  29. package/dist/types/run.d.ts +4 -0
  30. package/dist/types/tools/ToolNode.d.ts +2 -1
  31. package/dist/types/types/graph.d.ts +46 -1
  32. package/dist/types/types/run.d.ts +3 -1
  33. package/dist/types/types/tools.d.ts +3 -0
  34. package/package.json +1 -1
  35. package/src/graphs/Graph.ts +8 -0
  36. package/src/graphs/MultiAgentGraph.ts +142 -4
  37. package/src/graphs/handoff.ts +263 -0
  38. package/src/graphs/index.ts +2 -0
  39. package/src/run.ts +54 -2
  40. package/src/tools/ToolNode.ts +14 -6
  41. package/src/types/graph.ts +44 -1
  42. package/src/types/run.ts +3 -1
  43. package/src/types/tools.ts +3 -0
@@ -78,9 +78,45 @@ export type SystemCallbacks = {
78
78
  : never;
79
79
  };
80
80
 
81
+ /** An executed, SDK-generated handoff, identified independently of stream events. */
82
+ export interface HandoffTransition {
83
+ id: string;
84
+ sourceAgentId: string;
85
+ targetAgentId: string;
86
+ toolCallId: string;
87
+ scope: 'turn' | 'conversation';
88
+ /** Causal order: number of handoffs visible at this batch's input. */
89
+ depth: number;
90
+ }
91
+
92
+ /** Versioned graph checkpoint payload, scoped to one logical user turn. */
93
+ export interface HandoffState {
94
+ version: 1;
95
+ executionId: string;
96
+ entryAgentId: string;
97
+ maxHandoffs?: number;
98
+ transitions: HandoffTransition[];
99
+ parallel: boolean;
100
+ /** False when resuming an older checkpoint without complete routing provenance. */
101
+ historyComplete?: boolean;
102
+ }
103
+
104
+ /** Only a candidate from a completed top-level run may be promoted by a host. */
105
+ export type HandoffOutcome = {
106
+ executionId: string;
107
+ entryAgentId: string;
108
+ transitions: readonly HandoffTransition[];
109
+ } & (
110
+ | { status: 'candidate'; agentId: string; transitionId: string }
111
+ | { status: 'unchanged' | 'ambiguous' }
112
+ | { status: 'incomplete'; reason: string }
113
+ );
114
+
81
115
  export type BaseGraphState = {
82
116
  messages: BaseMessage[];
83
117
  runStepState?: RunStepResumeState;
118
+ /** SDK-owned routing state; hosts must not synthesize it from messages. */
119
+ handoffState?: HandoffState;
84
120
  /**
85
121
  * The summary a summarize-only run produced. Kept in state because such a
86
122
  * run has no assistant reply: trace roots report it as the run's output
@@ -434,6 +470,8 @@ export type GraphEdge = {
434
470
  condition?: (state: BaseGraphState) => boolean | string | string[];
435
471
  /** 'handoff' creates tools for dynamic routing, 'direct' creates direct edges, which also allow parallel execution */
436
472
  edgeType?: 'handoff' | 'direct';
473
+ /** Host may promote the destination after successful top-level completion. */
474
+ handoffScope?: 'turn' | 'conversation';
437
475
  /**
438
476
  * For direct edges: Optional prompt to add when transitioning through this edge.
439
477
  * String prompts can include variables like {results} which will be replaced with
@@ -463,15 +501,20 @@ export type GraphEdge = {
463
501
 
464
502
  export type GraphSubagentEdge = Omit<
465
503
  GraphEdge,
466
- 'edgeType' | 'condition' | 'promptKey'
504
+ 'edgeType' | 'condition' | 'promptKey' | 'handoffScope'
467
505
  > & {
468
506
  edgeType: 'direct';
469
507
  condition?: never;
470
508
  promptKey?: never;
509
+ handoffScope?: never;
471
510
  };
472
511
 
473
512
  export type MultiAgentGraphInput = StandardGraphInput & {
474
513
  edges: GraphEdge[];
514
+ /** Explicit fresh-turn entry; absent preserves topology-inferred entry points. */
515
+ entryAgentId?: string;
516
+ /** Shared logical-turn handoff cap. Zero forbids handoffs; absent uses only recursion limits. */
517
+ maxHandoffs?: number;
475
518
  /** Captures the designated member's final AI turn in graph state. */
476
519
  resultAgentId?: string;
477
520
  /** Optional per-member Pregel budget when the outer graph has its own topology budget. */
package/src/types/run.ts CHANGED
@@ -115,11 +115,13 @@ export type MultiAgentGraphConfig = {
115
115
  compileOptions?: g.CompileOptions;
116
116
  agents: g.AgentInputs[];
117
117
  edges: g.GraphEdge[];
118
+ entryAgentId?: string;
119
+ maxHandoffs?: number;
118
120
  };
119
121
 
120
122
  export type StandardGraphConfig = Omit<
121
123
  MultiAgentGraphConfig,
122
- 'edges' | 'type'
124
+ 'edges' | 'type' | 'entryAgentId' | 'maxHandoffs'
123
125
  > & { type?: 'standard'; signal?: AbortSignal };
124
126
 
125
127
  /**
@@ -14,6 +14,7 @@ import type { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
14
14
  import type { LangfuseConfig, SubagentExecutionContext } from './graph';
15
15
  import type { PreparedSubagents } from '@/tools/preparedSubagents';
16
16
  import type { RunBreakerScope } from '@/llm/streamLimits';
17
+ import type { HandoffRouting } from '@/graphs/handoff';
17
18
  import type { HumanInTheLoopConfig } from './hitl';
18
19
  import type { HookRegistry } from '@/hooks';
19
20
 
@@ -117,6 +118,8 @@ export type EagerEventToolCallChunkState = {
117
118
  };
118
119
 
119
120
  export type ToolNodeOptions = {
121
+ /** @internal Admission shared by tool nodes belonging to one multi-agent graph. */
122
+ handoffRouting?: Pick<HandoffRouting, 'finalize'>;
120
123
  name?: string;
121
124
  tags?: string[];
122
125
  /** Enables LangChain/LangGraph tracing for this ToolNode. Defaults to false. */