Bug Description
wechat_channel.py line 249 directly uses m.role from the database when building LLM history. Tool call logs are stored
with role="tool_call" in ChatMessage, but this is an internal role — it should be converted to standard OpenAI format
(assistant + tool_calls followed by tool result) before sending to the LLM API.
This causes HTTP 400 with providers that strictly validate role (e.g. Agnes AI):
messages[2].role: unknown variant tool_call, expected one of system, user, assistant, tool, latest_reminder
Root Cause
wechat_channel.py line 249 (buggy)
history = [{"role": m.role, "content": m.content} for m in reversed(history_r.scalars().all())]
All other channels correctly use convert_chat_messages_to_llm_format(): feishu.py, dingtalk.py, discord_bot.py,
slack.py, teams.py, gateway.py, websocket.py. WeChat is the only channel that skips this conversion.
Fix
from app.services.llm.utils import convert_chat_messages_to_llm_format
history = convert_chat_messages_to_llm_format(reversed(history_r.scalars().all()))
Steps to Reproduce
- Configure an agent with WeChat channel
- Send a message that triggers a tool call
- After tool call completes, send another message
- LLM call fails with HTTP 400
Environment
- Clawith v1.10.3 (main branch)
- File: backend/app/services/wechat_channel.py, line 249
Bug Description
wechat_channel.py line 249 directly uses m.role from the database when building LLM history. Tool call logs are stored
with role="tool_call" in ChatMessage, but this is an internal role — it should be converted to standard OpenAI format
(assistant + tool_calls followed by tool result) before sending to the LLM API.
This causes HTTP 400 with providers that strictly validate role (e.g. Agnes AI):
messages[2].role: unknown variant tool_call, expected one of system, user, assistant, tool, latest_reminder
Root Cause
wechat_channel.py line 249 (buggy)
history = [{"role": m.role, "content": m.content} for m in reversed(history_r.scalars().all())]
All other channels correctly use convert_chat_messages_to_llm_format(): feishu.py, dingtalk.py, discord_bot.py,
slack.py, teams.py, gateway.py, websocket.py. WeChat is the only channel that skips this conversion.
Fix
from app.services.llm.utils import convert_chat_messages_to_llm_format
history = convert_chat_messages_to_llm_format(reversed(history_r.scalars().all()))
Steps to Reproduce
Environment