Skip to content

Commit

Permalink
Fix tool output truncation (#1129)
Browse files Browse the repository at this point in the history
* Modify web_browser to display errors better

* Add test

* remove items left during debugging

* Update CHANGELOG.md

* fix tool call formatting

* ruff

* fix commented out code

* simplify test

---------

Co-authored-by: Lukas Berglund <[email protected]>
Co-authored-by: jjallaire-aisi <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent d319e65 commit d419cce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/inspect_ai/model/_call_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,13 @@ def truncate_tool_output(
# truncate if required
truncated = truncate_string_to_bytes(output, active_max_output)
if truncated:
truncated_output = dedent(f"""
truncated_output = dedent("""
The output of your call to {tool_name} was too long to be displayed.
Here is a truncated version:
<START_TOOL_OUTPUT>
{truncated.output}
<END_TOOL_OUTPUT>""")
{truncated_output}
<END_TOOL_OUTPUT>
""").format(tool_name=tool_name, truncated_output=truncated.output)
return TruncatedToolOutput(
truncated_output, truncated.original_bytes, active_max_output
)
Expand Down
11 changes: 11 additions & 0 deletions tests/tools/test_tool_truncate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from inspect_ai.model._call_tools import truncate_tool_output


def test_tool_truncate():
long_tool_output = "TEST\n" * 100_000
truncated_output = truncate_tool_output(
tool_name="test", output=long_tool_output, max_output=1000
)

# Output should not contain leading/trailing whitespace on any line.
assert all(line.strip() == line for line in truncated_output.output.split("\n"))

0 comments on commit d419cce

Please sign in to comment.