fix: resolve UnboundLocalError in post-tool empty response nudge path

When a model returns an empty response after tool calls with no new
tool_calls in the follow-up turn, the code enters the "nudge" recovery
path which referenced `assistant_msg` before it was assigned. This
variable is only set in the tool-calls branch (line 10098), but the
nudge code lives in the no-tool-calls branch (line 10263+).

The fix builds a fresh assistant message dict via `_build_assistant_message()`
instead of reusing the unbound variable, consistent with the exhausted-
retries path at line 10457.
This commit is contained in:
Ko 2026-04-16 01:37:00 +09:00 committed by Teknium
parent 9f231dae56
commit 85752791ed

View file

@ -10945,8 +10945,9 @@ class AIAgent:
# tool(result) → assistant("(empty)") → user(nudge)
# Without this, we'd have tool → user which most
# APIs reject as an invalid sequence.
assistant_msg["content"] = "(empty)"
messages.append(assistant_msg)
_nudge_msg = self._build_assistant_message(assistant_message, finish_reason)
_nudge_msg["content"] = "(empty)"
messages.append(_nudge_msg)
messages.append({
"role": "user",
"content": (