in src/smolagents/memory.py [0:0]
def to_messages(self, summary_mode: bool = False) -> list[ChatMessage]:
messages = []
if self.model_output is not None and not summary_mode:
messages.append(
ChatMessage(role=MessageRole.ASSISTANT, content=[{"type": "text", "text": self.model_output.strip()}])
)
if self.tool_calls is not None:
messages.append(
ChatMessage(
role=MessageRole.TOOL_CALL,
content=[
{
"type": "text",
"text": "Calling tools:\n" + str([tc.dict() for tc in self.tool_calls]),
}
],
)
)
if self.observations_images:
messages.append(
ChatMessage(
role=MessageRole.USER,
content=[
{
"type": "image",
"image": image,
}
for image in self.observations_images
],
)
)
if self.observations is not None:
messages.append(
ChatMessage(
role=MessageRole.TOOL_RESPONSE,
content=[
{
"type": "text",
"text": f"Observation:\n{self.observations}",
}
],
)
)
if self.error is not None:
error_message = (
"Error:\n"
+ str(self.error)
+ "\nNow let's retry: take care not to repeat previous errors! If you have retried several times, try a completely different approach.\n"
)
message_content = f"Call id: {self.tool_calls[0].id}\n" if self.tool_calls else ""
message_content += error_message
messages.append(
ChatMessage(role=MessageRole.TOOL_RESPONSE, content=[{"type": "text", "text": message_content}])
)
return messages