A cron agent runs as platform "cron", so its system prompt only ever got PLATFORM_HINTS["cron"]. The job's final response lands on the `deliver` channel (Slack, Telegram, ...), but the model was never told what renders there: no MEDIA: attachment instructions, no "tables don't render", and a user's `platform_hints.slack.append` never reached scheduled jobs at all (community report: Slack-delivered cron jobs stopped sending attachments). platform_hint() now appends "Delivery destination (<channel>): <hint>" for cron agents, where <hint> is the channel's built-in/plugin text resolved through the same `platform_hints.<channel>` override path a live session uses. The channel comes from the HERMES_CRON_AUTO_DELIVER_PLATFORM ContextVar the scheduler publishes before the agent runs (the seam send_message already routes by). Non-cron platforms are untouched.
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""A cron agent's system prompt carries its delivery channel's hint.
|
|
|
|
Cron agents run as platform ``cron`` but the final response lands on the job's ``deliver``
|
|
channel. Without the destination hint the model never learns that MEDIA: tags become native
|
|
attachments there, and ``platform_hints.<channel>.append`` never reached scheduled jobs
|
|
(community report: Slack-delivered cron jobs stopped sending attachments).
|
|
"""
|
|
|
|
import types
|
|
|
|
import pytest
|
|
|
|
from agent.prompt_builder import PLATFORM_HINTS
|
|
from agent.system_prompt import platform_hint
|
|
from gateway.session_context import _VAR_MAP
|
|
|
|
EXTRA = "Always attach the report as a .pdf."
|
|
|
|
|
|
def _agent(platform, overrides=None):
|
|
return types.SimpleNamespace(platform=platform, _platform_hint_overrides=overrides or {})
|
|
|
|
|
|
@pytest.fixture
|
|
def deliver_to(monkeypatch):
|
|
var = _VAR_MAP["HERMES_CRON_AUTO_DELIVER_PLATFORM"]
|
|
token = var.set("slack")
|
|
monkeypatch.delenv("HERMES_DESKTOP_TERMINAL", raising=False)
|
|
yield
|
|
var.reset(token)
|
|
|
|
|
|
def test_cron_agent_gets_delivery_channel_hint_with_its_override(deliver_to):
|
|
hint = platform_hint(_agent("cron", {"slack": {"append": EXTRA}}))
|
|
assert hint.startswith(PLATFORM_HINTS["cron"])
|
|
assert PLATFORM_HINTS["slack"] in hint
|
|
assert EXTRA in hint
|
|
# The cron hint's own override channel is untouched by the destination's.
|
|
assert platform_hint(_agent("cron", {"cron": {"replace": "X"}})).startswith("X\n\n")
|
|
|
|
|
|
def test_delivery_target_only_applies_to_cron_agents(deliver_to):
|
|
assert platform_hint(_agent("telegram")) == PLATFORM_HINTS["telegram"]
|
|
_VAR_MAP["HERMES_CRON_AUTO_DELIVER_PLATFORM"].set("")
|
|
assert platform_hint(_agent("cron")) == PLATFORM_HINTS["cron"]
|