From cd6fb2b167bb4ffa6fc9483ff7edd31ae582a05a Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 23 Jul 2026 08:21:17 -0700 Subject: [PATCH] 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. --- agent/prompt_builder.py | 13 +++++++------ tests/agent/test_prompt_builder.py | 26 ++++++++++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py index 0c997ff42843..fc94ca2a6b22 100644 --- a/agent/prompt_builder.py +++ b/agent/prompt_builder.py @@ -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. " diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py index e1ef1dd170d6..d0639c227457 100644 --- a/tests/agent/test_prompt_builder.py +++ b/tests/agent/test_prompt_builder.py @@ -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