fix(agent): normalize empty assistant content to None for Anthropic compatibility#12737
Open
Tranquil-Flow wants to merge 2 commits into
Open
fix(agent): normalize empty assistant content to None for Anthropic compatibility#12737Tranquil-Flow wants to merge 2 commits into
Tranquil-Flow wants to merge 2 commits into
Conversation
13 tasks
19 tasks
7b54b1f to
267e719
Compare
…ompatibility Anthropic proxies reject empty-string content with HTTP 400. Normalize falsy assistant content to None in _build_assistant_message() before storing to transcript. Tests use the real AIAgent fixture and _build_assistant_message() call path, which correctly caught that whitespace-only content is also normalized to None after the strip() pass. Fixes NousResearch#11906
267e719 to
369f1d1
Compare
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.
What does this PR do?
Anthropic proxies reject empty-string content with HTTP 400. This PR normalizes falsy assistant content to
Nonein_build_assistant_message()before storing to transcript. Whitespace-only content is also normalized after the existingstrip()pass.Related Issue
Fixes #11906
Type of Change
Changes Made
_build_assistant_message(): normalize falsy assistant content (empty string, whitespace-only after strip) toNonebefore storing to transcriptHow to Test
Tests use the real
AIAgentfixture and_build_assistant_message()call path:test_normalizes_empty_string_to_none—""→Nonetest_preserves_nonempty_content—"hello"passes through unchangedtest_preserves_none_content—NonestaysNonetest_whitespace_only_content_becomes_none—" "→ stripped →""→NoneChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
N/A — see commit description and PR diff.