refactor: extract 6 helpers from convert_messages_to_anthropic#23968
Closed
kshitijk4poor wants to merge 1 commit into
Closed
refactor: extract 6 helpers from convert_messages_to_anthropic#23968kshitijk4poor wants to merge 1 commit into
kshitijk4poor wants to merge 1 commit into
Conversation
Split convert_messages_to_anthropic (complexity 79) into 6 focused helpers: - _convert_assistant_message — assistant msg to content blocks - _convert_tool_message_to_result — tool msg to tool_result + merge - _convert_user_message — user msg validation + conversion - _strip_orphaned_tool_blocks — orphan tool_use + tool_result removal - _merge_consecutive_roles — role alternation enforcement - _manage_thinking_signatures — strip/preserve/downgrade by endpoint - _evict_old_screenshots — keep only 3 most recent images Main function complexity: 79 → 10 (below C901 threshold). Zero logic changes — pure extraction. Net -4 lines.
This was referenced May 18, 2026
Collaborator
Author
|
Superseded by #27784 — same commit rebased onto current Both this PR and the new one are mine, so no contributor authorship to preserve. The new PR body has more honest complexity accounting — the original 79→10 claim was inaccurate; the real number is 79→18 max with 4 still-complex helpers. |
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.
Summary
Split
convert_messages_to_anthropic(complexity 79) into 6 focused helpers:_convert_assistant_message_convert_tool_message_to_result_convert_user_message_strip_orphaned_tool_blocks_merge_consecutive_roles_manage_thinking_signatures_evict_old_screenshotsResults
Test results
test_anthropic_adapter.py: 26 passed (same 5 pre-existing failures on main)run_agent + agent: 1,144 passed (same 2 pre-existing failures on main)Part 5 of the complexity reduction series.