Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions python/tools/code_execution_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
import time
from python.helpers.tool import Tool, Response
from python.helpers import files, rfc_exchange, projects, runtime
from python.helpers import files, rfc_exchange, projects, runtime, settings
from python.helpers.print_style import PrintStyle
from python.helpers.shell_local import LocalInteractiveSession
from python.helpers.shell_ssh import SSHInteractiveSession
Expand Down Expand Up @@ -468,7 +468,13 @@ def fix_full_output(self, output: str):
output = re.sub(r"(?<!\\)\\x[0-9A-Fa-f]{2}", "", output)
# Strip every line of output before truncation
# output = "\n".join(line.strip() for line in output.splitlines())
output = truncate_text_agent(agent=self.agent, output=output, threshold=1000000) # ~1MB, larger outputs should be dumped to file, not read from terminal

# Dynamic threshold to prevent ContextWindowExceededError (#833)
set = settings.get_settings()
max_tokens = set["chat_model_ctx_length"] * set["chat_model_ctx_history"] * 0.125
threshold = max(50000, int(max_tokens * 3))

output = truncate_text_agent(agent=self.agent, output=output, threshold=threshold)
return output

def get_cwd(self):
Expand Down