@librechat/agents 3.1.86 → 3.1.88

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 (160) hide show
  1. package/README.md +69 -0
  2. package/dist/cjs/events.cjs +23 -0
  3. package/dist/cjs/events.cjs.map +1 -1
  4. package/dist/cjs/graphs/Graph.cjs +133 -18
  5. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  6. package/dist/cjs/graphs/MultiAgentGraph.cjs +1 -1
  7. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  8. package/dist/cjs/llm/anthropic/index.cjs +251 -53
  9. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  10. package/dist/cjs/llm/init.cjs +1 -5
  11. package/dist/cjs/llm/init.cjs.map +1 -1
  12. package/dist/cjs/llm/openai/index.cjs +113 -24
  13. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  14. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  15. package/dist/cjs/llm/openrouter/index.cjs +3 -1
  16. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  17. package/dist/cjs/main.cjs +18 -5
  18. package/dist/cjs/main.cjs.map +1 -1
  19. package/dist/cjs/openai/index.cjs +253 -0
  20. package/dist/cjs/openai/index.cjs.map +1 -0
  21. package/dist/cjs/responses/index.cjs +448 -0
  22. package/dist/cjs/responses/index.cjs.map +1 -0
  23. package/dist/cjs/run.cjs +108 -7
  24. package/dist/cjs/run.cjs.map +1 -1
  25. package/dist/cjs/session/AgentSession.cjs +1057 -0
  26. package/dist/cjs/session/AgentSession.cjs.map +1 -0
  27. package/dist/cjs/session/JsonlSessionStore.cjs +425 -0
  28. package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -0
  29. package/dist/cjs/session/handlers.cjs +221 -0
  30. package/dist/cjs/session/handlers.cjs.map +1 -0
  31. package/dist/cjs/session/ids.cjs +22 -0
  32. package/dist/cjs/session/ids.cjs.map +1 -0
  33. package/dist/cjs/session/messageSerialization.cjs +179 -0
  34. package/dist/cjs/session/messageSerialization.cjs.map +1 -0
  35. package/dist/cjs/stream.cjs +475 -11
  36. package/dist/cjs/stream.cjs.map +1 -1
  37. package/dist/cjs/summarization/node.cjs +1 -1
  38. package/dist/cjs/summarization/node.cjs.map +1 -1
  39. package/dist/cjs/tools/ToolNode.cjs +177 -59
  40. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  41. package/dist/cjs/tools/eagerEventExecution.cjs +113 -0
  42. package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -0
  43. package/dist/cjs/tools/handlers.cjs +1 -1
  44. package/dist/cjs/tools/handlers.cjs.map +1 -1
  45. package/dist/cjs/tools/streamedToolCallSeals.cjs +42 -0
  46. package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -0
  47. package/dist/esm/events.mjs +23 -1
  48. package/dist/esm/events.mjs.map +1 -1
  49. package/dist/esm/graphs/Graph.mjs +133 -18
  50. package/dist/esm/graphs/Graph.mjs.map +1 -1
  51. package/dist/esm/graphs/MultiAgentGraph.mjs +1 -1
  52. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  53. package/dist/esm/llm/anthropic/index.mjs +251 -53
  54. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  55. package/dist/esm/llm/init.mjs +1 -5
  56. package/dist/esm/llm/init.mjs.map +1 -1
  57. package/dist/esm/llm/openai/index.mjs +113 -25
  58. package/dist/esm/llm/openai/index.mjs.map +1 -1
  59. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  60. package/dist/esm/llm/openrouter/index.mjs +4 -2
  61. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  62. package/dist/esm/main.mjs +5 -1
  63. package/dist/esm/main.mjs.map +1 -1
  64. package/dist/esm/openai/index.mjs +246 -0
  65. package/dist/esm/openai/index.mjs.map +1 -0
  66. package/dist/esm/responses/index.mjs +440 -0
  67. package/dist/esm/responses/index.mjs.map +1 -0
  68. package/dist/esm/run.mjs +108 -7
  69. package/dist/esm/run.mjs.map +1 -1
  70. package/dist/esm/session/AgentSession.mjs +1054 -0
  71. package/dist/esm/session/AgentSession.mjs.map +1 -0
  72. package/dist/esm/session/JsonlSessionStore.mjs +422 -0
  73. package/dist/esm/session/JsonlSessionStore.mjs.map +1 -0
  74. package/dist/esm/session/handlers.mjs +219 -0
  75. package/dist/esm/session/handlers.mjs.map +1 -0
  76. package/dist/esm/session/ids.mjs +17 -0
  77. package/dist/esm/session/ids.mjs.map +1 -0
  78. package/dist/esm/session/messageSerialization.mjs +173 -0
  79. package/dist/esm/session/messageSerialization.mjs.map +1 -0
  80. package/dist/esm/stream.mjs +476 -12
  81. package/dist/esm/stream.mjs.map +1 -1
  82. package/dist/esm/summarization/node.mjs +1 -1
  83. package/dist/esm/summarization/node.mjs.map +1 -1
  84. package/dist/esm/tools/ToolNode.mjs +177 -59
  85. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  86. package/dist/esm/tools/eagerEventExecution.mjs +107 -0
  87. package/dist/esm/tools/eagerEventExecution.mjs.map +1 -0
  88. package/dist/esm/tools/handlers.mjs +1 -1
  89. package/dist/esm/tools/handlers.mjs.map +1 -1
  90. package/dist/esm/tools/streamedToolCallSeals.mjs +36 -0
  91. package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -0
  92. package/dist/types/events.d.ts +1 -0
  93. package/dist/types/graphs/Graph.d.ts +24 -9
  94. package/dist/types/index.d.ts +1 -0
  95. package/dist/types/llm/openai/index.d.ts +1 -0
  96. package/dist/types/openai/index.d.ts +75 -0
  97. package/dist/types/responses/index.d.ts +97 -0
  98. package/dist/types/run.d.ts +2 -0
  99. package/dist/types/session/AgentSession.d.ts +32 -0
  100. package/dist/types/session/JsonlSessionStore.d.ts +67 -0
  101. package/dist/types/session/handlers.d.ts +8 -0
  102. package/dist/types/session/ids.d.ts +4 -0
  103. package/dist/types/session/index.d.ts +5 -0
  104. package/dist/types/session/messageSerialization.d.ts +7 -0
  105. package/dist/types/session/types.d.ts +191 -0
  106. package/dist/types/tools/ToolNode.d.ts +12 -1
  107. package/dist/types/tools/eagerEventExecution.d.ts +23 -0
  108. package/dist/types/tools/streamedToolCallSeals.d.ts +13 -0
  109. package/dist/types/types/hitl.d.ts +4 -0
  110. package/dist/types/types/run.d.ts +11 -1
  111. package/dist/types/types/tools.d.ts +36 -0
  112. package/package.json +19 -2
  113. package/src/__tests__/stream.eagerEventExecution.test.ts +2571 -0
  114. package/src/events.ts +29 -0
  115. package/src/graphs/Graph.ts +224 -50
  116. package/src/graphs/MultiAgentGraph.ts +1 -1
  117. package/src/graphs/__tests__/composition.smoke.test.ts +30 -0
  118. package/src/index.ts +3 -0
  119. package/src/llm/anthropic/index.ts +356 -84
  120. package/src/llm/anthropic/llm.spec.ts +64 -0
  121. package/src/llm/custom-chat-models.smoke.test.ts +175 -4
  122. package/src/llm/openai/contentBlocks.test.ts +35 -0
  123. package/src/llm/openai/deepseek.test.ts +201 -2
  124. package/src/llm/openai/index.ts +171 -26
  125. package/src/llm/openai/utils/index.ts +22 -0
  126. package/src/llm/openrouter/index.ts +4 -2
  127. package/src/openai/__tests__/openai.test.ts +337 -0
  128. package/src/openai/index.ts +404 -0
  129. package/src/responses/__tests__/responses.test.ts +652 -0
  130. package/src/responses/index.ts +677 -0
  131. package/src/run.ts +158 -8
  132. package/src/scripts/compare_pi_vs_ours.ts +592 -173
  133. package/src/scripts/session_live.ts +548 -0
  134. package/src/session/AgentSession.ts +1432 -0
  135. package/src/session/JsonlSessionStore.ts +572 -0
  136. package/src/session/__tests__/JsonlSessionStore.test.ts +1410 -0
  137. package/src/session/__tests__/handlers.test.ts +161 -0
  138. package/src/session/handlers.ts +272 -0
  139. package/src/session/ids.ts +17 -0
  140. package/src/session/index.ts +44 -0
  141. package/src/session/messageSerialization.ts +207 -0
  142. package/src/session/types.ts +275 -0
  143. package/src/specs/custom-event-await.test.ts +89 -0
  144. package/src/specs/summarization.test.ts +1 -1
  145. package/src/stream.ts +756 -48
  146. package/src/summarization/node.ts +1 -1
  147. package/src/tools/ToolNode.ts +299 -126
  148. package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +373 -0
  149. package/src/tools/__tests__/handlers.test.ts +2 -1
  150. package/src/tools/__tests__/hitl.test.ts +206 -110
  151. package/src/tools/eagerEventExecution.ts +153 -0
  152. package/src/tools/handlers.ts +8 -4
  153. package/src/tools/streamedToolCallSeals.ts +57 -0
  154. package/src/types/hitl.ts +4 -0
  155. package/src/types/run.ts +11 -0
  156. package/src/types/tools.ts +36 -0
  157. package/dist/cjs/llm/text.cjs +0 -69
  158. package/dist/cjs/llm/text.cjs.map +0 -1
  159. package/dist/esm/llm/text.mjs +0 -67
  160. package/dist/esm/llm/text.mjs.map +0 -1
@@ -0,0 +1,67 @@
1
+ import type { CreateSessionFileOptions, SessionBranchOptions, SessionEntry, SessionForkOptions, SessionHeader, SessionLabelEntry, SessionListItem, SessionMessageEntry, SessionCheckpointEntry, SessionCompactionEntry, SessionRunEventEntry, SessionSummaryEntry, SessionStateEntry, SessionTreeNode } from './types';
2
+ import type { BaseMessage } from '@langchain/core/messages';
3
+ export declare class JsonlSessionStore {
4
+ readonly path: string;
5
+ readonly header: SessionHeader;
6
+ private entries;
7
+ private constructor();
8
+ static getDefaultRoot(): string;
9
+ static create(options: CreateSessionFileOptions & {
10
+ path?: string;
11
+ }): Promise<JsonlSessionStore>;
12
+ static open(pathOrId: string): Promise<JsonlSessionStore>;
13
+ static openPath(path: string): Promise<JsonlSessionStore>;
14
+ static resolvePath(pathOrId: string): Promise<string>;
15
+ static list(cwd: string): Promise<SessionListItem[]>;
16
+ static listAll(root?: string): Promise<SessionListItem[]>;
17
+ private static listDirectory;
18
+ getEntries(): SessionEntry[];
19
+ getEntry(id: string): SessionEntry | undefined;
20
+ getChildren(id: string): SessionEntry[];
21
+ getTree(): SessionTreeNode[];
22
+ getLeafEntry(): SessionEntry | undefined;
23
+ getPath(entryId?: string | undefined): SessionEntry[];
24
+ getMessages(entryId?: string): BaseMessage[];
25
+ getForkPoints(): SessionMessageEntry[];
26
+ getLabel(entryId: string): string | undefined;
27
+ setLabel(entryId: string, label: string): Promise<SessionLabelEntry>;
28
+ appendMessage(message: BaseMessage, parentId?: string | null): Promise<SessionMessageEntry>;
29
+ appendRunEvent(event: string, payload?: unknown, params?: {
30
+ runId?: string;
31
+ threadId?: string;
32
+ }): Promise<SessionRunEventEntry>;
33
+ setLeaf(leafId: string | null): Promise<SessionStateEntry>;
34
+ appendEntryForCompaction(params: {
35
+ text: string;
36
+ tokenCount?: number;
37
+ retainedEntryIds: string[];
38
+ summarizedEntryIds: string[];
39
+ instructions?: string;
40
+ parentId?: string | null;
41
+ }): Promise<SessionSummaryEntry>;
42
+ appendCompactionEntry(params: {
43
+ summaryEntryId: string;
44
+ retainedEntryIds: string[];
45
+ summarizedEntryIds: string[];
46
+ }): Promise<SessionCompactionEntry>;
47
+ appendCheckpoint(params: {
48
+ source: SessionCheckpointEntry['data']['source'];
49
+ threadId: string;
50
+ runId?: string;
51
+ checkpointId?: string;
52
+ checkpointNs?: string;
53
+ parentCheckpointId?: string;
54
+ reason?: string;
55
+ }): Promise<SessionCheckpointEntry>;
56
+ getCheckpoints(threadId?: string): SessionCheckpointEntry[];
57
+ getLatestCheckpoint(threadId?: string): SessionCheckpointEntry | undefined;
58
+ branch(entryId: string, options?: SessionBranchOptions): Promise<SessionEntry | undefined>;
59
+ createBranchedSession(entryId?: string | undefined, options?: SessionForkOptions): Promise<JsonlSessionStore>;
60
+ clone(options?: SessionForkOptions): Promise<JsonlSessionStore>;
61
+ fork(entryId: string, options?: SessionForkOptions): Promise<JsonlSessionStore>;
62
+ private getBranchTarget;
63
+ private appendExistingEntry;
64
+ private appendEntry;
65
+ existsOnDisk(): Promise<boolean>;
66
+ }
67
+ export declare const SessionManager: typeof JsonlSessionStore;
@@ -0,0 +1,8 @@
1
+ import type * as t from '@/types';
2
+ import type { AgentSessionHandlersResult, AgentSessionStreamEvent } from './types';
3
+ export declare function createRunHandlers(params: {
4
+ runId: string;
5
+ threadId: string;
6
+ userHandlers?: Record<string, t.EventHandler>;
7
+ onEvent?: (event: AgentSessionStreamEvent) => void;
8
+ }): AgentSessionHandlersResult;
@@ -0,0 +1,4 @@
1
+ export declare function createSessionId(): string;
2
+ export declare function createEntryId(): string;
3
+ export declare function createRunId(): string;
4
+ export declare function createTimestamp(): string;
@@ -0,0 +1,5 @@
1
+ export { AgentSession, createAgentSession } from './AgentSession';
2
+ export { JsonlSessionStore, SessionManager } from './JsonlSessionStore';
3
+ export { createRunHandlers } from './handlers';
4
+ export { serializeMessage, deserializeMessage, extractTextFromContent, } from './messageSerialization';
5
+ export type { AgentSessionConfig, AgentSessionCheckpointLookupOptions, AgentSessionCheckpointReference, AgentSessionCheckpointing, AgentSessionCheckpointingOptions, AgentSessionHandlersResult, AgentSessionInput, AgentSessionRunOptions, AgentSessionRunResult, AgentSessionStream, AgentSessionStreamEvent, AgentSessionUsage, CreateSessionFileOptions, JsonObject, JsonPrimitive, JsonValue, SerializedSessionMessage, SessionBranchOptions, SessionCompactOptions, SessionCheckpointEntry, SessionCompactionEntry, SessionEntry, SessionEntryBase, SessionEntryType, SessionForkOptions, SessionHeader, SessionLabelEntry, SessionListItem, SessionMessageEntry, SessionPosition, SessionRunEventEntry, SessionStateEntry, SessionSummaryEntry, SessionTreeNode, } from './types';
@@ -0,0 +1,7 @@
1
+ import { BaseMessage } from '@langchain/core/messages';
2
+ import type { JsonValue, SerializedSessionMessage } from './types';
3
+ export declare function toJsonValue(value: unknown): JsonValue;
4
+ export declare function serializeMessage(message: BaseMessage): SerializedSessionMessage;
5
+ export declare function deserializeMessage(serialized: SerializedSessionMessage): BaseMessage;
6
+ export declare function getMessageRole(message: BaseMessage): string;
7
+ export declare function extractTextFromContent(content: JsonValue): string;
@@ -0,0 +1,191 @@
1
+ import type { RunnableConfig } from '@langchain/core/runnables';
2
+ import type { BaseMessage } from '@langchain/core/messages';
3
+ import type { BaseCheckpointSaver } from '@langchain/langgraph';
4
+ import type * as t from '@/types';
5
+ export type JsonPrimitive = string | number | boolean | null;
6
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
7
+ [key: string]: JsonValue;
8
+ };
9
+ export type JsonObject = {
10
+ [key: string]: JsonValue;
11
+ };
12
+ export type SessionEntryType = 'message' | 'summary' | 'compaction' | 'checkpoint' | 'label' | 'run_event' | 'session_state';
13
+ export interface SessionHeader {
14
+ type: 'session';
15
+ version: 1;
16
+ id: string;
17
+ timestamp: string;
18
+ cwd: string;
19
+ name?: string;
20
+ parentSession?: string;
21
+ }
22
+ export interface SessionEntryBase<TType extends SessionEntryType, TData> {
23
+ type: TType;
24
+ id: string;
25
+ parentId: string | null;
26
+ timestamp: string;
27
+ data: TData;
28
+ }
29
+ export interface SerializedSessionMessage {
30
+ messageType: string;
31
+ content: JsonValue;
32
+ additionalKwargs?: JsonObject;
33
+ responseMetadata?: JsonObject;
34
+ id?: string;
35
+ name?: string;
36
+ toolCallId?: string;
37
+ toolCalls?: JsonValue;
38
+ usageMetadata?: JsonObject;
39
+ }
40
+ export type SessionMessageEntry = SessionEntryBase<'message', {
41
+ role: string;
42
+ message: SerializedSessionMessage;
43
+ }>;
44
+ export type SessionSummaryEntry = SessionEntryBase<'summary', {
45
+ text: string;
46
+ tokenCount?: number;
47
+ retainedEntryIds: JsonValue[];
48
+ summarizedEntryIds: JsonValue[];
49
+ instructions?: string;
50
+ }>;
51
+ export type SessionCompactionEntry = SessionEntryBase<'compaction', {
52
+ summaryEntryId: string;
53
+ retainedEntryIds: JsonValue[];
54
+ summarizedEntryIds: JsonValue[];
55
+ }>;
56
+ export type SessionCheckpointEntry = SessionEntryBase<'checkpoint', {
57
+ provider: 'langgraph';
58
+ source: 'run' | 'resume' | 'reset';
59
+ threadId: string;
60
+ runId?: string;
61
+ checkpointId?: string;
62
+ checkpointNs?: string;
63
+ parentCheckpointId?: string;
64
+ reason?: string;
65
+ }>;
66
+ export type SessionLabelEntry = SessionEntryBase<'label', {
67
+ targetEntryId: string;
68
+ label: string;
69
+ }>;
70
+ export type SessionRunEventEntry = SessionEntryBase<'run_event', {
71
+ event: string;
72
+ runId?: string;
73
+ threadId?: string;
74
+ payload?: JsonValue;
75
+ }>;
76
+ export type SessionStateEntry = SessionEntryBase<'session_state', {
77
+ leafId: string | null;
78
+ }>;
79
+ export type SessionEntry = SessionMessageEntry | SessionSummaryEntry | SessionCompactionEntry | SessionCheckpointEntry | SessionLabelEntry | SessionRunEventEntry | SessionStateEntry;
80
+ export interface SessionTreeNode {
81
+ entry: SessionEntry;
82
+ children: SessionTreeNode[];
83
+ }
84
+ export interface SessionListItem {
85
+ id: string;
86
+ path: string;
87
+ cwd: string;
88
+ timestamp: string;
89
+ name?: string;
90
+ leafId?: string | null;
91
+ }
92
+ export type SessionPosition = 'before' | 'at';
93
+ export interface SessionForkOptions {
94
+ position?: SessionPosition;
95
+ cwd?: string;
96
+ name?: string;
97
+ }
98
+ export interface SessionBranchOptions {
99
+ position?: SessionPosition;
100
+ summarizeAbandoned?: boolean | {
101
+ instructions?: string;
102
+ };
103
+ }
104
+ export interface SessionCompactOptions {
105
+ instructions?: string;
106
+ retainRecentTurns?: number;
107
+ }
108
+ export interface AgentSessionRunResult {
109
+ text: string;
110
+ content: t.MessageContentComplex[];
111
+ messages: BaseMessage[];
112
+ usage: AgentSessionUsage;
113
+ steps: t.RunStep[];
114
+ interrupt: t.RunInterruptResult | undefined;
115
+ haltedReason: string | undefined;
116
+ runId: string;
117
+ threadId: string;
118
+ }
119
+ export interface AgentSessionUsage {
120
+ inputTokens: number;
121
+ outputTokens: number;
122
+ totalTokens: number;
123
+ }
124
+ export interface AgentSessionCheckpointReference {
125
+ provider: 'langgraph';
126
+ threadId: string;
127
+ checkpointId?: string;
128
+ checkpointNs?: string;
129
+ parentCheckpointId?: string;
130
+ }
131
+ export interface AgentSessionCheckpointLookupOptions {
132
+ threadId?: string;
133
+ checkpointNs?: string;
134
+ config?: RunnableConfig;
135
+ }
136
+ export interface AgentSessionCheckpointingOptions {
137
+ enabled?: boolean;
138
+ checkpointer?: BaseCheckpointSaver;
139
+ }
140
+ export type AgentSessionCheckpointing = boolean | AgentSessionCheckpointingOptions;
141
+ export type AgentSessionInput = string | BaseMessage | BaseMessage[] | t.IState;
142
+ export interface AgentSessionRunOptions {
143
+ runId?: string;
144
+ threadId?: string;
145
+ config?: Partial<RunnableConfig> & {
146
+ version?: 'v1' | 'v2';
147
+ };
148
+ streamOptions?: t.EventStreamOptions;
149
+ }
150
+ export interface AgentSessionStreamEvent {
151
+ type: 'run.started' | 'message.delta' | 'reasoning.delta' | 'tool.started' | 'tool.delta' | 'tool.completed' | 'usage.updated' | 'run.completed' | 'run.failed' | 'run.interrupted' | 'run.halted';
152
+ sequence: number;
153
+ runId: string;
154
+ threadId: string;
155
+ timestamp: string;
156
+ data?: JsonValue;
157
+ }
158
+ export interface AgentSessionStream extends AsyncIterable<AgentSessionStreamEvent> {
159
+ toTextStream(): AsyncIterable<string>;
160
+ finalResult(): Promise<AgentSessionRunResult>;
161
+ }
162
+ export interface AgentSessionHandlersResult {
163
+ contentParts: Array<t.MessageContentComplex | undefined>;
164
+ steps: t.RunStep[];
165
+ usage: AgentSessionUsage;
166
+ events: AgentSessionStreamEvent[];
167
+ handlers: Record<string, t.EventHandler>;
168
+ }
169
+ export type AgentSessionConfig = {
170
+ runConfig: t.RunConfig;
171
+ cwd?: string;
172
+ sessionPath?: string;
173
+ sessionId?: string;
174
+ name?: string;
175
+ ephemeral?: boolean;
176
+ checkpointing?: AgentSessionCheckpointing;
177
+ } | ({
178
+ runId?: string;
179
+ cwd?: string;
180
+ sessionPath?: string;
181
+ sessionId?: string;
182
+ name?: string;
183
+ ephemeral?: boolean;
184
+ checkpointing?: AgentSessionCheckpointing;
185
+ } & Omit<t.RunConfig, 'runId'>);
186
+ export interface CreateSessionFileOptions {
187
+ cwd: string;
188
+ name?: string;
189
+ parentSession?: string;
190
+ sessionId?: string;
191
+ }
@@ -80,6 +80,12 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
80
80
  private sessions?;
81
81
  /** When true, dispatches ON_TOOL_EXECUTE events instead of invoking tools directly */
82
82
  private eventDrivenMode;
83
+ /** Opt-in stream-layer prestart config for event-driven tools. */
84
+ private eagerEventToolExecution?;
85
+ /** Shared per-run prestarted tool registry populated by ChatModelStreamHandler. */
86
+ private eagerEventToolExecutions?;
87
+ /** Shared per-run per-tool turn counter used by eager and normal event dispatch. */
88
+ private eagerEventToolUsageCount?;
83
89
  /** Agent ID for event-driven mode */
84
90
  private agentId?;
85
91
  /** Tool names that bypass event dispatch and execute directly (e.g., graph-managed handoff tools) */
@@ -123,7 +129,7 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
123
129
  * other's in-flight state.
124
130
  */
125
131
  private anonBatchCounter;
126
- constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, agentId, directToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, }: t.ToolNodeConstructorParams);
132
+ constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, eagerEventToolExecution, eagerEventToolExecutions, eagerEventToolUsageCount, agentId, directToolNames, maxContextTokens, maxToolResultChars, hookRegistry, humanInTheLoop, toolOutputReferences, toolOutputRegistry, toolExecution, fileCheckpointer, }: t.ToolNodeConstructorParams);
127
133
  /**
128
134
  * Returns the run-scoped tool output registry, or `undefined` when
129
135
  * the feature is disabled.
@@ -177,6 +183,8 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
177
183
  * @returns A ReadonlyMap where keys are tool names and values are their usage counts.
178
184
  */
179
185
  getToolUsageCounts(): ReadonlyMap<string, number>;
186
+ private recordToolUsageTurn;
187
+ private recordEventToolPlanningTurn;
180
188
  /**
181
189
  * Runs a single tool call with error handling.
182
190
  *
@@ -309,6 +317,9 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
309
317
  * ToolMessages (appended AFTER to respect provider ordering).
310
318
  */
311
319
  private dispatchToolEvents;
320
+ private canConsumeEagerEventExecution;
321
+ private takeMatchingEagerEventExecution;
322
+ private resolveEagerEventExecution;
312
323
  /**
313
324
  * Fires the `PostToolBatch` hook (if registered) and appends the
314
325
  * accumulated batch-level `additionalContext` strings to `injected`
@@ -0,0 +1,23 @@
1
+ import type * as t from '@/types';
2
+ export declare function coerceRecordArgs(args: unknown): Record<string, unknown> | undefined;
3
+ export declare function stableStringify(value: unknown): string;
4
+ export declare function recordArgsEqual(left: Record<string, unknown>, right: Record<string, unknown>): boolean;
5
+ export declare function normalizeError(error: unknown): Error;
6
+ export type ToolExecutionPlanCall = {
7
+ id?: string;
8
+ name: string;
9
+ args: unknown;
10
+ stepId?: string;
11
+ codeSessionContext?: t.ToolCallRequest['codeSessionContext'];
12
+ };
13
+ export type ToolExecutionRequestPlan = {
14
+ allRequests: t.ToolCallRequest[];
15
+ requests: t.ToolCallRequest[];
16
+ rejectedResults: t.ToolExecuteResult[];
17
+ };
18
+ export declare function buildToolExecutionRequestPlan(args: {
19
+ toolCalls: ToolExecutionPlanCall[];
20
+ usageCount: Map<string, number>;
21
+ invalidArgsBehavior?: 'abort' | 'error-result';
22
+ recordTurn?: (toolName: string, turn: number, callId: string) => void;
23
+ }): ToolExecutionRequestPlan | undefined;
@@ -0,0 +1,13 @@
1
+ export declare const STREAMED_TOOL_CALL_ADAPTER_METADATA_KEY = "lc_streamed_tool_call_adapter";
2
+ export declare const STREAMED_TOOL_CALL_SEAL_METADATA_KEY = "lc_streamed_tool_call_seal";
3
+ export declare const OPENAI_RESPONSES_STREAMED_TOOL_CALL_ADAPTER = "openai_responses";
4
+ export type StreamedToolCallAdapter = typeof OPENAI_RESPONSES_STREAMED_TOOL_CALL_ADAPTER;
5
+ export type StreamedToolCallSeal = {
6
+ kind: 'single';
7
+ id?: string;
8
+ index?: number;
9
+ } | {
10
+ kind: 'all';
11
+ };
12
+ export declare function getStreamedToolCallAdapter(metadata: Record<string, unknown> | undefined): StreamedToolCallAdapter | undefined;
13
+ export declare function getStreamedToolCallSeal(metadata: Record<string, unknown> | undefined): StreamedToolCallSeal | undefined;
@@ -296,6 +296,10 @@ export interface RunInterruptResult<TPayload = HumanInterruptPayload> {
296
296
  interruptId: string;
297
297
  /** `thread_id` the run was bound to — required to resume. */
298
298
  threadId?: string;
299
+ /** LangGraph checkpoint id that contains the paused interrupt task. */
300
+ checkpointId?: string;
301
+ /** LangGraph checkpoint namespace for the paused interrupt task. */
302
+ checkpointNs?: string;
299
303
  /** Structured payload describing what needs human input. */
300
304
  payload: TPayload;
301
305
  }
@@ -7,7 +7,7 @@ import type * as s from '@/types/stream';
7
7
  import type * as e from '@/common/enum';
8
8
  import type * as g from '@/types/graph';
9
9
  import type * as l from '@/types/llm';
10
- import type { ToolSessionMap, ToolExecutionConfig, ToolOutputReferencesConfig } from '@/types/tools';
10
+ import type { ToolSessionMap, ToolExecutionConfig, ToolOutputReferencesConfig, EagerEventToolExecutionConfig } from '@/types/tools';
11
11
  import type { HumanInTheLoopConfig } from '@/types/hitl';
12
12
  import type { HookRegistry } from '@/hooks';
13
13
  export type ZodObjectAny = z.ZodObject<any, any, any, any>;
@@ -145,6 +145,16 @@ export type RunConfig = {
145
145
  * placeholders. Disabled by default so existing runs are unaffected.
146
146
  */
147
147
  toolOutputReferences?: ToolOutputReferencesConfig;
148
+ /**
149
+ * Opt-in latency optimization for event-driven tools. When enabled,
150
+ * the streaming layer may start a tool call as soon as it sees a
151
+ * complete, parseable tool call; ToolNode still waits for the final
152
+ * assistant message before appending ToolMessages, preserving provider
153
+ * ordering. The SDK automatically falls back to normal batch dispatch
154
+ * when hooks, HITL, output references, or ambiguous stream shapes make
155
+ * eager dispatch unsafe.
156
+ */
157
+ eagerEventToolExecution?: EagerEventToolExecutionConfig;
148
158
  /**
149
159
  * Selects the execution backend for built-in code tools. Omit this to keep
150
160
  * the remote LibreChat Code API sandbox. Set `{ engine: 'local' }` to run
@@ -22,6 +22,36 @@ export type ToolRefs = {
22
22
  toolMap?: ToolMap;
23
23
  };
24
24
  export type ToolRefGenerator = (tool_calls: ToolCall[]) => ToolRefs;
25
+ export type EagerEventToolExecutionConfig = {
26
+ /**
27
+ * When enabled, event-driven tool calls may be started from the
28
+ * streaming layer as soon as the SDK observes a complete tool call.
29
+ * Results are still held until ToolNode materializes the final
30
+ * ToolMessages so provider message ordering is preserved.
31
+ */
32
+ enabled?: boolean;
33
+ };
34
+ export type EagerEventToolExecutionOutcome = {
35
+ results: ToolExecuteResult[];
36
+ error?: undefined;
37
+ } | {
38
+ results?: undefined;
39
+ error: Error;
40
+ };
41
+ export type EagerEventToolExecution = {
42
+ toolCallId: string;
43
+ toolName: string;
44
+ args: Record<string, unknown>;
45
+ request: ToolCallRequest;
46
+ promise: Promise<EagerEventToolExecutionOutcome>;
47
+ };
48
+ export type EagerEventToolCallChunkState = {
49
+ id?: string;
50
+ name?: string;
51
+ argsText: string;
52
+ index?: number;
53
+ lastArgsFragment?: string;
54
+ };
25
55
  export type ToolNodeOptions = {
26
56
  name?: string;
27
57
  tags?: string[];
@@ -41,6 +71,12 @@ export type ToolNodeOptions = {
41
71
  agentId?: string;
42
72
  /** Tool names that must be executed directly (via runTool) even in event-driven mode (e.g., graph-managed handoff tools) */
43
73
  directToolNames?: Set<string>;
74
+ /** Opt-in eager execution for event-driven tool calls. */
75
+ eagerEventToolExecution?: EagerEventToolExecutionConfig;
76
+ /** Shared per-run eager execution registry populated by the stream handler. */
77
+ eagerEventToolExecutions?: Map<string, EagerEventToolExecution>;
78
+ /** Shared per-run per-tool turn counter used by eager and normal event dispatch. */
79
+ eagerEventToolUsageCount?: Map<string, number>;
44
80
  /**
45
81
  * Hook registry for PreToolUse/PostToolUse/PostToolUseFailure/
46
82
  * PermissionDenied lifecycle hooks. Fires for **every** tool the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "3.1.86",
3
+ "version": "3.1.88",
4
4
  "main": "./dist/cjs/main.cjs",
5
5
  "module": "./dist/esm/main.mjs",
6
6
  "types": "./dist/types/index.d.ts",
@@ -10,6 +10,16 @@
10
10
  "require": "./dist/cjs/main.cjs",
11
11
  "types": "./dist/types/index.d.ts"
12
12
  },
13
+ "./openai": {
14
+ "import": "./dist/esm/openai/index.mjs",
15
+ "require": "./dist/cjs/openai/index.cjs",
16
+ "types": "./dist/types/openai/index.d.ts"
17
+ },
18
+ "./responses": {
19
+ "import": "./dist/esm/responses/index.mjs",
20
+ "require": "./dist/cjs/responses/index.cjs",
21
+ "types": "./dist/types/responses/index.d.ts"
22
+ },
13
23
  "./langchain": {
14
24
  "import": "./dist/esm/langchain/index.mjs",
15
25
  "require": "./dist/cjs/langchain/index.cjs",
@@ -68,6 +78,12 @@
68
78
  ],
69
79
  "langchain/*": [
70
80
  "dist/types/langchain/*"
81
+ ],
82
+ "openai": [
83
+ "dist/types/openai/index.d.ts"
84
+ ],
85
+ "responses": [
86
+ "dist/types/responses/index.d.ts"
71
87
  ]
72
88
  }
73
89
  },
@@ -133,6 +149,7 @@
133
149
  "local:image": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/local_engine_image.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
134
150
  "local:compile": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/local_engine_compile.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
135
151
  "compare:pi": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/compare_pi_vs_ours.ts",
152
+ "session:live": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/session_live.ts",
136
153
  "local:workspace": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/local_engine_workspace.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
137
154
  "programmatic_exec_agent": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/programmatic_exec_agent.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
138
155
  "ant_web_search": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/ant_web_search.ts --name 'Jo' --location 'New York, NY'",
@@ -213,7 +230,7 @@
213
230
  "@langfuse/langchain": "^4.3.0",
214
231
  "@langfuse/otel": "^4.3.0",
215
232
  "@langfuse/tracing": "^4.3.0",
216
- "@opentelemetry/sdk-node": "^0.207.0",
233
+ "@opentelemetry/sdk-node": "^0.218.0",
217
234
  "@scarf/scarf": "^1.4.0",
218
235
  "@types/diff": "^7.0.2",
219
236
  "ai-tokenizer": "^1.0.6",