Files
hakastein cdfa0ffa89 fix(agent): decode auxiliary Relay requests as chat completions
Relay intercepts the adapter's chat.completions.create call at the three
auxiliary seams, so it must use the chat codec. The native api_mode made
it pick the Responses codec for openai-codex and reject every MoA
reference with 'OpenAI Responses request is missing input'.
2026-10-15 16:26:05 +05:30

34 lines
1.3 KiB
Python

"""Message hygiene at the resolved auxiliary client boundary."""
from openai import AsyncOpenAI, OpenAI
from agent.transports.chat_completions import ChatCompletionsTransport
def prepare_chat_messages(client, kwargs: dict) -> dict:
"""Sanitize actual Chat Completions SDK requests, not native adapter replay.
Auxiliary and MoA callers can retain a prepared request before the virtual
transport sanitizes its copy. The resolved SDK client identifies the wire;
native Messages/Responses adapters must retain their reasoning sidecars.
"""
if not isinstance(client, (OpenAI, AsyncOpenAI)) or "messages" not in kwargs:
return kwargs
from agent.reasoning_carriers import shape_wire_carriers
base_url = str(getattr(client, "base_url", "") or "")
messages = ChatCompletionsTransport().convert_messages(
shape_wire_carriers(kwargs["messages"], model=kwargs.get("model"), base_url=base_url),
model=kwargs.get("model"), base_url=base_url,
)
return {**kwargs, "messages": messages}
def relay_chat_metadata(metadata: dict) -> dict:
"""Relay metadata for an auxiliary attempt.
Relay intercepts ``client.chat.completions.create``, so it decodes a chat-completions
request even when the adapter speaks Responses or Messages to its provider.
"""
return {**metadata, "api_mode": "chat_completions"}