fix: agent_tools._truncate crashes on non-string input (#1624)

* fix: agent_tools._truncate crashes on non-string input

* fix: agent_tools._truncate returns a string for non-string input, not the raw value
This commit is contained in:
Afonso Coutinho
2026-06-03 06:06:39 +01:00
committed by GitHub
parent 3a741edbf1
commit 1571d8bba0
2 changed files with 29 additions and 0 deletions
+5
View File
@@ -80,6 +80,11 @@ def get_mcp_manager():
# Helpers (kept here — used by sub-modules)
# ---------------------------------------------------------------------------
def _truncate(text: str, limit: int = MAX_OUTPUT_CHARS) -> str:
# Callers treat the result as text, so always return a string: coerce a
# non-string (None -> "", otherwise str(...)) instead of returning it raw,
# which would just move the crash downstream.
if not isinstance(text, str):
text = "" if text is None else str(text)
if len(text) > limit:
return text[:limit] + f"\n... (truncated, {len(text)} chars total)"
return text