diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py index 4ae71cbb3a37..0c997ff42843 100644 --- a/agent/prompt_builder.py +++ b/agent/prompt_builder.py @@ -884,7 +884,13 @@ PLATFORM_HINTS = { "You're responding through an API server. The rendering layer is unknown — " "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." + "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." ), "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 633fde7c02d9..e1ef1dd170d6 100644 --- a/tests/agent/test_prompt_builder.py +++ b/tests/agent/test_prompt_builder.py @@ -1103,6 +1103,19 @@ 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.""" + hint = PLATFORM_HINTS["api_server"] + assert "MEDIA:" in hint + assert "not" in hint.lower() + def test_markdown_converting_platform_hints_do_not_forbid_markdown(self): """#12224 — WhatsApp (Baileys) and Signal adapters actively convert markdown to native formatting (gateway/platforms/whatsapp_common.py