mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-15 17:25:26 -04:00
95c54ac3cb
Replace hardcoded [:2000] and [:4000] slicing with the shared _truncate helper from tool_utils, which uses MAX_OUTPUT_CHARS and adds an explicit truncation indicator when content is cut. Scoped down from the original PR: only agent/tool-output display behavior, no integrations.py changes. Co-authored-by: michaelxer <michaelxer@users.noreply.github.com> Co-authored-by: Alexandre Teixeira <111787685+alteixeira20@users.noreply.github.com>
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""Tool-output display truncation uses _truncate with an indicator.
|
|
|
|
Previously agent_loop sliced tool output to a hard character limit ([:2000]
|
|
or [:4000]) with no signal to the UI that data was lost. Now it delegates to
|
|
tool_utils._truncate which caps at MAX_OUTPUT_CHARS (10 000) and appends
|
|
a ``... (truncated, N chars total)`` suffix so the frontend can show a
|
|
truncation indicator in the tool bubble.
|
|
"""
|
|
from src.tool_utils import _truncate, MAX_OUTPUT_CHARS
|
|
|
|
|
|
def test_short_output_unchanged():
|
|
"""Outputs within the limit pass through verbatim."""
|
|
text = "hello world"
|
|
assert _truncate(text) == text
|
|
|
|
|
|
def test_long_output_truncated_with_indicator():
|
|
"""Outputs exceeding MAX_OUTPUT_CHARS are truncated with a suffix."""
|
|
text = "x" * (MAX_OUTPUT_CHARS + 500)
|
|
result = _truncate(text)
|
|
assert len(result) > MAX_OUTPUT_CHARS # includes suffix
|
|
assert result.startswith("x" * MAX_OUTPUT_CHARS)
|
|
assert "truncated" in result
|
|
assert str(len(text)) in result # original length reported
|
|
|
|
|
|
def test_exact_limit_unchanged():
|
|
"""An output exactly at the limit is not truncated."""
|
|
text = "a" * MAX_OUTPUT_CHARS
|
|
assert _truncate(text) == text
|
|
|
|
|
|
def test_default_limit_matches_constant():
|
|
"""_truncate default limit equals MAX_OUTPUT_CHARS (10 000)."""
|
|
assert MAX_OUTPUT_CHARS == 10_000
|
|
text = "y" * 10_001
|
|
result = _truncate(text)
|
|
assert "truncated" in result
|
|
|
|
|
|
def test_empty_string():
|
|
assert _truncate("") == ""
|