2 Commits

Author SHA1 Message Date
Gao Chenkai
3192757d45 fix: handle DeepSeek reasoning budget exhaustion (#1331)
* fix: handle DeepSeek reasoning budget exhaustion

* style: satisfy ruff format, the one thing CI was red on

`ruff format --check` on agent_loop.py, the Responses parser and the test
file that came with them. No behaviour change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 01:43:40 +08:00
Bingxi Zhao (Frank)
faac018152 refactor(llm): centralise provider usage-payload coercion
Token counts arrive as a plain dict, a pydantic model, or a bare object with
attributes, and four readers each guessed the shape for themselves. #919 fixed
one of them (UsageTracker missed the dict case, so every streamed call on the
native adapters recorded zero), which left the other three still guessing.

Move the guess into services/llm/usage_frame.py: usage_mapping() answers "give
me this payload as a mapping", token_counts() returns DeepTutor's canonical
triple and takes the source key names, so the Responses API's
input_/output_tokens dialect stops needing its own hand-rolled copy.

Behaviour change, in the readers' favour: a provider that omits total_tokens
now gets prompt+completion instead of 0. An all-zero frame still reads as
falsy, which is what the streaming loop relies on to mean "no usage report".
2026-08-19 23:52:16 +08:00