Files
hermes-agent/agent/auxiliary_wire.py
Teknium ebe4e7bb44 fix: sanitize resolved auxiliary chat requests before dispatch
Extend the destination-boundary approach from PR #87840 to synchronous, asynchronous and streaming auxiliary dispatch, including prepared MoA requests. Keep native adapter replay intact.

Co-authored-by: siyoon <siyoon@friendli.ai>
2026-09-07 06:02:22 -07:00

21 lines
829 B
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
messages = ChatCompletionsTransport().convert_messages(
kwargs["messages"], model=kwargs.get("model")
)
return {**kwargs, "messages": messages}