Repository navigation
Description
Bug Description
In a Telegram group chat, a photo sent without an explicit bot @mention never reaches the model. The agent acts as if no attachment arrived — it repeatedly asks the user to "re-send the attachment," guesses from stale cache, or claims nothing came through. The same image works when (a) re-sent as a PDF document, or (b) sent with an @bot mention in the same message.
Root cause is in the observed-group-context assembly in gateway/run.py: observed message content is coerced with str(content), which mangles a multimodal parts list (text + image_url) into a Python repr string. The actual image is lost and the context prefix is polluted with {'type': 'image_url', ...} noise.
This is not a download/routing failure — the gateway logs Image routing: native … attached inline and the file is cached. It is corrupted at history assembly, and only for observed (unmentioned) group turns.
Steps to Reproduce
- Telegram group with the bot,
observe_unmentioned_group_messagesenabled (observed-context prompt active). - Send a photo to the group without mentioning the bot.
- Later/again, prompt the bot (e.g.
@bot what was in that image?). - The model has no usable image; it asks for a re-send.
- Re-send the same image with
@botin the message → works (native inline path, bypasses the observed accumulator).
Expected Behavior
An observed group photo should be represented in the replayed context as text (e.g. its caption plus an [image attachment] placeholder) — never as a stringified Python dict. The observed-context prefix is text-only by design (_wrap_current_message_with_observed_context), so multimodal content must be flattened to text rather than str()-ed.
Actual Behavior
observed_group_context.append(str(content).strip()) turns a multimodal list:
[{"type": "text", "text": "[Alice|111] here's the desk sheet"},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}]into the literal string "[{'type': 'text', 'text': '...'}, {'type': 'image_url', 'image_url': {'url': 'data:image/png;base64,...'}}]", which is then prepended as the observed-context prefix. The image content is unusable and the prefix is polluted.
Affected Component
- Gateway (Telegram/Discord/Slack/WhatsApp)
Messaging Platform (if gateway-related)
- Telegram
Debug Report
Not run intentionally — this was diagnosed on a production deployment, and
hermes debug sharewould upload that instance's config/secrets/logs to a public paste service. Inline evidence below instead.
# gateway.log (per photo send) — image WAS routed:
Image routing: native (model supports vision). 1 image(s) will be attached inline.
# agent.log turn_context — but the turn is observed-only:
msg='[1 image] [Observed Telegram group context - context only, not requests] [Alice|...'
# images present on disk (download succeeded), e.g. /opt/data/image_cache/img_*.jpg
# code: gateway/run.py, _build_gateway_agent_history
content = msg.get("content")
if separate_observed_context and msg.get("observed") and role == "user" and content:
observed_group_context.append(str(content).strip()) # <-- str() on a multimodal list
continueOperating System
Debian GNU/Linux 13 (trixie) — official nousresearch/hermes-agent container
Python Version
3.13.5
Hermes Version
0.16.0 (main; container image built 2026-06-15, revision 5f6be7f)
Root Cause Analysis (optional)
gateway/run.py → _build_gateway_agent_history: the observed-context branch does observed_group_context.append(str(content).strip()). For text messages str(str) is a no-op, so the bug only surfaces once content is a multimodal list (photo). The accumulated observed_group_context is later joined and replayed as a text prefix via _wrap_current_message_with_observed_context, so the image cannot survive there regardless — it must be flattened to text deliberately.
Proposed Fix (optional)
Add a helper that renders observed content as plain text — keep text parts, replace image_url/other parts with a short placeholder ([image attachment]) — and call it instead of str(content). PR attached.
Are you willing to submit a PR for this?
- I'd like to fix this myself and submit a PR
Activity
gitsacha commentedon Jul 17, 2026
Correcting my own root-cause analysis — the symptom is real, the mechanism I described is not.
I claimed observed
contentis a multimodal parts list mangled bystr(). It is not. Verified on currentmainby driving_handle_media_messagewith an unmentioned group photo — the persisted content is a plainstrcarrying a cached-path note:The real asymmetry:
_cache_observed_media()caches the image and appends[image '...' saved at: <path>]to the observed text, but the image is never attached inline. The @mention path dispatches the event withmedia_urlsand the model receives the image natively; the observed path only ever replays a text note. That is why re-sending with@botworks.So the fix is not flattening (see #47416, which I have closed as a no-op). Leaving this open with an accurate diagnosis for maintainer triage.
thanks!
GottZ commentedon Aug 3, 2026
Summary
Four PRs address or reference #47415. #47416, #47427, and #47584 flatten hypothetical list-shaped observed content, but the corrected diagnosis shows that Telegram persists observed photos as plain text; #73661 instead targets the actual loss of image metadata between observation and the next addressed turn.
Related pull requests
unrelated— (+75/-1) — unrelated/no-op; remains relevant as the canonical version of the discarded flattening approach. Despite the visible keep_open review on fix(gateway): flatten observed-group multimodal content to text #47416, the later author probe through_handle_media_messageshowed that the observed Telegram producer stores a plainstr, so the diff's helper leaves real-path content byte-identical and its synthetic list-shaped regression test does not exercise the reported flow.unrelated— (+27/-1) — unrelated duplicate; remains relevant because contributors identified it as the same call-site change as fix(gateway): flatten observed-group multimodal content to text #47416 and closed it in favor of that earlier PR. Its diff only replacesstr(content).strip()with multimodal flattening, so it does not preserve or replay the cached observed image that the corrected diagnosis identifies as missing.unrelated— (+134/-1) — unrelated duplicate; remains relevant because it was closed in favor of fix(gateway): flatten observed-group multimodal content to text #47416 after implementing the same flattening mechanism with additional synthetic list-content tests. Those tests cover placeholder rendering rather than the actual Telegram path, which persists attributed text and drops native image metadata.best fix— (+542/-4) — best existing fix; the supplied Graph-cache diff targets the corrected cause by persisting observedmedia_urls/media_types, collecting bounded trailing observed images for the next addressed turn, and reloading the persisted observed tail for queued follow-ups. Consistent with the visible maintainer-bot keep_open verdict, the updated diff includes the requested active-turn → observed-photo → queued-addressed-turn regression coverage, making this the only PR here that addresses both the normal and queued paths.Duplicates
#47427 and #47584 are substantive duplicates of #47416: all three replace the observed-context
str(content)call with text-flattening helpers, but none addresses the corrected media-persistence asymmetry. #73661 supersedes that approach rather than duplicating it.Suggested consolidation
Keep #73661 open with a salvage path as the best existing fix: preserve its structural observed-media persistence, bounded native-image collection, queued observed-tail reload, and normal/queued regression coverage, then validate those paths against current main before further disposition. Keep #47416 closed despite its earlier keep_open review because the producer-path probe invalidated its premise; keep #47427 and #47584 closed as duplicates of #47416.
Complex graph
flowchart LR classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937 classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151 classDef best stroke-width:3px,stroke:#b45309 classDef target stroke-width:3px,stroke:#4338ca I47415(["issue #47415 (open)"]) P73661["PR #73661 (open)"] subgraph Dup47416 ["PRs duplicating each other"] P47416["PR #47416 (closed)"] P47427["PR #47427 (closed)"] P47584["PR #47584 (closed)"] end P73661 -->|best fix| I47415 class I47415 open class I47415 target class P47416 closed class P47427 closed class P47584 closed class P73661 open class P73661 best click I47415 "https://github.com/NousResearch/hermes-agent/issues/47415" click P47416 "https://github.com/NousResearch/hermes-agent/pull/47416" click P47427 "https://github.com/NousResearch/hermes-agent/pull/47427" click P47584 "https://github.com/NousResearch/hermes-agent/pull/47584" click P73661 "https://github.com/NousResearch/hermes-agent/pull/73661"Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).
Cross-PR triage: Reviewed 4 pull requests and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 36 kB of PR diffs, 16 kB of issue/PR text, 7 kB of discussion (10 comments), 3 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
fix(gateway): attach observed group images to the next addressed turn
fix(telegram): observed group photos tell the agent where the file is…
fix(gateway): attach observed group images to the next addressed turn
fix(telegram): observed group photos tell the agent where the file is…
fix(telegram): observed group photos tell the agent where the file is…