mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(anthropic): merge consecutive assistant messages with mixed content types
When two consecutive assistant messages had mixed content types (one string, one list), the merge logic just replaced the earlier message entirely with the later one (fixed[-1] = m), silently dropping the earlier message's content. Apply the same normalization pattern used in the tool_use merge path (lines 952-956): convert both to list format before concatenating. This preserves all content from both messages.
This commit is contained in:
parent
56e0c90445
commit
8b411b234d
1 changed files with 6 additions and 2 deletions
|
|
@ -963,8 +963,12 @@ def convert_messages_to_anthropic(
|
|||
elif isinstance(prev_blocks, str) and isinstance(curr_blocks, str):
|
||||
fixed[-1]["content"] = prev_blocks + "\n" + curr_blocks
|
||||
else:
|
||||
# Keep the later message
|
||||
fixed[-1] = m
|
||||
# Mixed types — normalize both to list and merge
|
||||
if isinstance(prev_blocks, str):
|
||||
prev_blocks = [{"type": "text", "text": prev_blocks}]
|
||||
if isinstance(curr_blocks, str):
|
||||
curr_blocks = [{"type": "text", "text": curr_blocks}]
|
||||
fixed[-1]["content"] = prev_blocks + curr_blocks
|
||||
else:
|
||||
fixed.append(m)
|
||||
result = fixed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue