Skip to content

fix(agent): normalize empty assistant content to None for Anthropic compatibility#12737

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/anthropic-empty-content-400
Open

fix(agent): normalize empty assistant content to None for Anthropic compatibility#12737
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/anthropic-empty-content-400

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Anthropic proxies reject empty-string content with HTTP 400. This PR normalizes falsy assistant content to None in _build_assistant_message() before storing to transcript. Whitespace-only content is also normalized after the existing strip() pass.

Related Issue

Fixes #11906

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • _build_assistant_message(): normalize falsy assistant content (empty string, whitespace-only after strip) to None before storing to transcript

How to Test

Tests use the real AIAgent fixture and _build_assistant_message() call path:

  1. test_normalizes_empty_string_to_none""None
  2. test_preserves_nonempty_content"hello" passes through unchanged
  3. test_preserves_none_contentNone stays None
  4. test_whitespace_only_content_becomes_none" " → stripped → ""None

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS (Darwin 24.6.0, Python 3.14)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

N/A — see commit description and PR diff.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/anthropic Anthropic native Messages API labels Apr 23, 2026
@Tranquil-Flow Tranquil-Flow force-pushed the fix/anthropic-empty-content-400 branch from 7b54b1f to 267e719 Compare May 18, 2026 21:24
…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
@Tranquil-Flow Tranquil-Flow force-pushed the fix/anthropic-empty-content-400 branch from 267e719 to 369f1d1 Compare May 25, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/anthropic Anthropic native Messages API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Assistant messages with empty content cause HTTP 400 on Anthropic-compatible proxies

2 participants