mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
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'.
34 lines
1.3 KiB
Python
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"}
|