fix: skip empty assistant turns instead of placeholder space#560
Merged
Conversation
Follow-up to #559. Instead of emitting a ' ' placeholder for empty assistant turns, skip them entirely. An assistant turn with no text and no tool calls carries zero information — no tool_use means no tool_result pairing constraint, so omitting is safe. This matches the canonical pattern used by litellm, goose, and other Anthropic API consumers: strip empty content at serialization time.
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.
Follow-up to #559.
Instead of emitting
" "(single space) as a placeholder for empty assistant turns, skip them entirely. An assistant turn with no text and no tool calls carries zero information — notool_usemeans notool_resultpairing constraint, so omitting is safe.This matches the canonical pattern used by litellm, goose (
anthropic.rsline 124), and other Anthropic API consumers: strip empty content at serialization time rather than patching with placeholders.Research
The
" "placeholder from #559 works but is a band-aid. anthropics/anthropic-sdk-python#461 (April 2024) confirmed this validation is intentional and has existed since the tool use beta. The Anthropic maintainer's guidance: empty text blocks should be filtered, not patched.Change
llm.rs: replacecontent.push(json!({"type":"text","text":" "}))withcontinue(skip the turn).