Skip to content

fix(llm): surface attached image filename in model context - #41798

Closed
patil2001 wants to merge 1 commit into
anomalyco:devfrom
patil2001:fix/llm-include-media-filename-in-context
Closed

fix(llm): surface attached image filename in model context#41798
patil2001 wants to merge 1 commit into
anomalyco:devfrom
patil2001:fix/llm-include-media-filename-in-context

Conversation

@patil2001

Copy link
Copy Markdown

Summary

When a user attaches an image in the TUI, the attachment chip shows the original filename (e.g. IMG_3480.JPG), and the filename survives all the way into MediaPart.filename — but every provider lowering drops it before building the request. The model receives only the image content, so it cannot identify or reference the attached file.

This PR emits the filename as a caption text part alongside the image in the user message for the four image-capable protocols:

  • OpenAI Chat (openai-chat)
  • OpenAI Responses (openai-responses)
  • Anthropic Messages (anthropic-messages)
  • Gemini (gemini)

Bedrock Converse already preserves filename for document blocks, so it is left unchanged.

Changes

  • packages/llm/src/protocols/shared.ts: new mediaCaption(part) helper producing [Image: <filename>] when a filename is present.
  • Each protocol's user-content lowering now prepends that caption text before the image content.
  • Added prepare-layer tests for all four protocols asserting the caption appears alongside the image.

Test plan

  • bun test in packages/llm: 302 pass, 0 fail.
  • tsgo --noEmit in packages/llm: clean.

Fixes #41454

Provider lowerings (OpenAI Chat/Responses, Anthropic, Gemini) dropped the
MediaPart.filename that survives attachment ingestion, so the model could
see the image content but never the original file name. Emit the filename as
a caption text part alongside the image so agents can reference the attached
file.

Fixes anomalyco#41454
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential related PR found:

However, this is not a duplicate. PR #41798 is focused on adding filename captions in the LLM protocols when passing images to models, while PR #41789 likely handles exposing attachment paths at the core level. These are complementary changes addressing different layers of the same feature.

No duplicate PRs found.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 11, 2026
@github-actions github-actions Bot closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tui: attached image path is omitted from model context

1 participant