[pull] main from danny-avila:main#67
Merged
pull[bot] merged 1 commit intoinnFactory:mainfrom Apr 25, 2026
Merged
Conversation
* fix: tolerate trailing tool_use without a thinking block (#115) When Anthropic thinking is enabled and Claude issues a tool call without emitting a thinking block first, the pruner saw `[AI tool_use, Tool]` at the tail and walked back searching for a thinking block. With none to find, it threw "The payload is malformed. There is a thinking sequence but no AI messages with thinking blocks" — permanently breaking any conversation that crossed the context limit on that turn. Anthropic does not require a thinking block before every tool call, so the absence of one is valid. Broaden the false-start guard to clear thinkingEndIndex whenever the loop exits the trailing AI/tool sequence without having found a thinking block, instead of only on the message immediately before the tail. * test: cover multi-hop and createPruneMessages cases for #115 Two additional cases requested in PR review: - Multi-hop tail [AI(tool_use), Tool, AI(tool_use), Tool] with no thinking blocks anywhere — locks down the guard for chained tool calls, a common Anthropic pattern. - Carry-over scenario through createPruneMessages: a first call establishes runThinkingStartIndex from a thinking turn, and a second call extends the conversation with a no-thinking tail. This exercises the production entry point and verifies the new guard interacts correctly with the closed-over thinking-index state. * test: verify pruner output flows correctly through ensureThinkingBlockInMessages Models the full Graph.ts pipeline (pruner → ensureThinkingBlockInMessages) with the issue #115 tail. Confirms the two functions handle complementary concerns: the pruner just stops throwing, and ensureThinkingBlockInMessages folds the orphan AI(tool_use)+Tool into a [Previous agent context] HumanMessage. The outgoing API payload contains no AI tool_use without a thinking block, so Anthropic's signature requirement is satisfied. * test: address PR review of #115 follow-ups - Drop the redundant double-call in the multi-hop test; calling the pure function once and asserting on the result is sufficient (a throw fails the test anyway). - Tighten the carry-over test so the first call actually triggers pruning. Previously maxTokens=1000 against a 12-token conversation took the early-return path, leaving runThinkingStartIndex at -1 — the second call was indistinguishable from a fresh call. Now the first call's Human is large enough to be pruned while the AI(thinking) message survives, so runThinkingStartIndex is set to the AI's index. The second call's Tool is sized so AI(tool_use) survives and the carry-over thinking block actually gets reattached, which the new assertion verifies. * test: fix vacuous ensureThinkingBlockInMessages integration assertion The prior test used Tool('f'×8000) against maxContextTokens: 200, which sent every message to prunedMemory. ensureThinkingBlockInMessages then received an empty array, the assertion loop iterated zero times, and the test passed without checking anything — pure false-confidence coverage. Tune Tool size to 100 chars and budget to 300 so the full [Human, AI(tool_use), Tool] tail survives pruning. Replace the filter-and-skip loop with concrete assertions: context.length === 3 post-prune, finalMessages.length === 2 post-fold, both finalMessages are HumanMessage instances, the folded message contains the '[Previous agent context]' marker, and no AI(tool_use) survives in the outgoing payload.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )