fix(agent): bundle assistant text with toolUse + document cache hint dormancy #185

Merged
KofTwentyTwo merged 3 commits from fix/agent-cache-text-blocks-23-24 into develop 2026-05-14 11:53:35 +00:00
3 Commits
Author SHA1 Message Date
james.maes ef1462f795 Merge remote-tracking branch 'origin/develop' into fix/agent-cache-text-blocks-23-24 2026-05-14 06:39:49 -05:00
james.maes edc8daefe2 Merge remote-tracking branch 'origin/develop' into fix/agent-cache-text-blocks-23-24 2026-05-13 18:03:31 -05:00
james.maes f214845c89 fix(agent): bundle assistant text with toolUse + document cache hint dormancy
Two related AgentCore tactical fixes from the 2026-05-12 audit.

#24 — Assistant text blocks alongside tool_use were dropped from message
history. Opus 4.7 commonly narrates ("Let me check the time for
you...") before calling a tool. On the next round-trip the appended
assistant message contained only the .toolUse block, so the model had
no record of the narration — a user follow-up like "what did you say
before checking the time?" would deny it.

Fix: introduce `assistantTextSinceLastFlush` parallel to
`assistantTextSoFar` (the latter stays cumulative for D-02 vision
routing). On every toolUseRequested, flush the per-flush buffer into a
.text(...) block bundled into the same assistant message as the
.toolUse, trim whitespace-only text to avoid Anthropic 400s on empty
text blocks, and reset the flush buffer so subsequent tool_uses in the
same round get only the text emitted between them. D-02 untouched.

#23 — CacheHints documentation flagged that the eligibility threshold
(4096 chars ≈ 1024 tokens) is structurally false on healthy boot
(preamble ~700 chars, empty initial context). Added a paragraph
explicitly documenting the dormancy, the intentional cost-acceptance
rationale, and the natural recovery once M-4 (v0.8) lands
searchFacts-driven hydration. No code change.

Tests: 3 new tests in AssistantTextWithToolUseTests cover text+toolUse
bundling, toolUse-alone (no spurious empty text block), and
whitespace-only-text rejection. Full AgentCore suite: 248 tests, 0
failures, 1 skipped.

Closes #23, #24
2026-05-13 16:35:16 -05:00