fix: address PR review comments - rename _dedup to _dedupe and fix ID storage consistency

This commit is contained in:
Teddy Yan
2026-06-24 10:21:48 +08:00
committed by Xubin Ren
parent 6689e2d377
commit 6b8e832ba5
2 changed files with 9 additions and 9 deletions
+5 -5
View File
@@ -373,7 +373,7 @@ class AgentRunner:
# may repair or compact historical messages for the model, but
# those synthetic edits must not shift the append boundary used
# later when the caller saves only the new turn.
messages_for_model = self._dedup_tool_calls(messages)
messages_for_model = self._dedupe_tool_calls(messages)
messages_for_model = self._drop_orphan_tool_results(messages_for_model)
messages_for_model = self._backfill_missing_tool_results(messages_for_model)
messages_for_model = self._microcompact(messages_for_model)
@@ -389,7 +389,7 @@ class AgentRunner:
spec.session_key or "default",
)
try:
messages_for_model = self._dedup_tool_calls(messages)
messages_for_model = self._dedupe_tool_calls(messages)
messages_for_model = self._drop_orphan_tool_results(messages_for_model)
messages_for_model = self._backfill_missing_tool_results(messages_for_model)
except Exception:
@@ -1358,7 +1358,7 @@ class AgentRunner:
return content
@staticmethod
def _dedup_tool_calls(
def _dedupe_tool_calls(
messages: list[dict[str, Any]],
) -> list[dict[str, Any]]:
"""Remove duplicate tool_call / tool_result ids from the history.
@@ -1383,11 +1383,11 @@ class AgentRunner:
changed = False
for tc in msg.get("tool_calls") or []:
tid = tc.get("id") if isinstance(tc, dict) else None
if tid and tid in seen_call_ids:
if tid and str(tid) in seen_call_ids:
changed = True
continue
if tid:
seen_call_ids.add(tid)
seen_call_ids.add(str(tid))
kept.append(tc)
if changed:
replacement = dict(msg)
+4 -4
View File
@@ -184,7 +184,7 @@ async def test_backfill_missing_tool_results_inserts_error():
assert backfilled[0]["name"] == "read_file"
def test_dedup_tool_calls_removes_duplicate_ids():
def test_dedupe_tool_calls_removes_duplicate_ids():
from nanobot.agent.runner import AgentRunner
messages = [
@@ -205,7 +205,7 @@ def test_dedup_tool_calls_removes_duplicate_ids():
{"role": "tool", "tool_call_id": "b", "name": "y", "content": "rb-dup"},
]
cleaned = AgentRunner._dedup_tool_calls(messages)
cleaned = AgentRunner._dedupe_tool_calls(messages)
assert cleaned == [
{"role": "user", "content": "hi"},
@@ -222,7 +222,7 @@ def test_dedup_tool_calls_removes_duplicate_ids():
]
def test_dedup_tool_calls_noop_when_unique():
def test_dedupe_tool_calls_noop_when_unique():
from nanobot.agent.runner import AgentRunner
messages = [
@@ -238,7 +238,7 @@ def test_dedup_tool_calls_noop_when_unique():
]
# No duplicates -> identical list object returned (cheap no-op path).
assert AgentRunner._dedup_tool_calls(messages) is messages
assert AgentRunner._dedupe_tool_calls(messages) is messages
def test_drop_orphan_tool_results_removes_unmatched_tool_messages():