agent_runtime_helpers_placeholders.py 1.7 KB

1234567891011121314151617181920212223242526
  1. """Interrupt placeholder wording substituted into empty non-final wire rows.
  2. Split out of ``agent/agent_runtime_helpers.py`` (code-health size ratchet); a leaf module with no
  3. imports so every reader (runtime helpers, turn prep, the conversation loop) can import it directly.
  4. """
  5. # Placeholder for an empty non-final message the provider would reject. This is the single source of
  6. # the wording: every healing path imports it from here, so healed transcripts read consistently.
  7. #
  8. # Wording matters: this text is substituted into an assistant row's ``content`` on the wire copy
  9. # (``fill_empty_non_final_wire_payload``, ``repair_empty_non_final_messages``, and the projection in
  10. # ``run_conversation``), so the model reads it as something IT said. A short natural-language phrase
  11. # in that position gets echoed verbatim — a clean ``finish_reason=stop`` turn answering an ordinary
  12. # instruction with just the placeholder (#132949, and #81841 for the same hazard on the scaffold).
  13. # Keep it a structural label the model has no conversational reason to reproduce, never prose.
  14. _INTERRUPTED_PLACEHOLDER = "[interrupt: no assistant output for this turn]"
  15. # The spelling shipped before #132949. Models reproduce it verbatim, so rows already carrying it
  16. # stay poisoned after the wording change; the replay filters reference this name to retire them.
  17. _LEGACY_INTERRUPTED_PLACEHOLDER = "[response interrupted]"
  18. def hidden_interrupt_placeholder_row() -> dict:
  19. """A fresh assistant row that is invisible in transcripts but carries the placeholder as its
  20. non-empty ``api_content``, so the pre-call sanitizer does not re-heal it every call (#88955)."""
  21. return {"role": "assistant", "content": "", "display_kind": "hidden", "api_content": _INTERRUPTED_PLACEHOLDER}