Skip to content

Commit 5fd07f9

Browse files
Fix Access of content Field in ChatMessage Object (#1533)
Co-authored-by: Albert Villanova del Moral <[email protected]>
1 parent 9f43bbd commit 5fd07f9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/smolagents/agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ def __call__(self, task: str, **kwargs):
860860
if self.provide_run_summary:
861861
answer += "\n\nFor more detail, find below a summary of this agent's work:\n<summary_of_work>\n"
862862
for message in self.write_memory_to_messages(summary_mode=True):
863-
content = message["content"]
863+
content = message.content
864864
answer += "\n" + truncate_content(str(content)) + "\n---"
865865
answer += "\n</summary_of_work>"
866866
return answer

tests/test_agents.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,9 @@ def test_call_with_provide_run_summary(self, provide_run_summary):
17861786
assert agent.provide_run_summary is provide_run_summary
17871787
agent.name = "test_agent"
17881788
agent.run = MagicMock(return_value="Test output")
1789-
agent.write_memory_to_messages = MagicMock(return_value=[{"content": "Test summary"}])
1789+
agent.write_memory_to_messages = MagicMock(
1790+
return_value=[ChatMessage(role=MessageRole.ASSISTANT, content="Test summary")]
1791+
)
17901792

17911793
result = agent("Test request")
17921794
expected_summary = "Here is the final answer from your managed agent 'test_agent':\nTest output"

0 commit comments

Comments
 (0)