fix(codex_adapter): skip unsupported message roles in Responses API input

The _CodexCompletionsAdapter passed all non-system message roles through
to the Codex Responses endpoint unchanged. The endpoint only accepts
user and assistant roles in the input array; tool/function messages
(from prior memory flush calls in the session) caused HTTP 400:
'Invalid value: tool. Supported values are: assistant, system,
developer, and user.'

Changes:
- Skip role='tool' and role='function' messages (tool results not
  needed for the flush summary context)
- Map role='developer' to instructions, same as role='system'
- Silently skip any other unknown roles rather than sending them
- Note: temperature was already stripped in run_agent.py (prior commit)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Basit Mustafa 2026-04-24 15:30:35 -07:00
parent 3756d84dfe
commit fef29cc812

View file

@ -367,18 +367,26 @@ class _CodexCompletionsAdapter:
# Separate system/instructions from conversation messages.
# Convert chat.completions multimodal content blocks to Responses
# API format (input_text / input_image instead of text / image_url).
# The Codex Responses endpoint only accepts user/assistant roles in
# input — skip tool/function messages and map system/developer to
# instructions.
_RESPONSES_INPUT_ROLES = {"user", "assistant"}
instructions = "You are a helpful assistant."
input_msgs: List[Dict[str, Any]] = []
for msg in messages:
role = msg.get("role", "user")
content = msg.get("content") or ""
if role == "system":
if role in ("system", "developer"):
instructions = content if isinstance(content, str) else str(content)
else:
elif role in ("tool", "function"):
# Codex Responses endpoint does not support tool/function roles
continue
elif role in _RESPONSES_INPUT_ROLES:
input_msgs.append({
"role": role,
"content": _convert_content_for_responses(content),
})
# Unknown roles: skip rather than send an unsupported value
resp_kwargs: Dict[str, Any] = {
"model": model,