← Back to Pull requests

fix(models): move documents out of OpenAI tool messages into a user message #5961

Open
unknown opened this pull request with 293 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 09, 2026 10:11 UTC
Author

HUMAN:

I moved documents the same way images already move, but only PDFs — those are the only documents the API accepts in a user message. I read every changed line and ran the model tests locally on Windows (Python 3.12, openai 3.x, litellm 1.10x): test_openai.py and test_litellm.py are 260 passed, ruff clean. I did not run a live Bedrock call; the bot's repro is the evidence for that path.

---

AGENT:

Why

OpenAIModel.format_request_tool_message keeps a document in the tool message: format_request_message_content renders it as a file part, and the tool message keeps its array form. The Chat Completions tool role accepts text only, so that request is invalid for the tool-message shape, while _split_tool_message_images already moves images into a following user message for exactly this reason.

Summary

  • Extract file parts alongside image_url parts in the tool-message splitter, returning them in one user message and leaving the tool message text-only.

  • Only PDF documents move. PDF is the one document type Chat Completions accepts in a user message; other types stay where they are, because LiteLLM turns a file part inside a tool message into a native tool-result document, and moving one would break that path without making an OpenAI request valid.

  • Renamed the helper to _split_tool_message_media since it now covers both kinds, and the informational text says which kind moved.

  • Added three tests: a unit test on the splitter, a request-format test pinned to a PDF, and a test that a non-PDF document stays in the tool message.
  • Issue Number

    Related to #5848.

    How to Test

    cd strands-py
    uv pip install -e . "pytest>=9.0.0,<10.0.0" "pytest-asyncio>=1.0.0,<1.5.0" "pytest-timeout>=2.0.0,<3.0.0" moto "openai>=1.68.0,<4.0.0" "litellm>=1.75.9,<1.107.0" aws-bedrock-token-generator
    python -m pytest tests/strands/models/test_openai.py tests/strands/models/test_litellm.py -q
    

    260 passed. The new tests fail without the source change: the PDF test sees a file part left in the tool message, and the non-PDF test sees it moved.

    Type

  • Bug fix
  • Notes

    The informational text for an image is the same sentence as before, split across two literals to stay inside the line limit. Non-PDF documents are untouched, so LiteLLMModel → Bedrock keeps working as it does on main.

    Diff: 293 lines (+219 / -74) across 3 files Reviewer: chrikrah Review duration: 6622m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 293 lines diff across 3 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.340
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #5961"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.9% · Safe to merge
    23.9%