@librechat/agents 3.4.3 → 3.4.4

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 (75) hide show
  1. package/dist/cjs/graphs/Graph.cjs +27 -14
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/graphs/MultiAgentGraph.cjs +1 -1
  4. package/dist/cjs/instrumentation.cjs +3 -3
  5. package/dist/cjs/langfuse.cjs +3 -3
  6. package/dist/cjs/langfuseRuntimeScope.cjs +1 -1
  7. package/dist/cjs/langfuseToolOutputTracing.cjs +2 -2
  8. package/dist/cjs/main.cjs +5 -1
  9. package/dist/cjs/messages/assistantPhase.cjs +59 -0
  10. package/dist/cjs/messages/assistantPhase.cjs.map +1 -0
  11. package/dist/cjs/messages/index.cjs +1 -0
  12. package/dist/cjs/prompts/activityLabel.cjs +76 -0
  13. package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
  14. package/dist/cjs/run.cjs +200 -10
  15. package/dist/cjs/run.cjs.map +1 -1
  16. package/dist/cjs/session/AgentSession.cjs +1 -1
  17. package/dist/cjs/stream.cjs +45 -8
  18. package/dist/cjs/stream.cjs.map +1 -1
  19. package/dist/cjs/tools/ToolNode.cjs +3 -3
  20. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +81 -6
  21. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  22. package/dist/cjs/utils/callbacks.cjs +8 -0
  23. package/dist/cjs/utils/callbacks.cjs.map +1 -1
  24. package/dist/esm/graphs/Graph.mjs +27 -14
  25. package/dist/esm/graphs/Graph.mjs.map +1 -1
  26. package/dist/esm/graphs/MultiAgentGraph.mjs +1 -1
  27. package/dist/esm/instrumentation.mjs +3 -3
  28. package/dist/esm/langfuse.mjs +3 -3
  29. package/dist/esm/langfuseRuntimeScope.mjs +1 -1
  30. package/dist/esm/langfuseToolOutputTracing.mjs +2 -2
  31. package/dist/esm/main.mjs +3 -2
  32. package/dist/esm/messages/assistantPhase.mjs +57 -0
  33. package/dist/esm/messages/assistantPhase.mjs.map +1 -0
  34. package/dist/esm/messages/index.mjs +1 -0
  35. package/dist/esm/prompts/activityLabel.mjs +74 -1
  36. package/dist/esm/prompts/activityLabel.mjs.map +1 -1
  37. package/dist/esm/run.mjs +202 -12
  38. package/dist/esm/run.mjs.map +1 -1
  39. package/dist/esm/session/AgentSession.mjs +1 -1
  40. package/dist/esm/stream.mjs +45 -8
  41. package/dist/esm/stream.mjs.map +1 -1
  42. package/dist/esm/tools/ToolNode.mjs +3 -3
  43. package/dist/esm/tools/subagent/SubagentExecutor.mjs +81 -6
  44. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  45. package/dist/esm/utils/callbacks.mjs +8 -1
  46. package/dist/esm/utils/callbacks.mjs.map +1 -1
  47. package/dist/types/messages/assistantPhase.d.ts +22 -0
  48. package/dist/types/messages/index.d.ts +1 -0
  49. package/dist/types/prompts/activityLabel.d.ts +21 -1
  50. package/dist/types/run.d.ts +15 -2
  51. package/dist/types/types/activityLabel.d.ts +63 -0
  52. package/dist/types/types/assistantPhase.d.ts +6 -0
  53. package/dist/types/types/graph.d.ts +8 -1
  54. package/dist/types/types/index.d.ts +1 -0
  55. package/dist/types/types/stream.d.ts +11 -0
  56. package/dist/types/utils/callbacks.d.ts +1 -0
  57. package/package.json +1 -1
  58. package/src/graphs/Graph.ts +33 -9
  59. package/src/graphs/__tests__/Graph.reasoning.test.ts +57 -0
  60. package/src/messages/assistantPhase.test.ts +75 -0
  61. package/src/messages/assistantPhase.ts +91 -0
  62. package/src/messages/index.ts +1 -0
  63. package/src/prompts/activityLabel.ts +177 -1
  64. package/src/run.ts +403 -21
  65. package/src/specs/activity-label-prompt.test.ts +123 -1
  66. package/src/specs/activity-phase-label.test.ts +306 -0
  67. package/src/stream.ts +69 -12
  68. package/src/tools/__tests__/SubagentExecutor.test.ts +436 -0
  69. package/src/tools/subagent/SubagentExecutor.ts +160 -8
  70. package/src/types/activityLabel.ts +65 -0
  71. package/src/types/assistantPhase.ts +6 -0
  72. package/src/types/graph.ts +8 -0
  73. package/src/types/index.ts +1 -0
  74. package/src/types/stream.ts +9 -0
  75. package/src/utils/callbacks.ts +21 -0
@@ -1,4 +1,5 @@
1
1
  import type { RunnableConfig } from '@langchain/core/runnables';
2
+ import type { AssistantTextPhase } from '@/types/assistantPhase';
2
3
  import type { ClientOptions } from '@/types/llm';
3
4
  import type { Providers } from '@/common';
4
5
 
@@ -38,6 +39,11 @@ export type RunActivityLabelOptions = {
38
39
  thinkingExcerpts?: string[];
39
40
  /** Assistant's last text before the block (~200 chars), as intent context. */
40
41
  lastAssistantText?: string;
42
+ /**
43
+ * Provider-authored semantic phase for `lastAssistantText`. Hosts can use
44
+ * this to pass commentary as intent while excluding final-answer text.
45
+ */
46
+ lastAssistantPhase?: AssistantTextPhase;
41
47
  /**
42
48
  * Headers already committed for earlier batches in this run (run order,
43
49
  * most recent last). Continuity context: the prompt shows them so the new
@@ -61,3 +67,62 @@ export type RunActivityLabelOptions = {
61
67
  */
62
68
  traceSeed?: string;
63
69
  };
70
+
71
+ /** One logical activity contributing to a run-wide phase summary. */
72
+ export type ActivityPhaseEntry = {
73
+ /** Already committed child activity label, preferred over raw evidence. */
74
+ label?: string;
75
+ /** Raw fallback for a child label that was disabled, pending, or dropped. */
76
+ entries?: ActivityLabelToolEntry[];
77
+ /** Standalone or tool-attached reasoning excerpts for this activity. */
78
+ thinkingExcerpts?: string[];
79
+ /** Agent lane that produced the activity. */
80
+ agentId?: string;
81
+ /** Failed activities remain useful evidence and still count. */
82
+ status?: 'success' | 'partial' | 'error';
83
+ };
84
+
85
+ /** Options for `Run.generateActivityPhaseLabel`. */
86
+ export type RunActivityPhaseLabelOptions = {
87
+ provider: Providers;
88
+ clientOptions?: ClientOptions;
89
+ /**
90
+ * Logical activities in run order. The SDK requires at least two so hosts
91
+ * cannot accidentally spend a model call summarizing a single activity.
92
+ */
93
+ activities: ActivityPhaseEntry[];
94
+ /** Full count when the host retained only bounded prompt evidence. */
95
+ totalActivityCount?: number;
96
+ /**
97
+ * Bounded assistant commentary emitted inside the phase. Human messages
98
+ * must not be supplied through this low-scrutiny summarization path.
99
+ */
100
+ assistantContext?: string[];
101
+ /** Semantic phase of the text boundary that closed the activity phase. */
102
+ closingTextPhase?: AssistantTextPhase;
103
+ /** Override for the dedicated phase-label system prompt. */
104
+ prompt?: string;
105
+ /** Per-evidence serialization cap for the prompt. Default 600. */
106
+ charLimit?: number;
107
+ /** LangChain runnable config carrier (signal, callbacks, thread/user ids). */
108
+ chainOptions?: Partial<RunnableConfig> & {
109
+ configurable?: Record<string, unknown>;
110
+ };
111
+ /** Deterministic seed for this phase label trace. */
112
+ traceSeed?: string;
113
+ /** Stable source run identifier recorded on the phase observation. */
114
+ sourceRunId?: string;
115
+ /** Source Langfuse trace id for linking this detached summary trace. */
116
+ sourceTraceId?: string;
117
+ /** Host response/message identifier recorded on the phase observation. */
118
+ responseId?: string;
119
+ /** Zero-based index of the phase within the source run. */
120
+ phaseIndex?: number;
121
+ /** Completion state recorded on the phase observation. */
122
+ status?: 'completed' | 'partial' | 'failed';
123
+ /**
124
+ * Contributing agents. Their Langfuse redaction policies are combined into
125
+ * the strictest union before any phase evidence enters the model or trace.
126
+ */
127
+ agentIds?: string[];
128
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Semantic phase attached to assistant text by Open Responses-compatible
3
+ * providers. Commentary is intermediate agent narration; final_answer marks
4
+ * the user-facing answer that closes the preceding activity phase.
5
+ */
6
+ export type AssistantTextPhase = 'commentary' | 'final_answer';
@@ -19,6 +19,7 @@ import type {
19
19
  } from '@/types/summarize';
20
20
  import type {
21
21
  ToolMap,
22
+ ToolSessionMap,
22
23
  ToolEndEvent,
23
24
  GenericTool,
24
25
  LCTool,
@@ -848,6 +849,13 @@ export interface AgentInputs {
848
849
  subagentConfigs?: SubagentConfigEntry[];
849
850
  /** Maximum subagent nesting depth. Default 1 means top-level agents can spawn subagents but subagents cannot nest further. */
850
851
  maxSubagentDepth?: number;
852
+ /**
853
+ * Initial tool-session state owned by this agent when it runs as a
854
+ * subagent. The executor copies these sessions into the isolated child
855
+ * graph before its first invocation. Top-level runs continue to use
856
+ * `RunConfig.initialSessions`.
857
+ */
858
+ initialSessions?: ToolSessionMap;
851
859
  /**
852
860
  * Host-supplied tool instances that must execute IN-PROCESS inside the graph's
853
861
  * ToolNode even when the run is event-driven (`toolDefinitions` non-empty). Each
@@ -9,3 +9,4 @@ export * from './stream';
9
9
  export * from './tools';
10
10
  export * from './summarize';
11
11
  export * from './activityLabel';
12
+ export * from './assistantPhase';
@@ -9,6 +9,7 @@ import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
9
9
  import type { LLMResult, Generation } from '@langchain/core/outputs';
10
10
  import type { Command } from '@langchain/langgraph';
11
11
  import type { AnthropicContentBlock } from '@/llm/anthropic/types';
12
+ import type { AssistantTextPhase } from '@/types/assistantPhase';
12
13
  import type { SummarizeCompleteEvent } from '@/types/summarize';
13
14
  import type { ToolEndEvent } from '@/types/tools';
14
15
  import { StepTypes, ContentTypes, GraphEvents } from '@/common/enum';
@@ -119,6 +120,10 @@ export type MessageCreationDetails = {
119
120
  type: StepTypes.MESSAGE_CREATION;
120
121
  message_creation: {
121
122
  message_id: string;
123
+ /** Content lane announced before its first delta. */
124
+ content_type?: ContentTypes.TEXT | ContentTypes.THINK;
125
+ /** Provider-authored assistant text phase, when available. */
126
+ phase?: AssistantTextPhase;
122
127
  };
123
128
  };
124
129
 
@@ -415,6 +420,10 @@ export type MessageContentComplex = (
415
420
  type?: never;
416
421
  })
417
422
  ) & {
423
+ /** Open Responses-compatible semantic phase for assistant text. */
424
+ phase?: AssistantTextPhase;
425
+ /** LangChain standard-content form of provider-specific block fields. */
426
+ extras?: { phase?: AssistantTextPhase } & Record<string, unknown>;
418
427
  tool_call_ids?: string[];
419
428
  // Optional agentId for parallel execution attribution
420
429
  agentId?: string;
@@ -37,3 +37,24 @@ export function findCallback(
37
37
  const handlers = Array.isArray(callbacks) ? callbacks : callbacks.handlers;
38
38
  return handlers.find(predicate);
39
39
  }
40
+
41
+ export function filterCallbacks(
42
+ callbacks: Callbacks | undefined,
43
+ predicate: (callback: CallbackEntry) => boolean
44
+ ): Callbacks {
45
+ if (callbacks == null) {
46
+ return [];
47
+ }
48
+
49
+ if (Array.isArray(callbacks)) {
50
+ return callbacks.filter(predicate);
51
+ }
52
+
53
+ const filtered = callbacks.copy();
54
+ for (const handler of [...filtered.handlers]) {
55
+ if (!predicate(handler)) {
56
+ filtered.removeHandler(handler);
57
+ }
58
+ }
59
+ return filtered;
60
+ }