fix(prompt): scope api_server MEDIA: hint to actual interception behavior

Correction to the previous commit (PR #68402): the claim that api_server
never intercepts MEDIA: tags is inaccurate on current main.
_resolve_media_to_data_urls() (gateway/platforms/api_server.py) DOES
inline image MEDIA: tags (<=5MB, image extensions only) as base64 data
URLs on the four main endpoints (_handle_session_chat,
_handle_session_chat_stream, _handle_chat_completions, _handle_responses).

The real gaps elphamale's PR points at are narrower:
- the /v1/runs output path (_handle_runs) never calls the resolver;
- non-image filetypes are never resolved anywhere (_MEDIA_IMG_EXT is
  image-only).

Reword the hint to teach both halves: images via MEDIA: work on the
chat/completions/responses endpoints; non-image files and anything on
the runs endpoint must fall back to plain file paths in the response
text. Update the test to pin the scoped guidance instead of a blanket
prohibition.
This commit is contained in:
Teknium 2026-07-23 08:21:17 -07:00
parent 08abc5eba8
commit cd6fb2b167
2 changed files with 23 additions and 16 deletions

View file

@ -885,12 +885,13 @@ PLATFORM_HINTS = {
"assume plain text. No markdown formatting (no asterisks, bullets, headers, "
"code fences). Treat this like a conversation, not a document. Keep responses "
"brief and natural. "
"File/media delivery: do NOT emit MEDIA:/path tags in your response — "
"that convention is only intercepted on messaging platforms (Telegram, "
"WebUI, etc.); here it renders as literal, unusable text exposing a raw "
"host filesystem path to the caller. If a registered file-delivery tool "
"is available in your toolset, use it; otherwise there is no channel to "
"deliver a file on this platform."
"File/media delivery: images referenced as MEDIA:/absolute/path tags "
"(.png/.jpg/.jpeg/.gif/.webp/.bmp, up to 5MB) are inlined as base64 data "
"URLs in responses on the chat, completions, and responses endpoints. "
"Non-image files are NOT intercepted anywhere, and the runs endpoint "
"intercepts nothing — a MEDIA: tag there renders as literal text exposing "
"a raw host filesystem path. For those cases, state the plain file path "
"in your response text instead of a MEDIA: tag."
),
"webui": (
"You are in the Hermes WebUI, a browser-based chat interface. "

View file

@ -1103,18 +1103,24 @@ class TestPromptBuilderConstants:
hint = PLATFORM_HINTS["whatsapp_cloud"]
assert "MEDIA:" in hint
def test_api_server_hint_forbids_media_tag(self):
"""api_server has no MEDIA: interception (unlike telegram/webui/etc.,
which resolve it to an attachment or a validated/inlined data URL)
_handle_runs never calls the resolver other api_server endpoints use.
Without an explicit prohibition, the model's general cross-platform
habit of using MEDIA:/path for file delivery (correct and taught for
several other platforms in this same dict) can surface here too, with
no interception to catch it: the tag renders as literal text in the
response, exposing a raw host filesystem path to the API caller."""
def test_api_server_hint_scopes_media_tag_guidance(self):
"""api_server MEDIA: interception is partial (#68402, corrected):
_resolve_media_to_data_urls (gateway/platforms/api_server.py) inlines
small image MEDIA: tags as base64 data URLs on the chat, completions,
and responses endpoints but non-image files are never resolved
(_MEDIA_IMG_EXT is image-only) and the /v1/runs handler never calls
the resolver at all. The hint must teach BOTH halves: images work via
MEDIA:, everything else needs a plain path in the response text."""
hint = PLATFORM_HINTS["api_server"]
# Images ARE intercepted: inlined as data URLs.
assert "MEDIA:" in hint
assert "not" in hint.lower()
assert "inlined" in hint.lower()
assert "data" in hint.lower() # data URLs
# The gaps: non-image files and the runs endpoint.
assert "non-image" in hint.lower()
assert "runs" in hint.lower()
# Fallback guidance: plain file path in the response text.
assert "plain" in hint.lower()
def test_markdown_converting_platform_hints_do_not_forbid_markdown(self):
"""#12224 — WhatsApp (Baileys) and Signal adapters actively convert