[16.0] llm_anthropic: KeyError 'role' — missing format_messages implementation
#228 aberto em 16 de fev. de 2026
Métricas do repositório
- Stars
- (210 estrelas)
- Métricas de merge de PR
- (Métricas PR pendentes)
Description
Bug Description
The llm_anthropic module is missing the format_messages / format_message infrastructure that other providers (e.g., llm_openai) implement. This causes a KeyError: 'role' when anthropic_chat() receives mail.message records instead of pre-formatted dicts.
Steps to Reproduce
- Install
llm,llm_anthropic,llm_thread,llm_assistant,llm_tool - Configure an Anthropic provider with a valid API key
- Create a model, assistant, prompt, and thread
- Send a message via the chat UI or SSE endpoint
GET /llm/thread/generate?thread_id=X&message=Y
Expected Behavior
Assistant responds with LLM-generated content.
Actual Behavior
SSE returns:
data: {"type": "error", "error": "'role'"}
data: {"type": "done"}
Root Cause
The flow is:
llm_assistant/models/llm_thread.py→_generate_assistant_response()callsself.get_llm_messages()which returns amail.messagerecordset- This recordset is passed through
model.chat()→provider.chat()→anthropic_chat() anthropic_chat()iterates messages doingmsg["role"]— butmail.messagerecords have the fieldllm_role, notrole
The llm_openai module handles this correctly by implementing:
openai_format_messages()onllm.provider(converts recordset to list of dicts)openai_format_message()onmail.message(converts a single record)openai_chat()uses_prepare_chat_params()which callsformat_messages()
The llm_anthropic module has none of this — anthropic_chat() directly iterates the raw recordset assuming dict-like role/content keys.
Proposed Fix
Add anthropic_format_message() to mail.message and anthropic_format_messages() to llm.provider, following the same pattern as llm_openai. Then update anthropic_chat() to use _prepare_chat_params_base() or call format_messages() before processing.
Environment
- Odoo 16 Enterprise (Clodofy hosting)
llmv16.0.1.4.2llm_anthropicv16.0.1.1.0llm_threadv16.0.1.3.2llm_assistantv16.0.1.5.3llm_toolv16.0.3.0.0