Skip to content

Reuse cached conversation as prefix for dialog-summary helper#188

Draft
yzx9 wants to merge 1 commit into
mainfrom
cache-reuse-helpers
Draft

Reuse cached conversation as prefix for dialog-summary helper#188
yzx9 wants to merge 1 commit into
mainfrom
cache-reuse-helpers

Conversation

@yzx9

@yzx9 yzx9 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

_generate_dialog_summary sent a brand-new single-user prompt and discarded the leader's cached conversation, so it got 0 cache reuse. Append a short summary instruction to a snapshot of the leader's _dialog_messages instead, so the conversation prefix is an Anthropic cache hit and only the tail is fresh. Falls back to the legacy re-serialized-steps prompt when no dialog is cached yet.

  • leader_prompts: factor _SUMMARY_FORMAT_BLOCK (shared by legacy + tail); add make_summary_tail referencing the cached conversation above
  • leader_multiagent: add LeaderAgent.dialog_messages read-only property (Sequence[TextMessage]) + LeaderDriven._leader_dialog_snapshot(); rewrite _generate_dialog_summary with snapshot-or-fallback
  • tests: anthropic cache-compat assertion (prefix blocks byte-identical, BP2 relocated onto the tail, exactly-one cache_control across message blocks to guard the 4-breakpoint budget); unit tests for the snapshot primitive and the summary snapshot/fallback paths

Phase A of the cache-reuse plan. KB extract (#3) and the live-model validation gate (T3) are intentionally out of this commit.

_generate_dialog_summary sent a brand-new single-user prompt and discarded
the leader's cached conversation, so it got 0 cache reuse. Append a short
summary instruction to a snapshot of the leader's _dialog_messages instead,
so the conversation prefix is an Anthropic cache hit and only the tail is
fresh. Falls back to the legacy re-serialized-steps prompt when no dialog is
cached yet.

- leader_prompts: factor _SUMMARY_FORMAT_BLOCK (shared by legacy + tail);
  add make_summary_tail referencing the cached conversation above
- leader_multiagent: add LeaderAgent.dialog_messages read-only property
  (Sequence[TextMessage]) + LeaderDriven._leader_dialog_snapshot(); rewrite
  _generate_dialog_summary with snapshot-or-fallback
- tests: anthropic cache-compat assertion (prefix blocks byte-identical,
  BP2 relocated onto the tail, exactly-one cache_control across message
  blocks to guard the 4-breakpoint budget); unit tests for the snapshot
  primitive and the summary snapshot/fallback paths

Phase A of the cache-reuse plan. KB extract (#3) and the live-model
validation gate (T3) are intentionally out of this commit.

Assisted-by: Claude-Code:GLM-5.2
@yzx9 yzx9 changed the base branch from dev to main July 3, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant