Skip to content

Python: fix(bedrock): report the requested model on non-streaming responses - #9399

Open
Somay kousis (Somay-kousis) wants to merge 2 commits into
microsoft:mainfrom
Somay-kousis:fix/bedrock-response-model
Open

Somay kousis (Somay-kousis) wants to merge 2 commits into
microsoft:mainfrom
Somay-kousis:fix/bedrock-response-model

Conversation

@Somay-kousis

Copy link
Copy Markdown
Contributor

Motivation & Context

BedrockChatClient sends a per-call options["model"] to Converse, but the non-streaming ChatResponse.model is the client's default model, or None if the client has no default. Converse does not return a modelId, so _process_converse_response always falls back to self.model. Telemetry reads gen_ai.response.model from that value, so traces name the wrong model too. Streaming already reports the request's model.

Description & Review Guide

  • What are the major changes? The non-streaming path passes request["modelId"] into _process_converse_response as a new keyword-only model argument, and uses it before self.model. This matches what the streaming path already does with request["modelId"]. Added a test with a stub that returns the real Converse response shape (no modelId), for a client with and without a default model.
  • What is the impact of these changes? response.model on non-streaming Bedrock responses now names the model the request went to. No public API change. Existing callers of _process_converse_response(response) and (response, options) keep working.
  • What do you want reviewers to focus on? Whether to keep the response.get("modelId") / output.get("modelId") lookups. Converse never returns them, but I left them in to keep the change small.

Related Issue

Fixes #9398

I think this is an obvious fix: the streaming path already reports request["modelId"], and #9139 did the same for Gemini. Happy to wait for ready-for-implementation if you'd rather triage #9398 first.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: AI tools helped find the bug and write the code, the test and this description. I reviewed all of it and ran the repro, the bedrock tests, and the lint and typing checks myself.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI 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.

🟢 Approval recommended

The focused, backward-compatible fix covers both reported failure cases with no unresolved findings.

0 open findings

What changed in this PR

Fixes #9398 by making non-streaming Bedrock responses report the requested model, correcting model attribution in telemetry.

Changes:

  • Passes the resolved request model into response processing while preserving existing callers.
  • Adds regression coverage for per-call overrides with and without a client default model.
File Description
python/​packages/​bedrock/​tests/​test_bedrock_client.py Tests model reporting using a realistic Converse response.
python/​packages/​bedrock/​agent_framework_bedrock/​_chat_client.py Uses the requested model before falling back to the client default.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@Somay-kousis

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Somay-kousis

Somay kousis (Somay-kousis) commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Eduard van Valkenburg (@eavanvalkenburg) The red Python Tests run is one failure outside this change: packages/foundry_hosting/tests/test_responses.py::TestAgentSessionPersistence::test_cancellation_signal_preempts_stuck_agent_call hit its 1 s wait_for timeout on windows-latest / 3.14. The other failed jobs were cancelled after it, and 3.10 and 3.12 on Windows passed in full. It passes locally on this branch. This PR only touches the bedrock package.

Could you re-run the failed jobs?

This branch was successfully deployed

1 active deployment
github-app-auth — 1610dff9 Deployed Oct 14, 2026 by Somay-kousis via add_label #25381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: BedrockChatClient reports the client's default model on non-streaming responses, not the model it sent the request to

2 participants