Skip to content

fix(claude-agent-sdk): keep the assistant model when result model_usage covers the session - #4036

Open
Harsh23Kashyap wants to merge 2 commits into
Arize-ai:mainfrom
Harsh23Kashyap:fix/claude-agent-sdk-set-model-model-name
Open

Harsh23Kashyap wants to merge 2 commits into
Arize-ai:mainfrom
Harsh23Kashyap:fix/claude-agent-sdk-set-model-model-name

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Contributor

description

felixnic pointed out on #3949 that after set_model() mid-session, llm.model_name can still show the first model. i checked it with real AssistantMessage / ResultMessage types and it reproduces.

  • turn 1 runs on sonnet, then set_model("haiku"), turn 2 runs on haiku
  • the result message's model_usage covers the whole session, so it lists both models
  • the instrumentor picked the model with the most output tokens from that list, so turn 2 got sonnet even though the assistant message said haiku

fix:

before and after, same script:

terminal record

tests:

  • 2 new unit tests in test_wrappers_unit.py, the first one fails on main and passes with the fix
  • pytest tests in the package: 54 passed

separate from #3949, which only touches the per-turn token counts.

checklist:

  • Follows OpenInference configuration to hide sensitive info
  • Spans properly inherit from context attributes
  • Properly respects suppress tracing context

@Harsh23Kashyap
Harsh23Kashyap requested a review from a team as a code owner October 12, 2026 15:10
@felixnic

Copy link
Copy Markdown

Legend! Thanks for fixing!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants