@librechat/agents 3.7.22 → 3.8.1
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.
- package/dist/cjs/agents/AgentContext.cjs +13 -3
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +174 -53
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +15 -5
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +48 -2
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +42 -0
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/langfuseTraceShaping.cjs +7 -1
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +5 -9
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +2 -7
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/contextPressureMeter.cjs +51 -10
- package/dist/cjs/llm/contextPressureMeter.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +1 -1
- package/dist/cjs/llm/invoke.cjs +2 -2
- package/dist/cjs/llm/openai/index.cjs +4 -3
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +5 -4
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/preempt.cjs +3 -2
- package/dist/cjs/llm/preempt.cjs.map +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +9 -7
- package/dist/cjs/llm/prepareProviderRequest.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs +1 -1
- package/dist/cjs/main.cjs +11 -5
- package/dist/cjs/messages/alternation.cjs +1 -5
- package/dist/cjs/messages/alternation.cjs.map +1 -1
- package/dist/cjs/messages/budget.cjs +206 -7
- package/dist/cjs/messages/budget.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +3 -9
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +25 -37
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +131 -42
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/index.cjs +2 -0
- package/dist/cjs/messages/prune.cjs +12 -7
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/reasoningTypes.cjs +21 -0
- package/dist/cjs/messages/reasoningTypes.cjs.map +1 -0
- package/dist/cjs/messages/recency.cjs +15 -94
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/messages/toolHistoryProjection.cjs +243 -0
- package/dist/cjs/messages/toolHistoryProjection.cjs.map +1 -0
- package/dist/cjs/messages/toolResultTypes.cjs +145 -4
- package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
- package/dist/cjs/run.cjs +5 -4
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +6 -4
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs +3 -0
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/index.cjs +1 -1
- package/dist/cjs/session/sessionProjection.cjs +75 -0
- package/dist/cjs/session/sessionProjection.cjs.map +1 -0
- package/dist/cjs/stream.cjs +18 -17
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +18 -8
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/summarization/shared.cjs +9 -0
- package/dist/cjs/summarization/shared.cjs.map +1 -1
- package/dist/cjs/tools/ArtifactDelivery.cjs +27 -0
- package/dist/cjs/tools/ArtifactDelivery.cjs.map +1 -0
- package/dist/cjs/tools/BashExecutor.cjs +6 -1
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +6 -1
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +5 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +1 -1
- package/dist/cjs/utils/events.cjs +13 -0
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +105 -0
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +13 -3
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +176 -55
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +15 -5
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +49 -4
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +41 -1
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/langfuseTraceShaping.mjs +7 -1
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +5 -9
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +2 -7
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/contextPressureMeter.mjs +52 -11
- package/dist/esm/llm/contextPressureMeter.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +1 -1
- package/dist/esm/llm/invoke.mjs +2 -2
- package/dist/esm/llm/openai/index.mjs +2 -1
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +5 -4
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/preempt.mjs +2 -1
- package/dist/esm/llm/preempt.mjs.map +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +9 -7
- package/dist/esm/llm/prepareProviderRequest.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs +1 -1
- package/dist/esm/main.mjs +10 -7
- package/dist/esm/messages/alternation.mjs +2 -6
- package/dist/esm/messages/alternation.mjs.map +1 -1
- package/dist/esm/messages/budget.mjs +206 -8
- package/dist/esm/messages/budget.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +3 -9
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +23 -33
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +132 -43
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/index.mjs +2 -0
- package/dist/esm/messages/prune.mjs +12 -7
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/reasoningTypes.mjs +20 -0
- package/dist/esm/messages/reasoningTypes.mjs.map +1 -0
- package/dist/esm/messages/recency.mjs +16 -95
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/toolHistoryProjection.mjs +237 -0
- package/dist/esm/messages/toolHistoryProjection.mjs.map +1 -0
- package/dist/esm/messages/toolResultTypes.mjs +141 -4
- package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
- package/dist/esm/run.mjs +5 -4
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +6 -4
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs +3 -0
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/index.mjs +1 -1
- package/dist/esm/session/sessionProjection.mjs +72 -0
- package/dist/esm/session/sessionProjection.mjs.map +1 -0
- package/dist/esm/stream.mjs +15 -14
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +19 -9
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/summarization/shared.mjs +9 -1
- package/dist/esm/summarization/shared.mjs.map +1 -1
- package/dist/esm/tools/ArtifactDelivery.mjs +26 -0
- package/dist/esm/tools/ArtifactDelivery.mjs.map +1 -0
- package/dist/esm/tools/BashExecutor.mjs +6 -1
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +6 -1
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +5 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +1 -1
- package/dist/esm/utils/events.mjs +13 -0
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +105 -1
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +13 -1
- package/dist/types/graphs/Graph.d.ts +27 -0
- package/dist/types/hooks/types.d.ts +4 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/langfuse.d.ts +10 -0
- package/dist/types/langfuseToolOutputTracing.d.ts +2 -0
- package/dist/types/llm/contextPressureMeter.d.ts +2 -1
- package/dist/types/llm/prepareProviderRequest.d.ts +7 -1
- package/dist/types/messages/budget.d.ts +15 -10
- package/dist/types/messages/core.d.ts +8 -17
- package/dist/types/messages/format.d.ts +3 -2
- package/dist/types/messages/index.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +1 -1
- package/dist/types/messages/reasoningTypes.d.ts +7 -0
- package/dist/types/messages/recency.d.ts +3 -0
- package/dist/types/messages/toolHistoryProjection.d.ts +65 -0
- package/dist/types/messages/toolResultTypes.d.ts +31 -1
- package/dist/types/session/sessionProjection.d.ts +10 -0
- package/dist/types/summarization/index.d.ts +2 -1
- package/dist/types/summarization/node.d.ts +1 -0
- package/dist/types/summarization/shared.d.ts +12 -0
- package/dist/types/tools/ArtifactDelivery.d.ts +4 -0
- package/dist/types/types/graph.d.ts +28 -0
- package/dist/types/types/run.d.ts +4 -0
- package/dist/types/types/summarize.d.ts +4 -1
- package/dist/types/types/tools.d.ts +11 -0
- package/dist/types/utils/tokens.d.ts +2 -1
- package/package.json +1 -1
- package/src/agents/AgentContext.ts +34 -3
- package/src/graphs/Graph.ts +465 -147
- package/src/graphs/MultiAgentGraph.ts +28 -6
- package/src/hooks/types.ts +4 -1
- package/src/index.ts +1 -0
- package/src/langfuse.ts +84 -11
- package/src/langfuseToolOutputTracing.ts +91 -0
- package/src/langfuseTraceShaping.ts +17 -4
- package/src/llm/anthropic/utils/message_inputs.ts +5 -10
- package/src/llm/bedrock/utils/message_inputs.ts +2 -8
- package/src/llm/contextPressureMeter.ts +80 -12
- package/src/llm/openai/utils/index.ts +5 -4
- package/src/llm/prepareProviderRequest.ts +21 -16
- package/src/messages/alternation.ts +2 -15
- package/src/messages/budget.ts +439 -23
- package/src/messages/cache.ts +8 -9
- package/src/messages/core.ts +65 -95
- package/src/messages/format.ts +262 -78
- package/src/messages/index.ts +1 -1
- package/src/messages/prune.ts +31 -12
- package/src/messages/reasoningTypes.ts +23 -0
- package/src/messages/recency.ts +35 -179
- package/src/messages/toolHistoryProjection.ts +460 -0
- package/src/messages/toolResultTypes.ts +331 -100
- package/src/run.ts +10 -2
- package/src/session/AgentSession.ts +33 -16
- package/src/session/JsonlSessionStore.ts +6 -0
- package/src/session/sessionProjection.ts +126 -0
- package/src/stream.ts +14 -19
- package/src/summarization/index.ts +2 -0
- package/src/summarization/node.ts +62 -13
- package/src/summarization/shared.ts +23 -0
- package/src/tools/ArtifactDelivery.ts +50 -0
- package/src/tools/BashExecutor.ts +18 -1
- package/src/tools/CodeExecutor.ts +18 -1
- package/src/tools/ProgrammaticToolCalling.ts +15 -1
- package/src/types/graph.ts +28 -0
- package/src/types/run.ts +4 -0
- package/src/types/summarize.ts +4 -1
- package/src/types/tools.ts +12 -0
- package/src/utils/events.ts +19 -0
- package/src/utils/tokens.ts +183 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BaseMessage, ContentBlock } from '@langchain/core/messages';
|
|
2
|
+
interface ToolHistoryCallMirror {
|
|
3
|
+
readonly name?: string;
|
|
4
|
+
readonly arguments: string;
|
|
5
|
+
}
|
|
6
|
+
export type ToolHistoryCallMirrors = Map<string, ToolHistoryCallMirror | null>;
|
|
7
|
+
/** Only complete argument representations can establish that a call is a mirror. */
|
|
8
|
+
export declare function recordToolHistoryCallMirror(mirrors: ToolHistoryCallMirrors, block: unknown): void;
|
|
9
|
+
export declare function isToolHistoryCallMirror(mirrors: ToolHistoryCallMirrors | undefined, id: unknown, name: unknown, args: unknown): boolean;
|
|
10
|
+
export declare const OPENAI_RESPONSES_REPLAY_POSITIONS_KEY = "__openai_responses_replay_positions__";
|
|
11
|
+
export type ResponsesReplayPosition = {
|
|
12
|
+
contentIndex?: number;
|
|
13
|
+
itemId: string;
|
|
14
|
+
kind: 'message' | 'output' | 'reasoning' | 'text';
|
|
15
|
+
outputIndex: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function isResponsesReplayPosition(value: unknown): value is ResponsesReplayPosition;
|
|
18
|
+
/** Provider evidence is selected once; a sidecar never replaces message content. */
|
|
19
|
+
export interface ResponsesHistorySource {
|
|
20
|
+
readonly coverage: 'complete-output' | 'tool-sidecar';
|
|
21
|
+
readonly items: unknown[];
|
|
22
|
+
readonly message?: BaseMessage;
|
|
23
|
+
}
|
|
24
|
+
export interface OrderedToolHistoryProjection {
|
|
25
|
+
readonly source: ResponsesHistorySource;
|
|
26
|
+
readonly contributions: readonly ResponsesHistoryContribution[];
|
|
27
|
+
readonly hasToolContent: boolean;
|
|
28
|
+
readonly truncated: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ToolHistoryPreparation {
|
|
31
|
+
get(message: BaseMessage): OrderedToolHistoryProjection | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** A preparation owns this cache; changed messages must be copy-on-write. */
|
|
34
|
+
export declare function createToolHistoryPreparation(): ToolHistoryPreparation;
|
|
35
|
+
export interface ToolHistoryPosition {
|
|
36
|
+
readonly outputIndex: number;
|
|
37
|
+
readonly contentIndex?: number;
|
|
38
|
+
readonly itemId?: string;
|
|
39
|
+
}
|
|
40
|
+
export type ResponsesHistoryContribution = ToolHistoryPosition & ({
|
|
41
|
+
readonly kind: 'text';
|
|
42
|
+
readonly actor: 'model';
|
|
43
|
+
readonly text: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'call';
|
|
46
|
+
readonly actor: 'model';
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly callId?: string;
|
|
49
|
+
readonly arguments: unknown;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'image';
|
|
52
|
+
readonly actor: 'tool';
|
|
53
|
+
readonly image: ContentBlock.Multimodal.Image;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'provider-item';
|
|
56
|
+
readonly actor: 'model' | 'tool';
|
|
57
|
+
readonly providerType: string;
|
|
58
|
+
readonly value: unknown;
|
|
59
|
+
});
|
|
60
|
+
export declare function getResponsesHistorySource(message: BaseMessage): ResponsesHistorySource | undefined;
|
|
61
|
+
/** Complete generated images retain their actual format across replay and folding. */
|
|
62
|
+
export declare function getGeneratedImageMimeType(data: string): string;
|
|
63
|
+
/** Streaming positions order sidecar evidence only when text positions map exactly. */
|
|
64
|
+
export declare function projectResponsesHistory(source: ResponsesHistorySource, consumeWork: () => boolean): Generator<ResponsesHistoryContribution>;
|
|
65
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import type { ProviderName } from '@/types/llm';
|
|
1
3
|
export type ProviderToolCallKind = 'tool' | 'server' | 'anthropic-server' | 'mcp' | 'google' | 'bedrock';
|
|
2
4
|
export interface ProviderToolCallPartDescriptor {
|
|
3
5
|
readonly callId: string;
|
|
@@ -15,7 +17,7 @@ export interface ProviderToolResultPartDescriptor {
|
|
|
15
17
|
}
|
|
16
18
|
export interface ProviderToolCallIndexEntry {
|
|
17
19
|
readonly descriptor: ProviderToolCallPartDescriptor;
|
|
18
|
-
|
|
20
|
+
secondarySourceTypes?: Set<string>;
|
|
19
21
|
}
|
|
20
22
|
export type ProviderToolCallIndex = Map<string, ProviderToolCallIndexEntry | null>;
|
|
21
23
|
export declare const PROVIDER_TOOL_RESULT_MAX_ARRAY_ENTRIES = 256;
|
|
@@ -27,7 +29,35 @@ export declare function getBoundedProviderPairingArrayProperty(value: unknown, k
|
|
|
27
29
|
export declare function isBoundedProviderPairingString(value: unknown, allowEmpty?: boolean): value is string;
|
|
28
30
|
export declare function hasStructurallyValidAnthropicWebSearchResultContent(part: unknown): boolean;
|
|
29
31
|
export declare function getProviderToolResultPartDescriptor(part: unknown): ProviderToolResultPartDescriptor | undefined;
|
|
32
|
+
export declare function isProviderToolCallContentPart(part: unknown): boolean;
|
|
33
|
+
export declare function isProviderToolContentPart(part: unknown): boolean;
|
|
30
34
|
export declare function getProviderAIMessageToolCallDescriptor(toolCall: unknown): ProviderToolCallPartDescriptor | undefined;
|
|
31
35
|
export declare function getProviderToolCallPartDescriptor(part: unknown): ProviderToolCallPartDescriptor | undefined;
|
|
32
36
|
export declare function appendProviderToolCallDescriptor(index: ProviderToolCallIndex, descriptor: ProviderToolCallPartDescriptor): void;
|
|
37
|
+
/** Google's built-in code execution emits an `executableCode` part with no call
|
|
38
|
+
* id; its `codeExecutionResult` pairs by adjacency instead. */
|
|
39
|
+
export declare function isExecutableCodePart(part: unknown): boolean;
|
|
33
40
|
export declare function consumeProviderToolResultPair(descriptor: ProviderToolResultPartDescriptor, calls: ProviderToolCallIndex, previousPart?: unknown): boolean;
|
|
41
|
+
export declare function getLegacyFunctionCallId(name: string): string | undefined;
|
|
42
|
+
export type ProviderMessageRole = 'assistant' | 'user' | 'system' | 'tool' | 'function';
|
|
43
|
+
/**
|
|
44
|
+
* Normalizes a message to the role a provider converter would send it as. A
|
|
45
|
+
* `ChatMessage` reports its type as `generic` and carries the wire role on
|
|
46
|
+
* `role`, so every classifier that keys on `getType()` alone silently skips
|
|
47
|
+
* generic assistant, tool and function messages the converters accept.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getProviderMessageRole(message: BaseMessage, provider?: ProviderName): ProviderMessageRole | undefined;
|
|
50
|
+
export declare function getRawToolCallDescriptor(toolCall: unknown): ProviderToolCallPartDescriptor | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Appends every tool call an assistant message carries: parsed
|
|
53
|
+
* `AIMessage.tool_calls`, raw `additional_kwargs.tool_calls` (where OpenAI
|
|
54
|
+
* keeps calls when the parsed array is empty) and a legacy
|
|
55
|
+
* `additional_kwargs.function_call`. Content-block calls are the caller's to
|
|
56
|
+
* append, since only the caller knows whether the block is being replayed.
|
|
57
|
+
* Returns how many descriptors were recognized, so a caller can tell an
|
|
58
|
+
* invocation from a plain assistant turn without re-deriving the shapes.
|
|
59
|
+
*/
|
|
60
|
+
export declare function appendProviderMessageToolCalls(message: BaseMessage, calls: ProviderToolCallIndex, provider?: ProviderName): number;
|
|
61
|
+
/** Describes a whole-message tool result: a `ToolMessage`, a `FunctionMessage`,
|
|
62
|
+
* or a generic message carrying the equivalent wire role. */
|
|
63
|
+
export declare function getProviderToolMessageResultDescriptor(message: BaseMessage, provider?: ProviderName): ProviderToolResultPartDescriptor | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DerivedSessionMessages } from './deriveMessages';
|
|
2
|
+
import type { SessionEntry } from './types';
|
|
3
|
+
import type { JsonlSessionStore } from './JsonlSessionStore';
|
|
4
|
+
/** Internal: only AgentSession's unexposed stores may reuse log topology. */
|
|
5
|
+
export declare function initializeSessionProjection(store: JsonlSessionStore, entries: readonly SessionEntry[]): void;
|
|
6
|
+
/** Forks share entry references, so exposing either disables the whole family. */
|
|
7
|
+
export declare function shareSessionProjectionOwnership(source: JsonlSessionStore, target: JsonlSessionStore): void;
|
|
8
|
+
export declare function releaseSessionProjection(store: JsonlSessionStore): void;
|
|
9
|
+
/** Reuses log topology, but materializes fresh mutable messages for every run. */
|
|
10
|
+
export declare function deriveSessionMessages(store: JsonlSessionStore | undefined): DerivedSessionMessages;
|
|
@@ -4,7 +4,8 @@ import type { SummarizationTrigger } from '@/types';
|
|
|
4
4
|
* default prompts stay out of it: LibreChat's manual flow deliberately words
|
|
5
5
|
* its own, so exporting these would publish an API with no consumer.
|
|
6
6
|
*/
|
|
7
|
-
export { buildSummarizationInstruction, buildSummaryCarrierText, separateSummarizationParameters, } from './shared';
|
|
7
|
+
export { buildSummarizationInstruction, buildSummaryCarrierText, separateSummarizationParameters, ManualSummarizationSkippedError, } from './shared';
|
|
8
|
+
export type { ManualSummarizationSkipReason } from './shared';
|
|
8
9
|
/** For tests only. Resets the dedup set so warnings can be observed again. */
|
|
9
10
|
export declare function _resetUnrecognizedTriggerWarnings(): void;
|
|
10
11
|
/**
|
|
@@ -45,6 +45,7 @@ export declare function createSummarizeNode({ agentContext, graph: adapterGraph,
|
|
|
45
45
|
}, config?: RunnableConfig) => Promise<{
|
|
46
46
|
summarizationRequest: undefined;
|
|
47
47
|
messages?: BaseMessage[];
|
|
48
|
+
manualSummary?: string;
|
|
48
49
|
}>;
|
|
49
50
|
/** Creates an `onChunk` callback that dispatches `ON_SUMMARIZE_DELTA` events for streaming. */
|
|
50
51
|
export declare function createSummarizationChunkHandler({ stepId, config, provider, reasoningKey, graph, }: {
|
|
@@ -23,3 +23,15 @@ export declare function separateSummarizationParameters(parameters: Record<strin
|
|
|
23
23
|
maxSummaryTokens?: number;
|
|
24
24
|
};
|
|
25
25
|
export declare function buildSummarizationInstruction(promptText: string, updatePromptText: string | undefined, priorSummaryText?: string, semanticIndexAppendix?: string): string;
|
|
26
|
+
/** Why a summarize-only run could not attempt its summary. */
|
|
27
|
+
export type ManualSummarizationSkipReason = 'disabled' | 'exhausted' | 'instructions_exceed_budget' | 'nothing_to_summarize';
|
|
28
|
+
/**
|
|
29
|
+
* A summarize-only run asked for a summary the graph could not attempt.
|
|
30
|
+
* Thrown rather than ending the run quietly: the summary is the whole result
|
|
31
|
+
* of such a run, so a host left with neither a summary nor an error would
|
|
32
|
+
* have nothing to show the user.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ManualSummarizationSkippedError extends Error {
|
|
35
|
+
readonly reason: ManualSummarizationSkipReason;
|
|
36
|
+
constructor(reason: ManualSummarizationSkipReason, message: string);
|
|
37
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ArtifactDeliveryFailure } from '@/types';
|
|
2
|
+
export declare const ARTIFACT_DELIVERY_WARNING_PREFIX = "Artifact delivery warning:";
|
|
3
|
+
export declare function normalizeArtifactDeliveryFailure(value: unknown): ArtifactDeliveryFailure | undefined;
|
|
4
|
+
export declare function appendArtifactDeliveryWarning(output: string, delivery: ArtifactDeliveryFailure | undefined): string;
|
|
@@ -30,6 +30,13 @@ export type SystemCallbacks = {
|
|
|
30
30
|
export type BaseGraphState = {
|
|
31
31
|
messages: BaseMessage[];
|
|
32
32
|
runStepState?: RunStepResumeState;
|
|
33
|
+
/**
|
|
34
|
+
* The summary a summarize-only run produced. Kept in state because such a
|
|
35
|
+
* run has no assistant reply: trace roots report it as the run's output
|
|
36
|
+
* instead of the retained tail or the raw state. Empty once any later run
|
|
37
|
+
* on the same checkpointed thread starts, so it never outlives its run.
|
|
38
|
+
*/
|
|
39
|
+
manualSummary?: string;
|
|
33
40
|
};
|
|
34
41
|
export type AgentSubgraphState = BaseGraphState & {
|
|
35
42
|
summarizationRequest?: SummarizationNodeInput;
|
|
@@ -652,6 +659,14 @@ export interface LangfuseConfig {
|
|
|
652
659
|
*/
|
|
653
660
|
additionalHeaders?: Record<string, string>;
|
|
654
661
|
metadata?: Record<string, string | number | boolean | null | undefined>;
|
|
662
|
+
/**
|
|
663
|
+
* User identity stamped on every trace this run emits — the agent stream,
|
|
664
|
+
* titles, activity and reasoning labels, and phases. Hosts set it when the
|
|
665
|
+
* observability identity differs from `configurable.user_id` (an email or
|
|
666
|
+
* IdP subject instead of an internal database id); that id remains the
|
|
667
|
+
* fallback when unset or blank.
|
|
668
|
+
*/
|
|
669
|
+
userId?: string;
|
|
655
670
|
/**
|
|
656
671
|
* Internal OTLP span attributes to attach to Langfuse observations before
|
|
657
672
|
* export. Intended for collector-side routing/filtering; strip these in the
|
|
@@ -717,6 +732,19 @@ interface AgentInputFields {
|
|
|
717
732
|
*/
|
|
718
733
|
discoveredTools?: string[];
|
|
719
734
|
summarizationEnabled?: boolean;
|
|
735
|
+
/**
|
|
736
|
+
* Runs this agent as a summarize-only pass: the first model step requests
|
|
737
|
+
* summarization outright instead of consulting the trigger, and the step
|
|
738
|
+
* after the summary emits its context snapshot and ends the run without a
|
|
739
|
+
* model call. Hosts use it for user-initiated compaction, where the summary
|
|
740
|
+
* is the whole response. Requires `summarizationEnabled`: a run that cannot
|
|
741
|
+
* attempt the summary rejects with `ManualSummarizationSkippedError`
|
|
742
|
+
* rather than ending with nothing, and one whose provider calls all fail
|
|
743
|
+
* keeps the history and reports the failure on the summary step. A
|
|
744
|
+
* multi-agent workflow compiles to the agent that opted in alone; no other
|
|
745
|
+
* agent runs.
|
|
746
|
+
*/
|
|
747
|
+
summarizeOnly?: boolean;
|
|
720
748
|
summarizationConfig?: SummarizationConfig;
|
|
721
749
|
/**
|
|
722
750
|
* Optional host-supplied, user-visible guidance for compaction. The SDK
|
|
@@ -453,6 +453,10 @@ export type TokenBudgetBreakdown = {
|
|
|
453
453
|
toolTokenCounts?: Record<string, number>;
|
|
454
454
|
/** Names of counted tools that are deferred (`defer_loading`) and discovered. */
|
|
455
455
|
deferredToolNames?: string[];
|
|
456
|
+
/** Calibrated retained tool traffic: tool results plus assistant turns made only of tool calls, inline provider tool results and reasoning. A subset of messageTokens, not an additional budget category. */
|
|
457
|
+
toolMessageTokens?: number;
|
|
458
|
+
/** Per-tool result-message share; excludes assistant invocation overhead. */
|
|
459
|
+
toolMessageTokenCounts?: Record<string, number>;
|
|
456
460
|
};
|
|
457
461
|
export type EventStreamOptions = {
|
|
458
462
|
callbacks?: g.ClientCallbacks;
|
|
@@ -104,8 +104,11 @@ export interface SummarizationNodeInput {
|
|
|
104
104
|
* is compacting to recover. When summarization is not enabled, this
|
|
105
105
|
* variant performs no model call — the corrected budget alone is what the
|
|
106
106
|
* retry needs.
|
|
107
|
+
* - `manual`: the host asked for a summary outright (a summarize-only run).
|
|
108
|
+
* The recency window is not applied unless the host configured
|
|
109
|
+
* `retainRecent` explicitly, so the summary replaces the whole history.
|
|
107
110
|
*/
|
|
108
|
-
reason?: 'trigger' | 'overflow';
|
|
111
|
+
reason?: 'trigger' | 'overflow' | 'manual';
|
|
109
112
|
/**
|
|
110
113
|
* Whether an overflow recovery may spend a summarization model call.
|
|
111
114
|
*
|
|
@@ -449,6 +449,13 @@ export type FileRef = {
|
|
|
449
449
|
inherited?: true;
|
|
450
450
|
};
|
|
451
451
|
export type FileRefs = FileRef[];
|
|
452
|
+
export type ArtifactDeliveryFailure = {
|
|
453
|
+
code: 'artifact_delivery_failed';
|
|
454
|
+
status: 'partial' | 'failed';
|
|
455
|
+
attempted: number;
|
|
456
|
+
delivered: number;
|
|
457
|
+
failed: number;
|
|
458
|
+
};
|
|
452
459
|
export type ExecuteResult = {
|
|
453
460
|
/**
|
|
454
461
|
* Execution session id — the (transient) sandbox run that produced
|
|
@@ -459,6 +466,7 @@ export type ExecuteResult = {
|
|
|
459
466
|
stdout: string;
|
|
460
467
|
stderr: string;
|
|
461
468
|
files?: FileRefs;
|
|
469
|
+
artifact_delivery?: ArtifactDeliveryFailure;
|
|
462
470
|
/**
|
|
463
471
|
* Durable runtime session id echoed by a stateful Code API backend
|
|
464
472
|
* (hash of tenant+user+hint). Additive; absent on stateless servers.
|
|
@@ -1217,6 +1225,7 @@ export type ProgrammaticExecutionResponse = {
|
|
|
1217
1225
|
stdout?: string;
|
|
1218
1226
|
stderr?: string;
|
|
1219
1227
|
files?: FileRefs;
|
|
1228
|
+
artifact_delivery?: ArtifactDeliveryFailure;
|
|
1220
1229
|
/** Durable runtime session echo from a stateful backend (additive). */
|
|
1221
1230
|
runtime_session_id?: string;
|
|
1222
1231
|
runtime_status?: 'new' | 'reused';
|
|
@@ -1230,6 +1239,7 @@ export type ProgrammaticExecutionArtifact = {
|
|
|
1230
1239
|
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
1231
1240
|
session_id?: string;
|
|
1232
1241
|
files?: FileRefs;
|
|
1242
|
+
artifact_delivery?: ArtifactDeliveryFailure;
|
|
1233
1243
|
/** Durable runtime session echo from a stateful backend (additive). */
|
|
1234
1244
|
runtime_session_id?: string;
|
|
1235
1245
|
runtime_status?: 'new' | 'reused';
|
|
@@ -1284,6 +1294,7 @@ export type CodeExecutionArtifact = {
|
|
|
1284
1294
|
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
1285
1295
|
session_id?: string;
|
|
1286
1296
|
files?: FileRefs;
|
|
1297
|
+
artifact_delivery?: ArtifactDeliveryFailure;
|
|
1287
1298
|
/** Durable runtime session echo from a stateful backend (additive). */
|
|
1288
1299
|
runtime_session_id?: string;
|
|
1289
1300
|
runtime_status?: 'new' | 'reused';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
2
|
export type EncodingName = 'o200k_base' | 'claude';
|
|
3
|
-
export type UnsafeTokenMeasurementReason = 'message_proxy' | 'content_proxy' | 'metadata_proxy' | 'metadata_accessor' | 'invalid_count';
|
|
3
|
+
export type UnsafeTokenMeasurementReason = 'message_proxy' | 'content_proxy' | 'metadata_proxy' | 'metadata_accessor' | 'metadata_limit' | 'invalid_count';
|
|
4
4
|
export declare class UnsafeTokenMeasurementError extends Error {
|
|
5
5
|
readonly type = "unsafe_token_measurement";
|
|
6
6
|
readonly reason: UnsafeTokenMeasurementReason;
|
|
@@ -61,6 +61,7 @@ export declare function encodingForModel(model: string): EncodingName;
|
|
|
61
61
|
* unsafe so the caller can normalize or reject them conservatively.
|
|
62
62
|
*/
|
|
63
63
|
export declare function hasUnsafeStructuredSerialization(value: unknown): boolean;
|
|
64
|
+
export declare function readTokenMetadataProperty(value: object, key: PropertyKey, path: string): unknown;
|
|
64
65
|
export declare function getTokenCountForMessage(message: BaseMessage, getTokenCount: (text: string) => number, encoding?: EncodingName): number;
|
|
65
66
|
/**
|
|
66
67
|
* Largest-remainder apportionment: scales each count by `multiplier` and
|
package/package.json
CHANGED
|
@@ -123,6 +123,7 @@ export class AgentContext {
|
|
|
123
123
|
useLegacyContent,
|
|
124
124
|
discoveredTools,
|
|
125
125
|
summarizationEnabled,
|
|
126
|
+
summarizeOnly,
|
|
126
127
|
summarizationConfig,
|
|
127
128
|
compactionSemanticIndex,
|
|
128
129
|
initialSummary,
|
|
@@ -158,6 +159,7 @@ export class AgentContext {
|
|
|
158
159
|
useLegacyContent,
|
|
159
160
|
discoveredTools,
|
|
160
161
|
summarizationEnabled,
|
|
162
|
+
summarizeOnly,
|
|
161
163
|
summarizationConfig,
|
|
162
164
|
compactionSemanticIndex,
|
|
163
165
|
contextPruningConfig,
|
|
@@ -383,6 +385,10 @@ export class AgentContext {
|
|
|
383
385
|
useLegacyContent: boolean = false;
|
|
384
386
|
/** Enables graph-level summarization for this agent */
|
|
385
387
|
summarizationEnabled?: boolean;
|
|
388
|
+
/** Summarize-only run: request a summary on the first model step and end after it */
|
|
389
|
+
summarizeOnly?: boolean;
|
|
390
|
+
/** Whether the summarize-only run has already issued its one request */
|
|
391
|
+
private _manualSummarizationRequested: boolean = false;
|
|
386
392
|
/** Summarization runtime settings used by graph pruning hooks */
|
|
387
393
|
summarizationConfig?: t.SummarizationConfig;
|
|
388
394
|
/** Host-supplied advisory guidance consumed only when compaction runs. */
|
|
@@ -480,6 +486,7 @@ export class AgentContext {
|
|
|
480
486
|
useLegacyContent,
|
|
481
487
|
discoveredTools,
|
|
482
488
|
summarizationEnabled,
|
|
489
|
+
summarizeOnly,
|
|
483
490
|
summarizationConfig,
|
|
484
491
|
compactionSemanticIndex,
|
|
485
492
|
contextPruningConfig,
|
|
@@ -508,6 +515,7 @@ export class AgentContext {
|
|
|
508
515
|
useLegacyContent?: boolean;
|
|
509
516
|
discoveredTools?: string[];
|
|
510
517
|
summarizationEnabled?: boolean;
|
|
518
|
+
summarizeOnly?: boolean;
|
|
511
519
|
summarizationConfig?: t.SummarizationConfig;
|
|
512
520
|
compactionSemanticIndex?: t.CompactionSemanticIndex;
|
|
513
521
|
contextPruningConfig?: t.ContextPruningConfig;
|
|
@@ -549,6 +557,7 @@ export class AgentContext {
|
|
|
549
557
|
|
|
550
558
|
this.useLegacyContent = useLegacyContent ?? false;
|
|
551
559
|
this.summarizationEnabled = summarizationEnabled;
|
|
560
|
+
this.summarizeOnly = summarizeOnly;
|
|
552
561
|
this.summarizationConfig = summarizationConfig;
|
|
553
562
|
if (compactionSemanticIndex != null) {
|
|
554
563
|
this.compactionSemanticIndex = snapshotCompactionSemanticIndex(
|
|
@@ -1268,6 +1277,7 @@ export class AgentContext {
|
|
|
1268
1277
|
this.summaryPrecedesMessages = this.durableSummaryPrecedesMessages;
|
|
1269
1278
|
this._lastSummarizationMsgCount = 0;
|
|
1270
1279
|
this._summarizationFailures = 0;
|
|
1280
|
+
this._manualSummarizationRequested = false;
|
|
1271
1281
|
this.lastCallUsage = undefined;
|
|
1272
1282
|
this.totalTokensFresh = false;
|
|
1273
1283
|
this.restoreContextBudgetAfterOverflow();
|
|
@@ -1617,6 +1627,20 @@ export class AgentContext {
|
|
|
1617
1627
|
this._lastSummarizationMsgCount = msgCount;
|
|
1618
1628
|
}
|
|
1619
1629
|
|
|
1630
|
+
/**
|
|
1631
|
+
* Claims the single summarization request a summarize-only run makes.
|
|
1632
|
+
* True exactly once per run, on the first model step; the step that gets
|
|
1633
|
+
* `false` is the one after the summary, which reports usage and ends
|
|
1634
|
+
* without a model call. Always false when `summarizeOnly` is off.
|
|
1635
|
+
*/
|
|
1636
|
+
claimManualSummarization(): boolean {
|
|
1637
|
+
if (this.summarizeOnly !== true || this._manualSummarizationRequested) {
|
|
1638
|
+
return false;
|
|
1639
|
+
}
|
|
1640
|
+
this._manualSummarizationRequested = true;
|
|
1641
|
+
return true;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1620
1644
|
/**
|
|
1621
1645
|
* Records a summarization attempt that produced no usable summary — an
|
|
1622
1646
|
* empty model response, or a provider failure the run declined to paper
|
|
@@ -1767,8 +1791,9 @@ export class AgentContext {
|
|
|
1767
1791
|
const recounted: Record<string, number> = {};
|
|
1768
1792
|
for (let i = 0; i < messages.length; i++) {
|
|
1769
1793
|
const localCount = this.tokenCounter(messages[i]);
|
|
1770
|
-
const conservativeFloor =
|
|
1771
|
-
|
|
1794
|
+
const conservativeFloor = this.providerProjectionRecountFloors?.get(
|
|
1795
|
+
messages[i]
|
|
1796
|
+
);
|
|
1772
1797
|
recounted[i] =
|
|
1773
1798
|
conservativeFloor == null
|
|
1774
1799
|
? localCount
|
|
@@ -2112,7 +2137,13 @@ export class AgentContext {
|
|
|
2112
2137
|
remainingContextTokens,
|
|
2113
2138
|
calibrationRatio,
|
|
2114
2139
|
};
|
|
2115
|
-
syncBudgetDerivedFields(
|
|
2140
|
+
syncBudgetDerivedFields(
|
|
2141
|
+
usage,
|
|
2142
|
+
context,
|
|
2143
|
+
this.contextPressureTokenCounts?.count ?? tokenCounter,
|
|
2144
|
+
undefined,
|
|
2145
|
+
this.provider
|
|
2146
|
+
);
|
|
2116
2147
|
return usage;
|
|
2117
2148
|
}
|
|
2118
2149
|
|