From 151b0963712e913a1efd55054c3d7ae8da882e18 Mon Sep 17 00:00:00 2001 From: Hermes Agent Bot Date: Wed, 8 Jul 2026 12:23:13 +0000 Subject: [PATCH] fix: merge stray top-level system kwarg into messages array in Chat Completions transport (#60821) --- agent/transports/chat_completions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/agent/transports/chat_completions.py b/agent/transports/chat_completions.py index ff2cdcbaee69..deb0bf268599 100644 --- a/agent/transports/chat_completions.py +++ b/agent/transports/chat_completions.py @@ -569,6 +569,20 @@ def _build_kwargs_from_profile(self, profile, model, sanitized, tools, params): for k, v in overrides.items(): if k == "extra_body" and isinstance(v, dict): extra_body.update(v) + elif k == "system" and sanitized: + # system prompt as a top-level kwarg is invalid for + # OpenAI Chat Completions — it must be part of the + # messages array. Merge it into the first message when + # the caller accidentally forwards it via overrides. + # (#60821 — SiliconFlow/OpenRouter custom endpoints) + if sanitized[0].get("role") == "system": + sanitized[0] = { + **sanitized[0], + "content": (sanitized[0].get("content") or "") + + "\n" + str(v) if sanitized[0].get("content") else str(v), + } + else: + sanitized.insert(0, {"role": "system", "content": str(v)}) else: api_kwargs[k] = v