Skip to content

Python: added cache_write_tokens as required field#7049

Open
subhrm wants to merge 1 commit into
microsoft:mainfrom
subhrm:fix-cache-write-tokens-issue
Open

Python: added cache_write_tokens as required field#7049
subhrm wants to merge 1 commit into
microsoft:mainfrom
subhrm:fix-cache-write-tokens-issue

Conversation

@subhrm

@subhrm subhrm commented Jul 10, 2026

Copy link
Copy Markdown

Motivation & Context

openai added cache_write_tokens as a required field on InputTokensDetails. agent-framework-devui 1.0.0b260709 predates this change and constructs InputTokensDetails(cached_tokens=0) at three call sites in _mapper.py, omitting the now-required field. This causes a Pydantic ValidationError on every agent invocation, making the devui completely non-functional with current anthropic versions.

Description & Review Guide

Patched three call sites in agent_framework_devui/_mapper.py to pass cache_write_tokens=0 alongside the existing cached_tokens=0:

  • Line 402 — success path usage accumulator
  • Line 415 — fallback/estimated usage path
  • Line 1872 — error response path

No logic changes — purely adding the missing required field with a zero value to satisfy the updated Pydantic model contract.

Related Issue

Fixes #7048

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 is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • 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 review requested due to automatic review settings July 10, 2026 12:36
@giles17 giles17 added the python Usage: [Issues, PRs], Target: Python label Jul 10, 2026
@github-actions github-actions Bot changed the title added cache_write_tokens as required field Python: added cache_write_tokens as required field Jul 10, 2026

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.

Pull request overview

Fixes a compatibility break in the DevUI response mapper where constructing InputTokensDetails without the now-required cache_write_tokens field causes a Pydantic ValidationError, preventing any agent invocation from completing.

Changes:

  • Add cache_write_tokens=0 to InputTokensDetails(...) construction in the successful usage path.
  • Add cache_write_tokens=0 to InputTokensDetails(...) construction in the fallback/estimated usage path.
  • Add cache_write_tokens=0 to InputTokensDetails(...) construction in the error response path.

Comment thread python/packages/devui/agent_framework_devui/_mapper.py

@moonbox3 moonbox3 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.

Could we add test coverage for the accumulated-usage, fallback, and error-response paths?

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]: Every agent response fails with a Pydantic ValidationError

4 participants