Repository navigation
Conversation
Exclude transient request projections from automatic caching and fall back to durable messages across model formatters while respecting Anthropic's breakpoint limit.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
5 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.1.0-SNAPSHOTDescription
Refs #4538 (PR 3, explicit
cache_controlbreakpoint skip for Harness tail projections and Anthropic #2878 alignment).Problem
When
GenerateOptions.builder().cacheControl(true).build()is enabled on aHarnessAgent:HarnessContextBuilder.layout()appends request-only trailing projections after durable conversation history (such astask_delivery,todo_state,plan_state,harness:session-state, tailworkspace_materials, and an end-movedskill_catalogwhen guarding against a trailingASSISTANTprefill).lastIndexinapplyAutomaticCacheControl(...)and did not scan backward pastMessageMetadataKeys.CACHE_CONTROL = falseor empty/non-cacheable messages (such as tool-call-only assistant messages).doFormat(List<Msg>, GenerateOptions)/MessageMetadataKeys.CACHE_CONTROLcontract from fix(model): move cache control to content blocks #2878 and unconditionally marked the final formattedMessageParam.As a result, each turn's automatic conversation breakpoint landed on transient tail projections rather than the last durable message, preventing cached history prefixes from being reused on subsequent turns.
Summary of Changes
HarnessContextBuilder,io.agentscope.core.internal.PromptCacheMetadata):ASSISTANTfallback) on the request copy withMessageMetadataKeys.CACHE_CONTROL = false(preserving any caller-supplied directive) and internal_cache_control_projection = true.layout()idempotency, and leave wire output unchanged whenGenerateOptions.cacheControlis disabled.DashScopeChatFormatter,DashScopeMultiAgentFormatter,OpenAIBaseFormatter,OpenAIMultiAgentFormatter):applyAutomaticCacheControl(...)past excluded (false), empty-text (""), or non-cacheable messages so the automatic breakpoint lands on the latest cacheable durable message while stopping at an eligible explicittruemarker.AnthropicChatModel,AnthropicBaseFormatter,AnthropicChatFormatter,AnthropicMultiAgentFormatter,AnthropicMessageConverter,AnthropicToolsHelper,AnthropicFormatterCacheHooks):doFormat(List<Msg>, GenerateOptions)honoringMessageMetadataKeys.CACHE_CONTROL(true/false) on the leadingSYSTEMprompt and conversation messages (including merged tool results, split assistant tool-result messages, thinking-only/empty-text messages, and multi-agent groups).additionalBodyParams.cache_control), revoke framework-managed automaticsystemthen clienttoolmarkers when explicit markers exceed Anthropic's 4-breakpoint limit, and log a warning while forwarding supplied markers unchanged if supplied markers themselves exceed 4.format(List)/doFormat(List)/applyCacheControl(List)hooks viaAnthropicFormatterCacheHooks, while letting benign subclasses and Mockito spies inherit request-scoped caching.HarnessContextBuilderTest,ContextPipelineV2Test,DashScopeCacheControlTest,OpenAICacheControlTest,AnthropicCacheControlTest, andAnthropicChatModelCacheControlTest.docs/dev/{en,zh}/docs/harness/context.mdanddocs/dev/{en,zh}/integration/model/anthropic.md.Note: verification used unit/mock-server/formatter tests and offline Harness fixtures; live provider-side prompt-cache hit rates were not measured.
Validation
mvn -B -T1C clean verifypassed across all 114 modules ond22a9bc4a(prior to the final comment-only English translation commit).npm test20/20,npm run validate660 pages / 1,011 redirects,npm run broken-links0 broken links) passed ond22a9bc4a.9843e1421):mvn -T1C -pl agentscope-core,agentscope-harness,agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic spotless:checkpassed.AnthropicCacheControlTest,AnthropicChatModelCacheControlTest,HarnessContextBuilderTest,ContextPipelineV2Test) passed (agentscope-extensions-model-anthropic: 45 run, 0 failures/errors/skipped;agentscope-harness: 38 run, 0 failures/errors/skipped).Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)