@illuma-ai/agents 1.5.1 → 2.1.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/README.md +0 -62
- package/dist/cjs/agents/AgentContext.cjs +160 -259
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +12 -12
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +30 -13
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs +1 -1
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs.map +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs +1 -1
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/matchers.cjs +2 -2
- package/dist/cjs/hooks/matchers.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +1 -1
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -5
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +33 -61
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +10 -27
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +3 -84
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/memory/citations.cjs +4 -4
- package/dist/cjs/memory/citations.cjs.map +1 -1
- package/dist/cjs/memory/constants.cjs +17 -17
- package/dist/cjs/memory/constants.cjs.map +1 -1
- package/dist/cjs/memory/mmr.cjs +1 -1
- package/dist/cjs/memory/mmr.cjs.map +1 -1
- package/dist/cjs/memory/paths.cjs +1 -1
- package/dist/cjs/memory/paths.cjs.map +1 -1
- package/dist/cjs/memory/recallTracking.cjs +3 -3
- package/dist/cjs/memory/recallTracking.cjs.map +1 -1
- package/dist/cjs/memory/temporalDecay.cjs +2 -2
- package/dist/cjs/memory/temporalDecay.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +0 -89
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +13 -71
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +11 -21
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +13 -41
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +11 -16
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +78 -13
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/memory/memoryAppendTool.cjs +1 -1
- package/dist/cjs/tools/memory/memoryAppendTool.cjs.map +1 -1
- package/dist/cjs/tools/memory/memoryGetTool.cjs +2 -2
- package/dist/cjs/tools/memory/memoryGetTool.cjs.map +1 -1
- package/dist/cjs/tools/memory/memorySearchTool.cjs +3 -3
- package/dist/cjs/tools/memory/memorySearchTool.cjs.map +1 -1
- package/dist/cjs/tools/memory/shared.cjs +1 -1
- package/dist/cjs/tools/memory/shared.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +3 -11
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +4 -28
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +3 -10
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +48 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/types/graph.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +160 -259
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +12 -12
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +30 -13
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs +1 -1
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs.map +1 -1
- package/dist/esm/hooks/HookRegistry.mjs +1 -1
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/matchers.mjs +2 -2
- package/dist/esm/hooks/matchers.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +1 -1
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -5
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +34 -61
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +10 -27
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -5
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/memory/citations.mjs +4 -4
- package/dist/esm/memory/citations.mjs.map +1 -1
- package/dist/esm/memory/constants.mjs +17 -17
- package/dist/esm/memory/constants.mjs.map +1 -1
- package/dist/esm/memory/mmr.mjs +1 -1
- package/dist/esm/memory/mmr.mjs.map +1 -1
- package/dist/esm/memory/paths.mjs +1 -1
- package/dist/esm/memory/paths.mjs.map +1 -1
- package/dist/esm/memory/recallTracking.mjs +3 -3
- package/dist/esm/memory/recallTracking.mjs.map +1 -1
- package/dist/esm/memory/temporalDecay.mjs +2 -2
- package/dist/esm/memory/temporalDecay.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +0 -89
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +13 -71
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +12 -22
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +14 -41
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +12 -17
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +78 -13
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/memory/memoryAppendTool.mjs +1 -1
- package/dist/esm/tools/memory/memoryAppendTool.mjs.map +1 -1
- package/dist/esm/tools/memory/memoryGetTool.mjs +2 -2
- package/dist/esm/tools/memory/memoryGetTool.mjs.map +1 -1
- package/dist/esm/tools/memory/memorySearchTool.mjs +3 -3
- package/dist/esm/tools/memory/memorySearchTool.mjs.map +1 -1
- package/dist/esm/tools/memory/shared.mjs +1 -1
- package/dist/esm/tools/memory/shared.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +3 -11
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +4 -28
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +3 -10
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +48 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/types/graph.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +25 -95
- package/dist/types/common/enum.d.ts +12 -12
- package/dist/types/graphs/Graph.d.ts +2 -2
- package/dist/types/graphs/phases/memoryFlushPhase.d.ts +2 -2
- package/dist/types/hooks/HookRegistry.d.ts +1 -1
- package/dist/types/hooks/matchers.d.ts +2 -2
- package/dist/types/hooks/types.d.ts +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/llm/bedrock/index.d.ts +1 -54
- package/dist/types/llm/openai/index.d.ts +1 -1
- package/dist/types/memory/citations.d.ts +4 -4
- package/dist/types/memory/constants.d.ts +17 -17
- package/dist/types/memory/mmr.d.ts +3 -3
- package/dist/types/memory/paths.d.ts +1 -1
- package/dist/types/memory/temporalDecay.d.ts +2 -2
- package/dist/types/memory/types.d.ts +3 -3
- package/dist/types/messages/format.d.ts +2 -5
- package/dist/types/tools/CodeExecutor.d.ts +0 -6
- package/dist/types/tools/ToolNode.d.ts +3 -3
- package/dist/types/tools/memory/shared.d.ts +1 -1
- package/dist/types/tools/search/test.d.ts +1 -0
- package/dist/types/tools/search/types.d.ts +5 -99
- package/dist/types/tools/search/utils.d.ts +2 -2
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +29 -0
- package/dist/types/types/graph.d.ts +30 -34
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/messages.d.ts +1 -1
- package/dist/types/types/run.d.ts +1 -3
- package/dist/types/types/tools.d.ts +5 -14
- package/package.json +1 -61
- package/src/agents/AgentContext.test.ts +176 -0
- package/src/agents/AgentContext.ts +179 -305
- package/src/agents/__tests__/AgentContext.test.ts +0 -632
- package/src/common/__tests__/enum.test.ts +1 -1
- package/src/common/enum.ts +12 -12
- package/src/graphs/Graph.ts +32 -13
- package/src/graphs/MultiAgentGraph.ts +1 -1
- package/src/graphs/gapFeatures.test.ts +1 -1
- package/src/graphs/phases/__tests__/memoryFlushPhase.test.ts +1 -1
- package/src/graphs/phases/memoryFlushPhase.ts +2 -2
- package/src/hooks/HookRegistry.ts +1 -1
- package/src/hooks/index.ts +1 -1
- package/src/hooks/matchers.ts +2 -2
- package/src/hooks/types.ts +1 -1
- package/src/index.ts +0 -6
- package/src/llm/anthropic/utils/message_inputs.ts +1 -10
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +18 -166
- package/src/llm/bedrock/index.ts +41 -116
- package/src/llm/openai/index.ts +2 -2
- package/src/llm/openai/utils/index.ts +14 -31
- package/src/memory/citations.ts +4 -4
- package/src/memory/constants.ts +17 -17
- package/src/memory/mmr.ts +3 -3
- package/src/memory/paths.ts +1 -1
- package/src/memory/recallTracking.ts +3 -3
- package/src/memory/temporalDecay.ts +2 -2
- package/src/memory/types.ts +3 -3
- package/src/messages/cache.test.ts +24 -62
- package/src/messages/cache.ts +0 -112
- package/src/messages/ensureThinkingBlock.test.ts +1 -1
- package/src/messages/format.ts +13 -92
- package/src/messages/formatAgentMessages.test.ts +1 -1
- package/src/scripts/subagent-configurable-inheritance.ts +263 -0
- package/src/scripts/subagent-event-driven-debug.ts +2 -2
- package/src/specs/anthropic.simple.test.ts +0 -61
- package/src/specs/prune.orphans.test.ts +1 -1
- package/src/tools/BashExecutor.ts +13 -37
- package/src/tools/CodeExecutor.ts +14 -59
- package/src/tools/ProgrammaticToolCalling.ts +14 -29
- package/src/tools/ToolNode.ts +75 -14
- package/src/tools/__tests__/CodeExecutor.test.ts +3 -3
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -60
- package/src/tools/__tests__/SubagentExecutor.test.ts +157 -0
- package/src/tools/memory/memoryAppendTool.ts +1 -1
- package/src/tools/memory/memoryGetTool.ts +2 -2
- package/src/tools/memory/memorySearchTool.ts +3 -3
- package/src/tools/memory/shared.ts +1 -1
- package/src/tools/search/output.md +2775 -0
- package/src/tools/search/search.ts +2 -12
- package/src/tools/search/test.html +884 -0
- package/src/tools/search/test.md +643 -0
- package/src/tools/search/test.ts +159 -0
- package/src/tools/search/tool.ts +2 -36
- package/src/tools/search/types.ts +8 -133
- package/src/tools/search/utils.ts +5 -13
- package/src/tools/subagent/SubagentExecutor.ts +78 -0
- package/src/types/graph.ts +27 -34
- package/src/types/index.ts +0 -1
- package/src/types/messages.ts +1 -1
- package/src/types/run.ts +1 -3
- package/src/types/tools.ts +5 -14
- package/dist/cjs/langchain/google-common.cjs +0 -3
- package/dist/cjs/langchain/google-common.cjs.map +0 -1
- package/dist/cjs/langchain/index.cjs +0 -86
- package/dist/cjs/langchain/index.cjs.map +0 -1
- package/dist/cjs/langchain/language_models/chat_models.cjs +0 -3
- package/dist/cjs/langchain/language_models/chat_models.cjs.map +0 -1
- package/dist/cjs/langchain/messages/tool.cjs +0 -3
- package/dist/cjs/langchain/messages/tool.cjs.map +0 -1
- package/dist/cjs/langchain/messages.cjs +0 -51
- package/dist/cjs/langchain/messages.cjs.map +0 -1
- package/dist/cjs/langchain/openai.cjs +0 -3
- package/dist/cjs/langchain/openai.cjs.map +0 -1
- package/dist/cjs/langchain/prompts.cjs +0 -11
- package/dist/cjs/langchain/prompts.cjs.map +0 -1
- package/dist/cjs/langchain/runnables.cjs +0 -19
- package/dist/cjs/langchain/runnables.cjs.map +0 -1
- package/dist/cjs/langchain/tools.cjs +0 -23
- package/dist/cjs/langchain/tools.cjs.map +0 -1
- package/dist/cjs/langchain/utils/env.cjs +0 -11
- package/dist/cjs/langchain/utils/env.cjs.map +0 -1
- package/dist/cjs/llm/bedrock/cacheSupport.cjs +0 -55
- package/dist/cjs/llm/bedrock/cacheSupport.cjs.map +0 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs +0 -189
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +0 -1
- package/dist/cjs/tools/search/tavily-search.cjs +0 -372
- package/dist/cjs/tools/search/tavily-search.cjs.map +0 -1
- package/dist/cjs/types/agent-cache.cjs +0 -54
- package/dist/cjs/types/agent-cache.cjs.map +0 -1
- package/dist/esm/langchain/google-common.mjs +0 -2
- package/dist/esm/langchain/google-common.mjs.map +0 -1
- package/dist/esm/langchain/index.mjs +0 -5
- package/dist/esm/langchain/index.mjs.map +0 -1
- package/dist/esm/langchain/language_models/chat_models.mjs +0 -2
- package/dist/esm/langchain/language_models/chat_models.mjs.map +0 -1
- package/dist/esm/langchain/messages/tool.mjs +0 -2
- package/dist/esm/langchain/messages/tool.mjs.map +0 -1
- package/dist/esm/langchain/messages.mjs +0 -2
- package/dist/esm/langchain/messages.mjs.map +0 -1
- package/dist/esm/langchain/openai.mjs +0 -2
- package/dist/esm/langchain/openai.mjs.map +0 -1
- package/dist/esm/langchain/prompts.mjs +0 -2
- package/dist/esm/langchain/prompts.mjs.map +0 -1
- package/dist/esm/langchain/runnables.mjs +0 -2
- package/dist/esm/langchain/runnables.mjs.map +0 -1
- package/dist/esm/langchain/tools.mjs +0 -2
- package/dist/esm/langchain/tools.mjs.map +0 -1
- package/dist/esm/langchain/utils/env.mjs +0 -2
- package/dist/esm/langchain/utils/env.mjs.map +0 -1
- package/dist/esm/llm/bedrock/cacheSupport.mjs +0 -52
- package/dist/esm/llm/bedrock/cacheSupport.mjs.map +0 -1
- package/dist/esm/tools/search/tavily-scraper.mjs +0 -186
- package/dist/esm/tools/search/tavily-scraper.mjs.map +0 -1
- package/dist/esm/tools/search/tavily-search.mjs +0 -370
- package/dist/esm/tools/search/tavily-search.mjs.map +0 -1
- package/dist/esm/types/agent-cache.mjs +0 -52
- package/dist/esm/types/agent-cache.mjs.map +0 -1
- package/dist/types/langchain/google-common.d.ts +0 -1
- package/dist/types/langchain/index.d.ts +0 -8
- package/dist/types/langchain/language_models/chat_models.d.ts +0 -1
- package/dist/types/langchain/messages/tool.d.ts +0 -1
- package/dist/types/langchain/messages.d.ts +0 -2
- package/dist/types/langchain/openai.d.ts +0 -1
- package/dist/types/langchain/prompts.d.ts +0 -1
- package/dist/types/langchain/runnables.d.ts +0 -2
- package/dist/types/langchain/tools.d.ts +0 -2
- package/dist/types/langchain/utils/env.d.ts +0 -1
- package/dist/types/llm/bedrock/cacheSupport.d.ts +0 -35
- package/dist/types/tools/search/tavily-scraper.d.ts +0 -19
- package/dist/types/tools/search/tavily-search.d.ts +0 -4
- package/dist/types/tools/subagent/types.d.ts +0 -84
- package/dist/types/types/agent-cache.d.ts +0 -71
- package/src/agents/__tests__/AgentContext.cacheTtl.live.test.ts +0 -259
- package/src/agents/__tests__/AgentContext.crossAgentTier1.live.test.ts +0 -266
- package/src/agents/__tests__/AgentContext.crossUserCache.live.test.ts +0 -342
- package/src/langchain/google-common.ts +0 -1
- package/src/langchain/index.ts +0 -8
- package/src/langchain/language_models/chat_models.ts +0 -1
- package/src/langchain/messages/tool.ts +0 -5
- package/src/langchain/messages.ts +0 -21
- package/src/langchain/openai.ts +0 -1
- package/src/langchain/prompts.ts +0 -1
- package/src/langchain/runnables.ts +0 -7
- package/src/langchain/tools.ts +0 -8
- package/src/langchain/utils/env.ts +0 -1
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -436
- package/src/llm/bedrock/cacheSupport.test.ts +0 -99
- package/src/llm/bedrock/cacheSupport.ts +0 -53
- package/src/tools/search/tavily-scraper.ts +0 -235
- package/src/tools/search/tavily-search.ts +0 -424
- package/src/tools/search/tavily.test.ts +0 -965
- package/src/tools/subagent/types.test.ts +0 -70
- package/src/tools/subagent/types.ts +0 -115
- package/src/types/agent-cache.ts +0 -74
|
@@ -375,638 +375,6 @@ describe('AgentContext', () => {
|
|
|
375
375
|
|
|
376
376
|
expect(ctx.instructionTokens).toBeGreaterThan(initialTokens);
|
|
377
377
|
});
|
|
378
|
-
|
|
379
|
-
it('excludes deferred-undiscovered instance tools from token accounting', async () => {
|
|
380
|
-
/* Regression for #122 / #121.
|
|
381
|
-
* `calculateInstructionTokens` previously summed every entry in
|
|
382
|
-
* `this.tools` regardless of whether `getToolsForBinding` would
|
|
383
|
-
* actually emit it. That over-reported tokens and triggered
|
|
384
|
-
* spurious empty_messages preflight rejections. */
|
|
385
|
-
const deferredTool = createMockTool('deferred_tool');
|
|
386
|
-
const directTool = createMockTool('direct_tool');
|
|
387
|
-
const toolRegistry: t.LCToolRegistry = new Map([
|
|
388
|
-
[
|
|
389
|
-
'deferred_tool',
|
|
390
|
-
{
|
|
391
|
-
name: 'deferred_tool',
|
|
392
|
-
description: 'deferred',
|
|
393
|
-
defer_loading: true,
|
|
394
|
-
},
|
|
395
|
-
],
|
|
396
|
-
[
|
|
397
|
-
'direct_tool',
|
|
398
|
-
{
|
|
399
|
-
name: 'direct_tool',
|
|
400
|
-
description: 'direct',
|
|
401
|
-
},
|
|
402
|
-
],
|
|
403
|
-
]);
|
|
404
|
-
|
|
405
|
-
const ctxBase = createBasicContext({
|
|
406
|
-
agentConfig: {
|
|
407
|
-
instructions: 'Test',
|
|
408
|
-
tools: [directTool],
|
|
409
|
-
toolRegistry,
|
|
410
|
-
},
|
|
411
|
-
tokenCounter: mockTokenCounter,
|
|
412
|
-
});
|
|
413
|
-
await ctxBase.calculateInstructionTokens(mockTokenCounter);
|
|
414
|
-
const baseTokens = ctxBase.getContextBreakdown().tools;
|
|
415
|
-
|
|
416
|
-
const ctxWithDeferred = createBasicContext({
|
|
417
|
-
agentConfig: {
|
|
418
|
-
instructions: 'Test',
|
|
419
|
-
tools: [directTool, deferredTool],
|
|
420
|
-
toolRegistry,
|
|
421
|
-
},
|
|
422
|
-
tokenCounter: mockTokenCounter,
|
|
423
|
-
});
|
|
424
|
-
await ctxWithDeferred.calculateInstructionTokens(mockTokenCounter);
|
|
425
|
-
const withDeferredTokens = ctxWithDeferred.getContextBreakdown().tools;
|
|
426
|
-
|
|
427
|
-
/* The deferred tool is filtered out of the bound subset, so token
|
|
428
|
-
* accounting must match the direct-only baseline. */
|
|
429
|
-
expect(withDeferredTokens).toBe(baseTokens);
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
it('counts deferred instance tool after discovery', async () => {
|
|
433
|
-
const deferredTool = createMockTool('deferred_tool');
|
|
434
|
-
const toolRegistry: t.LCToolRegistry = new Map([
|
|
435
|
-
[
|
|
436
|
-
'deferred_tool',
|
|
437
|
-
{
|
|
438
|
-
name: 'deferred_tool',
|
|
439
|
-
description: 'deferred',
|
|
440
|
-
defer_loading: true,
|
|
441
|
-
},
|
|
442
|
-
],
|
|
443
|
-
]);
|
|
444
|
-
|
|
445
|
-
const ctxUndiscovered = createBasicContext({
|
|
446
|
-
agentConfig: {
|
|
447
|
-
instructions: 'Test',
|
|
448
|
-
tools: [deferredTool],
|
|
449
|
-
toolRegistry,
|
|
450
|
-
},
|
|
451
|
-
tokenCounter: mockTokenCounter,
|
|
452
|
-
});
|
|
453
|
-
await ctxUndiscovered.calculateInstructionTokens(mockTokenCounter);
|
|
454
|
-
expect(ctxUndiscovered.getContextBreakdown().tools).toBe(0);
|
|
455
|
-
|
|
456
|
-
const ctxDiscovered = createBasicContext({
|
|
457
|
-
agentConfig: {
|
|
458
|
-
instructions: 'Test',
|
|
459
|
-
tools: [deferredTool],
|
|
460
|
-
toolRegistry,
|
|
461
|
-
},
|
|
462
|
-
tokenCounter: mockTokenCounter,
|
|
463
|
-
});
|
|
464
|
-
ctxDiscovered.markToolsAsDiscovered(['deferred_tool']);
|
|
465
|
-
await ctxDiscovered.calculateInstructionTokens(mockTokenCounter);
|
|
466
|
-
expect(ctxDiscovered.getContextBreakdown().tools).toBeGreaterThan(0);
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it('excludes programmatic-only toolDefinitions from token accounting', async () => {
|
|
470
|
-
/* Programmatic-only tool definitions (allowed_callers: ['code_execution'])
|
|
471
|
-
* are never bound to the model — they were inflating toolSchemaTokens
|
|
472
|
-
* even though getEventDrivenToolsForBinding excludes them. */
|
|
473
|
-
const directDef: t.LCTool = {
|
|
474
|
-
name: 'direct_def',
|
|
475
|
-
description: 'direct schema',
|
|
476
|
-
parameters: { type: 'object', properties: {} },
|
|
477
|
-
allowed_callers: ['direct'],
|
|
478
|
-
};
|
|
479
|
-
const programmaticOnlyDef: t.LCTool = {
|
|
480
|
-
name: 'programmatic_only',
|
|
481
|
-
description: 'programmatic only schema',
|
|
482
|
-
parameters: { type: 'object', properties: {} },
|
|
483
|
-
allowed_callers: ['code_execution'],
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
const ctxBase = createBasicContext({
|
|
487
|
-
agentConfig: {
|
|
488
|
-
instructions: 'Test',
|
|
489
|
-
toolDefinitions: [directDef],
|
|
490
|
-
},
|
|
491
|
-
tokenCounter: mockTokenCounter,
|
|
492
|
-
});
|
|
493
|
-
await ctxBase.calculateInstructionTokens(mockTokenCounter);
|
|
494
|
-
|
|
495
|
-
const ctxWithProgrammatic = createBasicContext({
|
|
496
|
-
agentConfig: {
|
|
497
|
-
instructions: 'Test',
|
|
498
|
-
toolDefinitions: [directDef, programmaticOnlyDef],
|
|
499
|
-
},
|
|
500
|
-
tokenCounter: mockTokenCounter,
|
|
501
|
-
});
|
|
502
|
-
await ctxWithProgrammatic.calculateInstructionTokens(mockTokenCounter);
|
|
503
|
-
|
|
504
|
-
expect(ctxWithProgrammatic.getContextBreakdown().tools).toBe(
|
|
505
|
-
ctxBase.getContextBreakdown().tools
|
|
506
|
-
);
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
describe('System message prompt cache markers', () => {
|
|
511
|
-
/* These tests assert the contract that `buildSystemRunnable` (invoked
|
|
512
|
-
* lazily via `systemRunnable`) emits provider-specific cache markers
|
|
513
|
-
* inline in the system message. This is the cross-account / cross-user
|
|
514
|
-
* cache-hit foundation: a stable system prefix shared across all users
|
|
515
|
-
* invoking the same agent maps to the same cache entry on Anthropic
|
|
516
|
-
* (workspace-scoped) and Bedrock (account-scoped). */
|
|
517
|
-
|
|
518
|
-
const captureSystemMessage = async (ctx: AgentContext) => {
|
|
519
|
-
const runnable = ctx.systemRunnable;
|
|
520
|
-
if (!runnable) {
|
|
521
|
-
throw new Error('systemRunnable returned undefined');
|
|
522
|
-
}
|
|
523
|
-
// Invoke the prompt runnable with an empty conversation to extract
|
|
524
|
-
// the prefixed system message. RunnableLambda is async.
|
|
525
|
-
const out = (await runnable.invoke([])) as Array<{ content: unknown }>;
|
|
526
|
-
return out[0];
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
it('Anthropic + promptCache: stable text gets cache_control: ephemeral', async () => {
|
|
530
|
-
const ctx = AgentContext.fromConfig({
|
|
531
|
-
agentId: 'a1',
|
|
532
|
-
provider: Providers.ANTHROPIC,
|
|
533
|
-
instructions: 'Stable agent instructions',
|
|
534
|
-
clientOptions: { promptCache: true } as t.AnthropicClientOptions,
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
const sys = await captureSystemMessage(ctx);
|
|
538
|
-
const content = sys.content as Array<{
|
|
539
|
-
type: string;
|
|
540
|
-
text?: string;
|
|
541
|
-
cache_control?: { type: string };
|
|
542
|
-
}>;
|
|
543
|
-
|
|
544
|
-
expect(Array.isArray(content)).toBe(true);
|
|
545
|
-
expect(content).toHaveLength(1);
|
|
546
|
-
expect(content[0].type).toBe('text');
|
|
547
|
-
expect(content[0].text).toBe('Stable agent instructions');
|
|
548
|
-
expect(content[0].cache_control).toEqual({ type: 'ephemeral', ttl: '5m' });
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it('Anthropic + promptCache: dynamic tail (additional_instructions) NOT marked', async () => {
|
|
552
|
-
const ctx = AgentContext.fromConfig({
|
|
553
|
-
agentId: 'a1',
|
|
554
|
-
provider: Providers.ANTHROPIC,
|
|
555
|
-
instructions: 'Stable agent instructions',
|
|
556
|
-
additional_instructions: 'Per-user dynamic context',
|
|
557
|
-
clientOptions: { promptCache: true } as t.AnthropicClientOptions,
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
const sys = await captureSystemMessage(ctx);
|
|
561
|
-
const content = sys.content as Array<{
|
|
562
|
-
type: string;
|
|
563
|
-
text?: string;
|
|
564
|
-
cache_control?: { type: string };
|
|
565
|
-
}>;
|
|
566
|
-
|
|
567
|
-
expect(content).toHaveLength(2);
|
|
568
|
-
expect(content[0].cache_control).toEqual({ type: 'ephemeral', ttl: '5m' });
|
|
569
|
-
expect(content[1].text).toBe('Per-user dynamic context');
|
|
570
|
-
expect(content[1].cache_control).toBeUndefined();
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
it('Bedrock Claude + promptCache: cachePoint inserted after stable text', async () => {
|
|
574
|
-
const ctx = AgentContext.fromConfig({
|
|
575
|
-
agentId: 'a1',
|
|
576
|
-
provider: Providers.BEDROCK,
|
|
577
|
-
instructions: 'Stable agent instructions',
|
|
578
|
-
clientOptions: {
|
|
579
|
-
promptCache: true,
|
|
580
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
581
|
-
} as t.BedrockAnthropicClientOptions,
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
const sys = await captureSystemMessage(ctx);
|
|
585
|
-
const content = sys.content as Array<
|
|
586
|
-
{ type: string; text?: string } | { cachePoint: { type: string } }
|
|
587
|
-
>;
|
|
588
|
-
|
|
589
|
-
expect(content).toHaveLength(2);
|
|
590
|
-
expect(content[0]).toEqual({
|
|
591
|
-
type: 'text',
|
|
592
|
-
text: 'Stable agent instructions',
|
|
593
|
-
});
|
|
594
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
it('Bedrock Claude + promptCache + dynamic: cachePoint between stable and dynamic', async () => {
|
|
598
|
-
const ctx = AgentContext.fromConfig({
|
|
599
|
-
agentId: 'a1',
|
|
600
|
-
provider: Providers.BEDROCK,
|
|
601
|
-
instructions: 'Stable agent instructions',
|
|
602
|
-
additional_instructions: 'Per-user dynamic context',
|
|
603
|
-
clientOptions: {
|
|
604
|
-
promptCache: true,
|
|
605
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
606
|
-
} as t.BedrockAnthropicClientOptions,
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
const sys = await captureSystemMessage(ctx);
|
|
610
|
-
const content = sys.content as Array<
|
|
611
|
-
{ type: string; text?: string } | { cachePoint: { type: string } }
|
|
612
|
-
>;
|
|
613
|
-
|
|
614
|
-
expect(content).toHaveLength(3);
|
|
615
|
-
expect((content[0] as { text: string }).text).toBe(
|
|
616
|
-
'Stable agent instructions'
|
|
617
|
-
);
|
|
618
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
619
|
-
expect((content[2] as { text: string }).text).toBe(
|
|
620
|
-
'Per-user dynamic context'
|
|
621
|
-
);
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
it('Bedrock Llama: NO cachePoint (model does not support it)', async () => {
|
|
625
|
-
const ctx = AgentContext.fromConfig({
|
|
626
|
-
agentId: 'a1',
|
|
627
|
-
provider: Providers.BEDROCK,
|
|
628
|
-
instructions: 'Stable agent instructions',
|
|
629
|
-
clientOptions: {
|
|
630
|
-
promptCache: true,
|
|
631
|
-
model: 'meta.llama3-1-405b-instruct-v1:0',
|
|
632
|
-
} as t.BedrockAnthropicClientOptions,
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
const sys = await captureSystemMessage(ctx);
|
|
636
|
-
// Falls through to plain string when neither Anthropic nor a
|
|
637
|
-
// cache-capable Bedrock model is configured.
|
|
638
|
-
expect(typeof sys.content).toBe('string');
|
|
639
|
-
expect(sys.content).toBe('Stable agent instructions');
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
it('Bedrock + promptCache=false: NO cachePoint', async () => {
|
|
643
|
-
const ctx = AgentContext.fromConfig({
|
|
644
|
-
agentId: 'a1',
|
|
645
|
-
provider: Providers.BEDROCK,
|
|
646
|
-
instructions: 'Stable agent instructions',
|
|
647
|
-
clientOptions: {
|
|
648
|
-
promptCache: false,
|
|
649
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
650
|
-
} as t.BedrockAnthropicClientOptions,
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
const sys = await captureSystemMessage(ctx);
|
|
654
|
-
expect(typeof sys.content).toBe('string');
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
it('Anthropic without promptCache: plain string system content', async () => {
|
|
658
|
-
const ctx = AgentContext.fromConfig({
|
|
659
|
-
agentId: 'a1',
|
|
660
|
-
provider: Providers.ANTHROPIC,
|
|
661
|
-
instructions: 'Stable agent instructions',
|
|
662
|
-
clientOptions: { promptCache: false } as t.AnthropicClientOptions,
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
const sys = await captureSystemMessage(ctx);
|
|
666
|
-
expect(typeof sys.content).toBe('string');
|
|
667
|
-
expect(sys.content).toBe('Stable agent instructions');
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
it('Cross-user cache stability: identical agent → identical cacheable system block', async () => {
|
|
671
|
-
/* This is the load-bearing test for the cross-user cost win.
|
|
672
|
-
* Two AgentContext instances with the same agent.instructions but
|
|
673
|
-
* DIFFERENT additional_instructions (per-user dynamic context) MUST
|
|
674
|
-
* produce a byte-identical FIRST content block — the cache prefix.
|
|
675
|
-
* Bedrock and Anthropic both key the cache off the stable prefix. */
|
|
676
|
-
const baseConfig = {
|
|
677
|
-
agentId: 'a1',
|
|
678
|
-
provider: Providers.ANTHROPIC,
|
|
679
|
-
instructions: 'Stable agent instructions for ALL users',
|
|
680
|
-
clientOptions: { promptCache: true } as t.AnthropicClientOptions,
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
const ctxAlice = AgentContext.fromConfig({
|
|
684
|
-
...baseConfig,
|
|
685
|
-
additional_instructions: 'Hi Alice. Memory: A, B, C.',
|
|
686
|
-
});
|
|
687
|
-
const ctxBob = AgentContext.fromConfig({
|
|
688
|
-
...baseConfig,
|
|
689
|
-
additional_instructions: 'Hi Bob. Memory: X, Y, Z.',
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
const sysAlice = await captureSystemMessage(ctxAlice);
|
|
693
|
-
const sysBob = await captureSystemMessage(ctxBob);
|
|
694
|
-
|
|
695
|
-
const contentAlice = sysAlice.content as Array<{
|
|
696
|
-
type: string;
|
|
697
|
-
text: string;
|
|
698
|
-
cache_control?: { type: string };
|
|
699
|
-
}>;
|
|
700
|
-
const contentBob = sysBob.content as Array<{
|
|
701
|
-
type: string;
|
|
702
|
-
text: string;
|
|
703
|
-
cache_control?: { type: string };
|
|
704
|
-
}>;
|
|
705
|
-
|
|
706
|
-
// Stable prefix is BYTE-IDENTICAL → same cache entry.
|
|
707
|
-
expect(contentAlice[0]).toEqual(contentBob[0]);
|
|
708
|
-
|
|
709
|
-
// Dynamic tail differs but is NOT cache-marked.
|
|
710
|
-
expect(contentAlice[1].text).not.toBe(contentBob[1].text);
|
|
711
|
-
expect(contentAlice[1].cache_control).toBeUndefined();
|
|
712
|
-
expect(contentBob[1].cache_control).toBeUndefined();
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
describe('System cache blocks (multi-cachePoint emission)', () => {
|
|
717
|
-
/* Verifies the generic multi-cachePoint primitive. Consumers compose
|
|
718
|
-
* cacheable blocks via `system_cache_blocks` and the library encodes
|
|
719
|
-
* provider-specific cache markers around each. See
|
|
720
|
-
* src/types/agent-cache.ts for the contract. */
|
|
721
|
-
|
|
722
|
-
const captureSystemMessage = async (ctx: AgentContext) => {
|
|
723
|
-
const runnable = ctx.systemRunnable;
|
|
724
|
-
if (!runnable) {
|
|
725
|
-
throw new Error('systemRunnable returned undefined');
|
|
726
|
-
}
|
|
727
|
-
const out = (await runnable.invoke([])) as Array<{ content: unknown }>;
|
|
728
|
-
return out[0];
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
it('Anthropic with one cache block + instructions + dynamic: emits 3 cache_control blocks', async () => {
|
|
732
|
-
const ctx = AgentContext.fromConfig({
|
|
733
|
-
agentId: 'a1',
|
|
734
|
-
provider: Providers.ANTHROPIC,
|
|
735
|
-
system_cache_blocks: [{ text: 'Outer cacheable prefix.' }],
|
|
736
|
-
instructions: 'Agent-specific stable.',
|
|
737
|
-
additional_instructions: 'Dynamic per-user.',
|
|
738
|
-
clientOptions: { promptCache: true } as t.AnthropicClientOptions,
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
const sys = await captureSystemMessage(ctx);
|
|
742
|
-
const content = sys.content as Array<{
|
|
743
|
-
type: string;
|
|
744
|
-
text: string;
|
|
745
|
-
cache_control?: { type: string; ttl?: string };
|
|
746
|
-
}>;
|
|
747
|
-
|
|
748
|
-
expect(content).toHaveLength(3);
|
|
749
|
-
expect(content[0].text).toBe('Outer cacheable prefix.');
|
|
750
|
-
expect(content[0].cache_control).toEqual({
|
|
751
|
-
type: 'ephemeral',
|
|
752
|
-
ttl: '5m',
|
|
753
|
-
});
|
|
754
|
-
expect(content[1].text).toBe('Agent-specific stable.');
|
|
755
|
-
expect(content[1].cache_control).toEqual({
|
|
756
|
-
type: 'ephemeral',
|
|
757
|
-
ttl: '5m',
|
|
758
|
-
});
|
|
759
|
-
expect(content[2].text).toBe('Dynamic per-user.');
|
|
760
|
-
expect(content[2].cache_control).toBeUndefined();
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
it('Bedrock with one cache block + instructions + dynamic: emits 5-element content array', async () => {
|
|
764
|
-
const ctx = AgentContext.fromConfig({
|
|
765
|
-
agentId: 'a1',
|
|
766
|
-
provider: Providers.BEDROCK,
|
|
767
|
-
system_cache_blocks: [{ text: 'Outer cacheable prefix.' }],
|
|
768
|
-
instructions: 'Agent-specific stable.',
|
|
769
|
-
additional_instructions: 'Dynamic per-user.',
|
|
770
|
-
clientOptions: {
|
|
771
|
-
promptCache: true,
|
|
772
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
773
|
-
} as t.BedrockAnthropicClientOptions,
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
const sys = await captureSystemMessage(ctx);
|
|
777
|
-
const content = sys.content as Array<
|
|
778
|
-
| { type: string; text: string }
|
|
779
|
-
| { cachePoint: { type: string; ttl?: string } }
|
|
780
|
-
>;
|
|
781
|
-
|
|
782
|
-
expect(content).toHaveLength(5);
|
|
783
|
-
expect((content[0] as { text: string }).text).toBe('Outer cacheable prefix.');
|
|
784
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
785
|
-
expect((content[2] as { text: string }).text).toBe(
|
|
786
|
-
'Agent-specific stable.'
|
|
787
|
-
);
|
|
788
|
-
expect(content[3]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
789
|
-
expect((content[4] as { text: string }).text).toBe('Dynamic per-user.');
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
it('per-block TTL respected: prefix=5m, instructions=1h emits the right TTL on each cachePoint', async () => {
|
|
793
|
-
const ctx = AgentContext.fromConfig({
|
|
794
|
-
agentId: 'a1',
|
|
795
|
-
provider: Providers.BEDROCK,
|
|
796
|
-
system_cache_blocks: [{ text: 'Prefix.', ttl: '5m' }],
|
|
797
|
-
instructions: 'Agent.',
|
|
798
|
-
instructions_cache_ttl: '1h',
|
|
799
|
-
clientOptions: {
|
|
800
|
-
promptCache: true,
|
|
801
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
802
|
-
} as t.BedrockAnthropicClientOptions,
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
const sys = await captureSystemMessage(ctx);
|
|
806
|
-
const content = sys.content as Array<
|
|
807
|
-
| { type: string; text: string }
|
|
808
|
-
| { cachePoint: { type: string; ttl?: string } }
|
|
809
|
-
>;
|
|
810
|
-
|
|
811
|
-
expect(content).toHaveLength(4);
|
|
812
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
813
|
-
expect(content[3]).toEqual({ cachePoint: { type: 'default', ttl: '1h' } });
|
|
814
|
-
});
|
|
815
|
-
|
|
816
|
-
it('Cross-tenant cache stability: two consumers with shared cache block produce byte-identical prefix', async () => {
|
|
817
|
-
/* Load-bearing test: two distinct agents (different instructions)
|
|
818
|
-
* but the SAME outer cache block produce byte-identical first
|
|
819
|
-
* content entries, so Bedrock/Anthropic see the same cache key for
|
|
820
|
-
* the outer block. */
|
|
821
|
-
const sharedPrefix = 'Universal platform identity rules and tool routing.';
|
|
822
|
-
|
|
823
|
-
const customAgentA = AgentContext.fromConfig({
|
|
824
|
-
agentId: 'finance-helper',
|
|
825
|
-
name: 'Finance Helper',
|
|
826
|
-
provider: Providers.BEDROCK,
|
|
827
|
-
system_cache_blocks: [{ text: sharedPrefix }],
|
|
828
|
-
instructions: 'You are Finance Helper. Use SAP and Bloomberg.',
|
|
829
|
-
clientOptions: {
|
|
830
|
-
promptCache: true,
|
|
831
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
832
|
-
} as t.BedrockAnthropicClientOptions,
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
const customAgentB = AgentContext.fromConfig({
|
|
836
|
-
agentId: 'hr-helper',
|
|
837
|
-
name: 'HR Helper',
|
|
838
|
-
provider: Providers.BEDROCK,
|
|
839
|
-
system_cache_blocks: [{ text: sharedPrefix }],
|
|
840
|
-
instructions: 'You are HR Helper. Use Workday and Lever.',
|
|
841
|
-
clientOptions: {
|
|
842
|
-
promptCache: true,
|
|
843
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
844
|
-
} as t.BedrockAnthropicClientOptions,
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
const sysA = await captureSystemMessage(customAgentA);
|
|
848
|
-
const sysB = await captureSystemMessage(customAgentB);
|
|
849
|
-
const contentA = sysA.content as Array<unknown>;
|
|
850
|
-
const contentB = sysB.content as Array<unknown>;
|
|
851
|
-
|
|
852
|
-
// First TWO entries must match byte-for-byte: [prefix text, cachePoint]
|
|
853
|
-
expect(contentA[0]).toEqual(contentB[0]);
|
|
854
|
-
expect(contentA[1]).toEqual(contentB[1]);
|
|
855
|
-
|
|
856
|
-
// Third entry (agent-specific text) MUST differ — they are different agents.
|
|
857
|
-
expect(contentA[2]).not.toEqual(contentB[2]);
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
it('Empty system_cache_blocks: falls back to 2-tier (instructions + dynamic) shape', async () => {
|
|
861
|
-
/* Backwards-compat: consumers without the multi-cachePoint pattern
|
|
862
|
-
* get the legacy 2-tier shape — instructions + dynamic. */
|
|
863
|
-
const ctx = AgentContext.fromConfig({
|
|
864
|
-
agentId: 'a1',
|
|
865
|
-
provider: Providers.BEDROCK,
|
|
866
|
-
instructions: 'Agent-only stable.',
|
|
867
|
-
additional_instructions: 'Dynamic per-user.',
|
|
868
|
-
clientOptions: {
|
|
869
|
-
promptCache: true,
|
|
870
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
871
|
-
} as t.BedrockAnthropicClientOptions,
|
|
872
|
-
});
|
|
873
|
-
|
|
874
|
-
const sys = await captureSystemMessage(ctx);
|
|
875
|
-
const content = sys.content as Array<unknown>;
|
|
876
|
-
|
|
877
|
-
// [text, cachePoint, text] — exactly the 2-tier shape
|
|
878
|
-
expect(content).toHaveLength(3);
|
|
879
|
-
expect((content[0] as { text: string }).text).toBe('Agent-only stable.');
|
|
880
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
881
|
-
expect((content[2] as { text: string }).text).toBe('Dynamic per-user.');
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
it('Cache block only (no instructions): emits prefix tier + dynamic', async () => {
|
|
885
|
-
/* Edge case: only system_cache_blocks set, instructions empty.
|
|
886
|
-
* Useful for "global default" agents that rely entirely on the
|
|
887
|
-
* shared cacheable prefix. */
|
|
888
|
-
const ctx = AgentContext.fromConfig({
|
|
889
|
-
agentId: 'a1',
|
|
890
|
-
provider: Providers.BEDROCK,
|
|
891
|
-
system_cache_blocks: [{ text: 'Prefix only.' }],
|
|
892
|
-
additional_instructions: 'Dynamic.',
|
|
893
|
-
clientOptions: {
|
|
894
|
-
promptCache: true,
|
|
895
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
896
|
-
} as t.BedrockAnthropicClientOptions,
|
|
897
|
-
});
|
|
898
|
-
|
|
899
|
-
const sys = await captureSystemMessage(ctx);
|
|
900
|
-
const content = sys.content as Array<unknown>;
|
|
901
|
-
|
|
902
|
-
// [prefix text, cachePoint, dynamic text]
|
|
903
|
-
expect(content).toHaveLength(3);
|
|
904
|
-
expect((content[0] as { text: string }).text).toBe('Prefix only.');
|
|
905
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
906
|
-
expect((content[2] as { text: string }).text).toBe('Dynamic.');
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
it('two cache blocks: emits 2 cachePoints in order', async () => {
|
|
910
|
-
/* Composite case — N=2 entries. Each gets its own cachePoint, in
|
|
911
|
-
* declared order (outer first). This proves the array semantics. */
|
|
912
|
-
const ctx = AgentContext.fromConfig({
|
|
913
|
-
agentId: 'a1',
|
|
914
|
-
provider: Providers.BEDROCK,
|
|
915
|
-
system_cache_blocks: [
|
|
916
|
-
{ text: 'Block A (outer).', ttl: '1h' },
|
|
917
|
-
{ text: 'Block B (inner).', ttl: '5m' },
|
|
918
|
-
],
|
|
919
|
-
instructions: 'Instructions.',
|
|
920
|
-
clientOptions: {
|
|
921
|
-
promptCache: true,
|
|
922
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
923
|
-
} as t.BedrockAnthropicClientOptions,
|
|
924
|
-
});
|
|
925
|
-
|
|
926
|
-
const sys = await captureSystemMessage(ctx);
|
|
927
|
-
const content = sys.content as Array<
|
|
928
|
-
| { type: string; text: string }
|
|
929
|
-
| { cachePoint: { type: string; ttl?: string } }
|
|
930
|
-
>;
|
|
931
|
-
|
|
932
|
-
// [A text, cp(1h), B text, cp(5m), instructions text, cp(5m)]
|
|
933
|
-
expect(content).toHaveLength(6);
|
|
934
|
-
expect((content[0] as { text: string }).text).toBe('Block A (outer).');
|
|
935
|
-
expect(content[1]).toEqual({ cachePoint: { type: 'default', ttl: '1h' } });
|
|
936
|
-
expect((content[2] as { text: string }).text).toBe('Block B (inner).');
|
|
937
|
-
expect(content[3]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
938
|
-
expect((content[4] as { text: string }).text).toBe('Instructions.');
|
|
939
|
-
expect(content[5]).toEqual({ cachePoint: { type: 'default', ttl: '5m' } });
|
|
940
|
-
});
|
|
941
|
-
|
|
942
|
-
it('throws when system_cache_blocks exceeds MAX_SYSTEM_CACHE_BLOCKS (cachePoint budget)', () => {
|
|
943
|
-
/* Bedrock supports 4 cachePoints/request total. The library uses up
|
|
944
|
-
* to 2 in the system message + 1 trailing for instructions, leaving
|
|
945
|
-
* 1 for the tools array. Allowing 3+ entries would silently exceed
|
|
946
|
-
* the budget — the library throws to surface the misuse early. */
|
|
947
|
-
expect(() => {
|
|
948
|
-
AgentContext.fromConfig({
|
|
949
|
-
agentId: 'a1',
|
|
950
|
-
provider: Providers.BEDROCK,
|
|
951
|
-
system_cache_blocks: [
|
|
952
|
-
{ text: 'A' },
|
|
953
|
-
{ text: 'B' },
|
|
954
|
-
{ text: 'C' }, // ← over the cap
|
|
955
|
-
],
|
|
956
|
-
instructions: 'X',
|
|
957
|
-
clientOptions: {
|
|
958
|
-
promptCache: true,
|
|
959
|
-
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
|
960
|
-
} as t.BedrockAnthropicClientOptions,
|
|
961
|
-
});
|
|
962
|
-
}).toThrow(/system_cache_blocks supports at most 2 entries/);
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
it('Bedrock with non-cache-supported model (titan): NO cachePoint emitted', async () => {
|
|
966
|
-
/* The cacheSupport allowlist (cacheSupport.ts) rejects titan — we
|
|
967
|
-
* must NOT emit cachePoint markers there or Bedrock errors. */
|
|
968
|
-
const ctx = AgentContext.fromConfig({
|
|
969
|
-
agentId: 'a1',
|
|
970
|
-
provider: Providers.BEDROCK,
|
|
971
|
-
system_cache_blocks: [{ text: 'Prefix.' }],
|
|
972
|
-
instructions: 'Agent.',
|
|
973
|
-
clientOptions: {
|
|
974
|
-
promptCache: true,
|
|
975
|
-
model: 'amazon.titan-text-premier-v1:0',
|
|
976
|
-
} as t.BedrockAnthropicClientOptions,
|
|
977
|
-
});
|
|
978
|
-
|
|
979
|
-
const sys = await captureSystemMessage(ctx);
|
|
980
|
-
// Falls through to plain string concatenation when caching unsupported.
|
|
981
|
-
expect(typeof sys.content).toBe('string');
|
|
982
|
-
});
|
|
983
|
-
|
|
984
|
-
it('Bedrock with bedrockCacheModelPatterns extension: emits cachePoint for custom model', async () => {
|
|
985
|
-
/* Consumer extension: AWS adds a new model family before the
|
|
986
|
-
* library's allowlist updates. Consumer passes a regex; library
|
|
987
|
-
* treats the model as cache-supported. */
|
|
988
|
-
const ctx = AgentContext.fromConfig({
|
|
989
|
-
agentId: 'a1',
|
|
990
|
-
provider: Providers.BEDROCK,
|
|
991
|
-
system_cache_blocks: [{ text: 'Prefix.' }],
|
|
992
|
-
instructions: 'Agent.',
|
|
993
|
-
clientOptions: {
|
|
994
|
-
promptCache: true,
|
|
995
|
-
model: 'mycorp.future-model-v1:0',
|
|
996
|
-
bedrockCacheModelPatterns: [/^mycorp\.future-model-/i],
|
|
997
|
-
} as t.BedrockAnthropicClientOptions & {
|
|
998
|
-
bedrockCacheModelPatterns?: readonly RegExp[];
|
|
999
|
-
},
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
const sys = await captureSystemMessage(ctx);
|
|
1003
|
-
const content = sys.content as Array<unknown>;
|
|
1004
|
-
|
|
1005
|
-
expect(Array.isArray(content)).toBe(true);
|
|
1006
|
-
expect(content).toContainEqual({
|
|
1007
|
-
cachePoint: { type: 'default', ttl: '5m' },
|
|
1008
|
-
});
|
|
1009
|
-
});
|
|
1010
378
|
});
|
|
1011
379
|
|
|
1012
380
|
describe('reset()', () => {
|
|
@@ -22,7 +22,7 @@ describe('EdgeType enum', () => {
|
|
|
22
22
|
expect(EdgeType.HANDOFF).toBe('handoff');
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it('has correct DIRECT value (fixed graph edges
|
|
25
|
+
it('has correct DIRECT value (fixed graph edges with Ranger fan-in / parallel / approval-gate logic)', () => {
|
|
26
26
|
expect(EdgeType.DIRECT).toBe('direct');
|
|
27
27
|
});
|
|
28
28
|
|