mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 10:11:46 +03:00
fix(tool_hints): respect max_length for plain (non-path/non-command) tool values
Plain tool values (grep patterns, web_search/x_search queries, find_files
globs) were never truncated by format_tool_hints(), so long arguments
overflowed tool_hint_max_length and were pushed to chat/UI verbatim.
Add a hard-truncation fallback for the plain branch, mirroring the existing
truncation used by abbreviate_path / _abbreviate_command. This completes the
same class of fix started in 99209a80 for is_path tools.
Adds 4 regression tests to tests/agent/test_tool_hint.py.
This commit is contained in:
committed by
Xubin Ren
parent
816a999cac
commit
eddfa0dd6b
@@ -104,6 +104,10 @@ def _fmt_known(tc: ToolCallRequest, fmt: ToolFormat, max_length: int = 40) -> st
|
||||
val = abbreviate_path(val, max_len=max_length)
|
||||
elif fmt[3]: # is_command
|
||||
val = _abbreviate_command(val, max_len=max_length)
|
||||
elif len(val) > max_length:
|
||||
# Plain values (grep patterns, search queries, ...) have no path or
|
||||
# command structure to fold, so fall back to a hard truncation.
|
||||
val = val[:max_length - 1] + "\u2026"
|
||||
return fmt[1].format(val)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user