Skip to content

fix: enrich file attachment fallback context - #10175

Open
iuiu-py wants to merge 4 commits into
AstrBotDevs:masterfrom
iuiu-py:fix/file-attachment-fallback-context
Open

iuiu-py wants to merge 4 commits into
AstrBotDevs:masterfrom
iuiu-py:fix/file-attachment-fallback-context

Conversation

@iuiu-py

@iuiu-py iuiu-py commented Sep 21, 2026

Copy link
Copy Markdown

Motivation

When file extraction is disabled, the file fallback only tells the model about the downloaded local path. The original file URL is lost, and the model is not explicitly told how to inspect the downloaded attachment. This makes it harder for models to handle file-only messages. Fixes #8997.

Changes

  • Added a shared formatter for normal and quoted file attachment fallback text.
  • Included the source URL when the platform provides one.
  • Told the model to use astrbot_file_read_tool with the local path when that tool is available.
  • Kept the existing path-only fallback format for attachments without a URL.
  • Applied Ruff formatting to an existing long test signature so the format check passes.

Testing

  • Added regression tests for normal and quoted file-only messages, with and without a URL.
  • uv run pytest tests/unit/test_astr_main_agent.py -q - 143 passed.
  • uv run ruff format --check .
  • uv run ruff check .

Summary by Sourcery

Improve file attachment fallback messages so models retain source context and know how to inspect downloaded files.

Bug Fixes:

  • Enrich file attachment fallback context with the source URL when available and guidance for inspecting the downloaded file with the file-reading tool.

Enhancements:

  • Use a shared formatter for normal and quoted file attachment fallback text while preserving path-only output when no URL is provided.

Tests:

  • Add regression coverage for normal and quoted file-only messages with and without source URLs.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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.

file_extract 默认关闭导致文件内容丢失,LLM 只看到 [File] 占位符

1 participant