Skip to content

Commit ef0126d

Browse files
author
giulio-leone
committed
fix(review): replace unreachable normalization with assertions in message merge
- Replace defensive normalization with explicit type assertions - Assertions enforce invariants and surface violations clearly Refs: #2021
1 parent 40190c5 commit ef0126d

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/smolagents/models.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,15 @@ def get_clean_message_list(
380380
assert isinstance(message.content, list), "Error: wrong content:" + str(message.content)
381381
if flatten_messages_as_text:
382382
# In flatten mode, output content is stored as a plain string.
383-
# Normalize it if needed before concatenating.
384-
if isinstance(output_message_list[-1]["content"], list):
385-
output_message_list[-1]["content"] = output_message_list[-1]["content"][0]["text"]
383+
assert isinstance(
384+
output_message_list[-1]["content"], str
385+
), "Error: expected string content in flatten mode"
386386
output_message_list[-1]["content"] += "\n" + message.content[0]["text"]
387387
else:
388388
# In structured mode, output content is stored as a list of dicts.
389-
# Normalize it if needed before merging.
390-
if isinstance(output_message_list[-1]["content"], str):
391-
output_message_list[-1]["content"] = [
392-
{"type": "text", "text": output_message_list[-1]["content"]}
393-
]
389+
assert isinstance(
390+
output_message_list[-1]["content"], list
391+
), "Error: expected list content in structured mode"
394392
for el in message.content:
395393
if el["type"] == "text" and output_message_list[-1]["content"][-1]["type"] == "text":
396394
# Merge consecutive text messages rather than creating new ones

0 commit comments

Comments
 (0)