Skip to content

Commit 19b9a9d

Browse files
committed
Improve tool output handling
1 parent d437f1d commit 19b9a9d

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

interpreter/interpreter.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -896,20 +896,15 @@ async def async_respond(self, user_input=None):
896896
output = result.error
897897
else:
898898
output = result.output
899-
self.messages.append(
900-
{
901-
"role": "tool",
902-
"content": output,
903-
"tool_call_id": tool_call.id,
904-
}
905-
)
899+
900+
tool_output = ""
901+
902+
if output:
903+
tool_output += output
904+
906905
if result.base64_image:
907-
self.messages.append(
908-
{
909-
"role": "tool",
910-
"content": "The user will reply with the tool's image output.",
911-
"tool_call_id": tool_call.id,
912-
}
906+
tool_output += (
907+
"\nThe user will reply with the tool's image output."
913908
)
914909
user_content_to_add.append(
915910
{
@@ -919,6 +914,17 @@ async def async_respond(self, user_input=None):
919914
},
920915
}
921916
)
917+
918+
if tool_output == "":
919+
tool_output = "No output from tool."
920+
921+
self.messages.append(
922+
{
923+
"role": "tool",
924+
"content": tool_output.strip(),
925+
"tool_call_id": tool_call.id,
926+
}
927+
)
922928
else:
923929
text_content = (
924930
"This was the output of the tool call. What does it mean/what's next?\n"

0 commit comments

Comments
 (0)