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