fix: render markdown in assistant panels and speed up reasoning-only recovery

Assistant message panels now use Markdown() instead of raw strings, so
bold/italic/lists render properly. Also nudge the model immediately after
tool errors instead of wasting 2 retry iterations in reasoning-only mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 18:21:51 -05:00
parent 90a38f12d1
commit cc03f76593
2 changed files with 11 additions and 3 deletions

View File

@@ -153,7 +153,14 @@ class AgentLoop:
reasoning_only_streak += 1
self._ctx.pop_last_message()
if reasoning_only_streak >= _MAX_REASONING_RETRIES:
# If the last context messages are tool errors, nudge immediately
# rather than wasting retries — the model is likely confused by the error.
has_recent_tool_error = any(
m.role == "tool" and m.content and m.content.startswith("Unknown ")
for m in self._ctx.get_history()[-3:]
)
if has_recent_tool_error or reasoning_only_streak >= _MAX_REASONING_RETRIES:
# Nudge the model by injecting a user hint
if self._display:
self._display.write_warning(
@@ -162,7 +169,7 @@ class AgentLoop:
)
self._ctx.add_message(
"user",
"Please respond with your answer. Do not just think — provide your actual response.",
"Please respond with your answer. If a tool call failed, briefly explain what happened and continue.",
)
reasoning_only_streak = 0
else:

View File

@@ -10,6 +10,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Protocol
from rich.markdown import Markdown
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
@@ -50,7 +51,7 @@ def render_user_message(content: str) -> Panel:
def render_assistant_message(content: str) -> Panel:
"""Render an assistant message as a styled panel."""
return Panel(content, title="Assistant", border_style="green", expand=True)
return Panel(Markdown(content), title="Assistant", border_style="green", expand=True)
def render_tool_call(name: str, args: str) -> Text: