@librechat/agents 3.2.36 → 3.2.38
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 +1 -1
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +7 -8
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +16 -5
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +7 -0
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +92 -3
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +24 -4
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/main.cjs +2 -0
- package/dist/cjs/messages/cache.cjs +183 -0
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +1 -1
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +28 -14
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +2 -2
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +8 -9
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +16 -5
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +7 -0
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +92 -3
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +24 -4
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -2
- package/dist/esm/messages/cache.mjs +182 -1
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +2 -2
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +28 -14
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/types/messages/cache.d.ts +40 -0
- package/dist/types/types/graph.d.ts +2 -0
- package/package.json +8 -5
- package/src/agents/AgentContext.ts +2 -2
- package/src/agents/__tests__/AgentContext.test.ts +3 -9
- package/src/graphs/Graph.ts +65 -36
- package/src/langfuse.ts +38 -4
- package/src/langfuseToolOutputTracing.ts +18 -0
- package/src/llm/anthropic/utils/message_inputs.ts +131 -3
- package/src/llm/anthropic/utils/stripPrefillCache.test.ts +111 -0
- package/src/llm/bedrock/utils/message_inputs.test.ts +129 -0
- package/src/llm/bedrock/utils/message_inputs.ts +46 -4
- package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +103 -0
- package/src/messages/cache.tail.test.ts +340 -0
- package/src/messages/cache.ts +266 -0
- package/src/messages/tailCacheConversion.test.ts +161 -0
- package/src/scripts/bench-prompt-cache.ts +479 -0
- package/src/specs/langfuse-config.test.ts +69 -2
- package/src/specs/langfuse-metadata.test.ts +44 -0
- package/src/specs/langfuse-tool-output-tracing.test.ts +6 -0
- package/src/summarization/node.ts +2 -2
- package/src/tools/__tests__/annotateMessagesForLLM.test.ts +50 -0
- package/src/tools/toolOutputReferences.ts +34 -20
- package/src/types/graph.ts +2 -0
|
@@ -173,6 +173,56 @@ describe('annotateMessagesForLLM', () => {
|
|
|
173
173
|
expect(out[0].content).toBe('[ref: tool0turn0]\nplain output');
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
+
it('annotates a live ref on multi-part content (prompt-cache-rewritten tool tail)', () => {
|
|
177
|
+
/**
|
|
178
|
+
* A tail tool result that prompt caching rewrote from a string into a
|
|
179
|
+
* text-block array (to host the cache_control / cachePoint marker) keeps
|
|
180
|
+
* its `_refKey` on additional_kwargs. The live-ref marker must still be
|
|
181
|
+
* projected as a leading text block; otherwise the common tool-result
|
|
182
|
+
* tail silently loses its reference annotation once cached.
|
|
183
|
+
*/
|
|
184
|
+
const registry = new ToolOutputReferenceRegistry();
|
|
185
|
+
registry.set('r1', 'tool0turn0', 'raw');
|
|
186
|
+
const tm = makeToolMessage({
|
|
187
|
+
content: [
|
|
188
|
+
{ type: 'text', text: 'output', cache_control: { type: 'ephemeral' } },
|
|
189
|
+
] as unknown as ToolMessage['content'],
|
|
190
|
+
additional_kwargs: { _refKey: 'tool0turn0' },
|
|
191
|
+
});
|
|
192
|
+
const out = annotateMessagesForLLM([tm], registry, 'r1');
|
|
193
|
+
const blocks = out[0].content as Array<{
|
|
194
|
+
type: string;
|
|
195
|
+
text?: string;
|
|
196
|
+
cache_control?: unknown;
|
|
197
|
+
}>;
|
|
198
|
+
expect(blocks).toHaveLength(2);
|
|
199
|
+
expect(blocks[0]).toEqual({ type: 'text', text: '[ref: tool0turn0]' });
|
|
200
|
+
// The original block (and its cache marker) is preserved after the prefix.
|
|
201
|
+
expect(blocks[1].text).toBe('output');
|
|
202
|
+
expect(blocks[1].cache_control).toEqual({ type: 'ephemeral' });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('annotates both live ref and unresolved on multi-part content', () => {
|
|
206
|
+
const registry = new ToolOutputReferenceRegistry();
|
|
207
|
+
registry.set('r1', 'tool0turn0', 'raw');
|
|
208
|
+
const tm = makeToolMessage({
|
|
209
|
+
content: [
|
|
210
|
+
{ type: 'text', text: 'output' },
|
|
211
|
+
] as unknown as ToolMessage['content'],
|
|
212
|
+
additional_kwargs: {
|
|
213
|
+
_refKey: 'tool0turn0',
|
|
214
|
+
_unresolvedRefs: ['tool9turn9'],
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
const out = annotateMessagesForLLM([tm], registry, 'r1');
|
|
218
|
+
const blocks = out[0].content as Array<{ type: string; text?: string }>;
|
|
219
|
+
expect(blocks.map((b) => b.text)).toEqual([
|
|
220
|
+
'[ref: tool0turn0]',
|
|
221
|
+
'[unresolved refs: tool9turn9]',
|
|
222
|
+
'output',
|
|
223
|
+
]);
|
|
224
|
+
});
|
|
225
|
+
|
|
176
226
|
it('prepends an unresolved-refs warning text block to multi-part content', () => {
|
|
177
227
|
const registry = new ToolOutputReferenceRegistry();
|
|
178
228
|
const tm = makeToolMessage({
|
|
@@ -682,28 +682,42 @@ export function annotateMessagesForLLM(
|
|
|
682
682
|
liveRef,
|
|
683
683
|
unresolved
|
|
684
684
|
);
|
|
685
|
-
} else if (
|
|
686
|
-
annotates &&
|
|
687
|
-
Array.isArray(tm.content) &&
|
|
688
|
-
unresolved.length > 0
|
|
689
|
-
) {
|
|
690
|
-
const warningBlock = {
|
|
691
|
-
type: 'text' as const,
|
|
692
|
-
text: `[unresolved refs: ${unresolved.join(', ')}]`,
|
|
693
|
-
};
|
|
685
|
+
} else if (annotates && Array.isArray(tm.content)) {
|
|
694
686
|
/**
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
687
|
+
* Array tool content. The string annotator can't run — this notably
|
|
688
|
+
* includes a tail tool result that prompt caching rewrote from a string
|
|
689
|
+
* into a text-block array to host its `cache_control` / `cachePoint`
|
|
690
|
+
* marker (the `_refKey` survives on `additional_kwargs`). Project the
|
|
691
|
+
* same markers the string path would, as leading text blocks: the live
|
|
692
|
+
* `[ref: …]` prefix and/or the unresolved-refs warning. Without this the
|
|
693
|
+
* common tool-result tail loses its reference marker once cached.
|
|
694
|
+
*
|
|
695
|
+
* `as unknown as ToolMessage['content']` is unavoidable: LangChain's
|
|
696
|
+
* content union does not accept a freshly built mixed array literal even
|
|
697
|
+
* though the structural shape is valid at runtime. The double-cast is
|
|
698
|
+
* structurally safe — every original block is preserved and only
|
|
699
|
+
* `{ type: 'text', text }` blocks (which all providers accept) are
|
|
700
|
+
* prepended.
|
|
702
701
|
*/
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
702
|
+
const prefixBlocks: Array<{ type: 'text'; text: string }> = [];
|
|
703
|
+
if (liveRef != null) {
|
|
704
|
+
prefixBlocks.push({
|
|
705
|
+
type: 'text',
|
|
706
|
+
text: buildReferencePrefix(liveRef),
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
if (unresolved.length > 0) {
|
|
710
|
+
prefixBlocks.push({
|
|
711
|
+
type: 'text',
|
|
712
|
+
text: `[unresolved refs: ${unresolved.join(', ')}]`,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
if (prefixBlocks.length > 0) {
|
|
716
|
+
nextContent = [
|
|
717
|
+
...prefixBlocks,
|
|
718
|
+
...tm.content,
|
|
719
|
+
] as unknown as ToolMessage['content'];
|
|
720
|
+
}
|
|
707
721
|
}
|
|
708
722
|
|
|
709
723
|
/**
|
package/src/types/graph.ts
CHANGED
|
@@ -536,6 +536,8 @@ export interface LangfuseConfig {
|
|
|
536
536
|
publicKey?: string;
|
|
537
537
|
secretKey?: string;
|
|
538
538
|
baseUrl?: string;
|
|
539
|
+
metadata?: Record<string, string | number | boolean | null | undefined>;
|
|
540
|
+
tags?: string[];
|
|
539
541
|
toolNodeTracing?: LangfuseToolNodeTracingConfig;
|
|
540
542
|
toolOutputTracing?: LangfuseToolOutputTracingConfig;
|
|
541
543
|
/**
|