Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions agent/transports/chat_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and sanitized leaves an empty messages list on the final else, which still forwards the invalid top-level system kwarg. Handle the empty-list case by inserting a system message too.

# 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 "")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System content can be a non-empty content-parts list (tests/providers/test_provider_profiles.py:471); adding "\n" to it raises TypeError. Merge only strings, or insert a separate system message for non-string content.

+ "\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

Expand Down
Loading