fix(telegram): expose inbound media as tool-accessible attachments (#20899) - #20906
Closed
tymrtn wants to merge 1 commit into
Closed
fix(telegram): expose inbound media as tool-accessible attachments (#20899)#20906tymrtn wants to merge 1 commit into
tymrtn wants to merge 1 commit into
Conversation
…ousResearch#20899) Closes NousResearch#20899. Telegram inbound photos and documents are now downloaded into a profile-scoped, chat-scoped attachment cache and surfaced to the agent as tool-readable local file paths. The agent can then use file/terminal tools to copy, move, or otherwise organise user-provided media without asking the user to resend. Changes: - gateway/platforms/base.py: add cache_inbound_attachment helper + MessageEvent.attachments field. Cache layout: <hermes_home>/cache/attachments/<platform>/<chat_id>/<message_id>/<filename> Path traversal is sanitised; collisions are disambiguated. - gateway/platforms/telegram.py: _handle_media_message mirrors photos (largest PhotoSize) and documents (original filename preserved) into the attachment cache and populates event.attachments alongside the existing vision-route media_urls. - gateway/run.py: when event.attachments is present, prepend a structured 'Inbound attachments cached locally' block listing each attachment as 'filename (mime, size): /abs/path'. The agent now sees a tool-accessible path even when the image is also routed via native vision. - tests/gateway/test_telegram_attachments.py: 6 new tests covering cache layout, path-traversal protection, photo/document inbound, cross-chat isolation, and PhotoSize selection.
Contributor
|
Thanks for the careful attachment-cache implementation. The tool-accessible native-image path behavior is already present on current Automated hermes-sweeper review evidence:
The linked #20971 discussion identified this narrower shared resolution path. This PR's duplicate cache/event-field implementation also targets files that have since moved to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #20899.
Problem
Telegram inbound photos/documents were visible to the model via the vision pipeline but had no tool-accessible local path. The agent could analyse an image but could not copy or move it on user request without asking the user to resend.
Fix
Mirror inbound photos and documents into a profile-scoped, chat-scoped attachment cache, and surface the cached path to the agent's user-message context so file/terminal tools can act on it.
Cache layout
<hermes_home>/cache/attachments/<platform>/<chat_id>/<message_id>/<filename>Path-traversal-sanitised; per-chat directories prevent cross-chat reads; collisions are disambiguated by suffix.
Code changes
gateway/platforms/base.py: newcache_inbound_attachment()helper,MessageEvent.attachments: list[dict]field with{path, filename, mime_type, size, platform, message_id, chat_id}.gateway/platforms/telegram.py:_handle_media_messagewrites through to the attachment cache (largest PhotoSize for photos, original filename for documents) and mergesattachmentsinto single-message and album/media-group events.gateway/run.py: prepends a structured[Inbound attachments cached locally — use file/terminal tools to read, copy, or move them]block listing each cached file as- filename (mime, size): /abs/pathbefore the existing document-context injection.Tests
tests/gateway/test_telegram_attachments.py(6 tests, all passing):Local regression scope:
tests/gateway/test_telegram_*.py→ 147/147 passing.Notes
Builds on the existing
cache_image_from_bytes/cache_document_from_bytesvision-route caches. The new attachment cache is structurally distinct so cross-chat isolation is preserved at the path layer, not just in field naming.Retention/gc is left as future work; existing media is not deleted automatically.