Skip to content

fix(memory): skip file content parts unsupported by the target model in history replay - #41192

Open
engmohamedsalah wants to merge 2 commits into
langgenius:mainfrom
engmohamedsalah:fix/history-attachments-unsupported-models
Open

fix(memory): skip file content parts unsupported by the target model in history replay#41192
engmohamedsalah wants to merge 2 commits into
langgenius:mainfrom
engmohamedsalah:fix/history-attachments-unsupported-models

Conversation

@engmohamedsalah

Copy link
Copy Markdown

Fixes #41059

Summary

When a conversation's second turn arrives, TokenBufferMemory replays earlier turns and re-sends every past attachment as a native prompt content part — regardless of what the invoked model actually supports. On models whose provider does not implement document input (e.g. Qwen served via vLLM), the request fails with:

400 Unsupported chat content part type: 'file'

This change gates each converted history file part on the model schema's declared features using the existing AIModelEntity.supports_prompt_content_type() primitive:

  • Supported content types → unchanged, sent natively
  • Unsupported content types (e.g. documents replayed to a text/vision-only model) → degraded to a text note ([Unsupported file type: document]) so earlier turns keep contributing context instead of breaking the request
  • Unresolvable model schema → previous send-anyway behavior preserved

Current-turn files are untouched; this only affects history replay.

Testing

  • 3 new unit tests in tests/unit_tests/core/memory/test_token_buffer_memory.py:
    • unsupported document parts are replaced with text (regression for this issue)
    • supported image parts are still sent when VISION is declared
    • unresolved model schemas keep the old behavior
  • Full file suite: 61 passed
  • ruff check + ruff format --check clean

…in history replay

Conversation history rebuilt by TokenBufferMemory re-sent every past
attachment as a native prompt content part regardless of what the
invoked model supports. On models whose provider does not implement
document input (e.g. Qwen served through vLLM), a follow-up turn in
the same conversation failed with:

  400 Unsupported chat content part type: 'file'

Gate each converted history file on the model schema's declared
features via AIModelEntity.supports_prompt_content_type() and degrade
unsupported parts to a text note so earlier turns keep contributing
context without breaking the request. Unresolvable model schemas fall
back to the previous send-anywhere behavior.

Fixes langgenius#41059
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

1 participant