fix(agent): keep tool results stable across replay (#5695)

* fix(agent): keep processed tool results stable across replay

* fix(agent): preserve multimodal text and complete result references

* docs: trim tool result persistence comments

* fix(tools): allow complete reads of oversized text lines

* fix: keep read_file interface unchanged in replay fix

* refactor: pass one tool result reference path

* refactor: keep tool result persistence text-only

* fix: keep tool output references stable across workspace changes
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-08 14:10:55 +08:00
1 parent 7aaff4f66b
commit e77c638f89
6 files changed
+333 -67

No files matched your search

+2 -17
View File
@@ -106,7 +106,6 @@ from nanobot.triggers.local_turns import LocalTriggerTurnCoordinator
from nanobot.utils.cancellation import task_is_cancelling
from nanobot.utils.document import reference_non_image_attachments
from nanobot.utils.helpers import image_placeholder_text
from nanobot.utils.helpers import truncate_text as truncate_text_fn
from nanobot.utils.llm_runtime import LLMRuntime
from nanobot.utils.progress_events import output_events
from nanobot.utils.runtime import (
@@ -2103,8 +2102,6 @@ class AgentLoop:
def _sanitize_persisted_blocks(
self,
content: list[object],
*,
should_truncate_text: bool = False,
) -> list[object]:
"""Strip volatile multimodal payloads before writing session history."""
filtered: list[object] = []
@@ -2125,16 +2122,6 @@ class AgentLoop:
)
continue
if block_data.get("type") == "text" and isinstance(
block_data.get("text"),
str,
):
text = cast(str, block_data["text"])
if should_truncate_text and len(text) > self.max_tool_result_chars:
text = truncate_text_fn(text, self.max_tool_result_chars)
filtered.append({**block_data, "text": text})
continue
filtered.append(block_data)
return filtered
@@ -2251,12 +2238,10 @@ class AgentLoop:
)
continue
fulfilled_tool_call_ids.add(tool_call_id_str)
if isinstance(content, str) and len(content) > self.max_tool_result_chars:
entry["content"] = truncate_text_fn(content, self.max_tool_result_chars)
elif isinstance(content, list):
# Preserve model-visible text for replay; redact only inline images.
if isinstance(content, list):
filtered = self._sanitize_persisted_blocks(
cast(list[object], content),
should_truncate_text=True,
)
if not filtered:
# Preserve the tool_call/result pair after block filtering.