loop: 用 rich.Markdown 渲染 assistant 输出

之前 console.print(f"...{content}") 只解析 [tag] 标签,不识别 **bold**、表格、列表
等 markdown 语法,LLM 回复会以原文显示。改成单独打印前缀后再 console.print(Markdown(content))。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
caoqianming 2026-05-07 11:19:46 +08:00
parent 950aa5aadc
commit 80f9934f8f
1 changed files with 3 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import json
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from rich.console import Console from rich.console import Console
from rich.markdown import Markdown
from .capabilities import ModelCapabilities from .capabilities import ModelCapabilities
from .llm import LLM from .llm import LLM
@ -44,7 +45,8 @@ class AgentLoop:
tool_calls = getattr(msg, "tool_calls", None) or [] tool_calls = getattr(msg, "tool_calls", None) or []
content = getattr(msg, "content", None) content = getattr(msg, "content", None)
if content: if content:
self.console.print(f"[cyan]assistant>[/cyan] {content}") self.console.print("[cyan]assistant>[/cyan]")
self.console.print(Markdown(content))
if not tool_calls: if not tool_calls:
return content or "" return content or ""