mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-21 07:55:08 +00:00
fix: exempt codex_responses from the empty-assistant-content pads
Commentary-phase Codex turns persist with content:'' by design (their text is delivered via the interim assistant callback), and the Responses wire has no 'assistant must not be empty' validation — padding them broke test_run_conversation_codex_continues_after_commentary_phase_message in CI. Both the builder pad and the send-time pad now skip api_mode=codex_responses. Keying on the ACTIVE api_mode preserves the repair for codex-written sessions replayed through a strict chat-completions provider.
This commit is contained in:
parent
25a8574592
commit
5e88745f12
2 changed files with 28 additions and 10 deletions
|
|
@ -1392,7 +1392,18 @@ def build_assistant_message(agent, assistant_message, finish_reason: str) -> dic
|
|||
# the same trick the reasoning_content pad uses above (#15250, #17400).
|
||||
# Tool-call turns are exempt: ``content: ""`` alongside ``tool_calls``
|
||||
# is accepted everywhere and normalizing it would alter cache keys.
|
||||
if not _san_content and not assistant_tool_calls:
|
||||
# codex_responses is exempt too: empty assistant content is a designed
|
||||
# first-class state there (commentary-phase messages persist with
|
||||
# content:"" while their text is delivered via the interim callback),
|
||||
# and the Responses wire has no "assistant must not be empty"
|
||||
# validation. A codex session later replayed through a strict
|
||||
# chat-completions provider is still repaired by the send-time pad,
|
||||
# which keys on the ACTIVE api_mode at replay time.
|
||||
if (
|
||||
not _san_content
|
||||
and not assistant_tool_calls
|
||||
and getattr(agent, "api_mode", None) != "codex_responses"
|
||||
):
|
||||
_san_content = " "
|
||||
|
||||
msg = {
|
||||
|
|
|
|||
|
|
@ -1653,15 +1653,22 @@ def run_conversation(
|
|||
# turn), but BEFORE apply_anthropic_cache_control rewrites content
|
||||
# into list blocks. Tool-call turns are exempt: ``content: ''``
|
||||
# alongside ``tool_calls`` is accepted everywhere and normalizing
|
||||
# it would alter prompt-cache keys.
|
||||
for am in api_messages:
|
||||
if (
|
||||
am.get("role") == "assistant"
|
||||
and not am.get("tool_calls")
|
||||
and isinstance(am.get("content"), str)
|
||||
and not am["content"].strip()
|
||||
):
|
||||
am["content"] = " "
|
||||
# it would alter prompt-cache keys. codex_responses is exempt:
|
||||
# empty assistant content is a designed first-class state there
|
||||
# (commentary-phase turns persist with content:'') and the
|
||||
# Responses wire has no empty-content validation. Keying on the
|
||||
# ACTIVE api_mode means a codex-written empty turn is still
|
||||
# repaired the moment the session replays through a strict
|
||||
# chat-completions provider.
|
||||
if getattr(agent, "api_mode", None) != "codex_responses":
|
||||
for am in api_messages:
|
||||
if (
|
||||
am.get("role") == "assistant"
|
||||
and not am.get("tool_calls")
|
||||
and isinstance(am.get("content"), str)
|
||||
and not am["content"].strip()
|
||||
):
|
||||
am["content"] = " "
|
||||
|
||||
# Apply Anthropic prompt caching for Claude models on native
|
||||
# Anthropic, OpenRouter, and third-party Anthropic-compatible
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue