Commit 982cc9a0 by sunqi02 Committed by 胡悦

refactor: 移除 ThinkingBlockSafeFormatter,恢复使用 OpenAIChatFormatter

1 parent 498607af
...@@ -18,30 +18,6 @@ from agentscope.tool import execute_python_code, execute_shell_command ...@@ -18,30 +18,6 @@ from agentscope.tool import execute_python_code, execute_shell_command
from agentscope.agent import ReActAgent from agentscope.agent import ReActAgent
from agentscope.memory import InMemoryMemory from agentscope.memory import InMemoryMemory
class ThinkingBlockSafeFormatter(OpenAIChatFormatter):
"""OpenAI formatter that strips ThinkingBlock before formatting.
The upstream OpenAIChatFormatter does not handle ThinkingBlock
(type="thinking"), causing "Unsupported block type" warnings and
risking silent message drops when a message contains only thinking
blocks. This wrapper pre-filters them so they never reach the upstream
block-handling loop.
"""
async def _format(self, msgs: list[Msg]) -> list[dict[str, Any]]:
# TruncatedFormatterBase.format() deepcopies msgs before calling
# _format, so we can safely mutate the copies here.
for msg in msgs:
if hasattr(msg, "content") and isinstance(msg.content, list):
msg.content = [
block
for block in msg.content
if not (isinstance(block, dict) and block.get("type") == "thinking")
]
return await super()._format(msgs)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# sub_agent 专用低 temperature:调用子 Agent 处理确定性任务时使用更稳定的输出 # sub_agent 专用低 temperature:调用子 Agent 处理确定性任务时使用更稳定的输出
...@@ -161,7 +137,7 @@ class AgentHub: ...@@ -161,7 +137,7 @@ class AgentHub:
stream=False, stream=False,
client_kwargs={"base_url": self.main_model_config.api_base} client_kwargs={"base_url": self.main_model_config.api_base}
) )
self.formatter = ThinkingBlockSafeFormatter() self.formatter = OpenAIChatFormatter()
# 加载回复风格指南(soul/agent.md) # 加载回复风格指南(soul/agent.md)
soul_path = Path(__file__).parent.parent.parent / "soul" / "agent.md" soul_path = Path(__file__).parent.parent.parent / "soul" / "agent.md"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!