Zhuoxi2000 opened a new pull request, #959:
URL: https://github.com/apache/flink-agents/pull/959

   <!--
   * Thank you very much for contributing to Flink Agents.
   * Please add the relevant components in the PR title. E.g., [api], 
[runtime], [java], [python], [hotfix], etc.
   -->
   
   <!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this. 
-->
   Linked issue: #946
   
   ### Purpose of change
   
   <!-- What is the purpose of this change? -->
   
   `extra_args` (`model_name` / `promptTokens` / `completionTokens`) is built 
after every Anthropic API call, but was only attached to the returned 
`ChatMessage` on the `tool_use` branch. Plain-text responses (`stop_reason == 
"end_turn"`, the common case) returned without `extra_args`, so 
`_record_token_metrics` never fired for them: in a ReAct loop only the 
intermediate tool-calling turns were counted and the final answer's tokens were 
always lost. All sibling connectors (openai / azure / ollama / tongyi) already 
pass `extra_args` on every path.
   
   Fix: pass `extra_args=extra_args` in the non-tool_use branch. One line; no 
behavior change on the tool_use path.
   
   ### Tests
   
   <!-- How is this change verified? -->
   
   Two new cases in `test_anthropic_response_parsing.py`: 
`test_plain_text_response_keeps_token_usage` (regression for the fixed branch) 
and `test_tool_use_response_keeps_token_usage` (guard for the already-working 
branch). Both are mock-based with explicit token counts and a `model=` kwarg so 
the metrics path is actually exercised — the pre-existing 
`test_plain_text_response` only asserted `content` and never covered this path.
   
   ### API
   
   <!-- Does this change touches any public APIs? -->
   
   None.
   
   ### Documentation
   
   <!-- Do not remove this section. Check the proper box only. -->
   
   - [ ] `doc-needed` <!-- Your PR changes impact docs -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-included` <!-- Your PR already contains the necessary 
documentation updates -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to