Skip to content

To retrieve the current token consumption during the reasoning process, assign a value to ChatUsage in ReasoningChunkEvent.accumulated#935

Open
MrYang-Jia wants to merge 4 commits intoagentscope-ai:mainfrom
MrYang-Jia:feature/chatusage-v1.0.10
Open

To retrieve the current token consumption during the reasoning process, assign a value to ChatUsage in ReasoningChunkEvent.accumulated#935
MrYang-Jia wants to merge 4 commits intoagentscope-ai:mainfrom
MrYang-Jia:feature/chatusage-v1.0.10

Conversation

@MrYang-Jia
Copy link

@MrYang-Jia MrYang-Jia commented Mar 12, 2026

To retrieve the current token consumption during the reasoning process, assign a value to ChatUsage in ReasoningChunkEvent.accumulated:

  1. Add the getChatUsage() method to ReasoningContext.
  2. In ReActAgent.notifyReasoningChunk, assign ReasoningContext.getChatUsage() to accumulated.metadata._chat_usage. This allows real-time retrieval of consumed tokens during the reasoning process, facilitating interrupted billing recovery or token replenishment for missing billing records.

chinese:
为了在思考过程中获取到当前的tokens损耗,所以在 ReasoningChunkEvent.accumulated 里为 ChatUsage 赋值 1、ReasoningContext 增加 getChatUsage() 方法
2、ReActAgent.notifyReasoningChunk 将 ReasoningContext.getChatUsage() 赋予 accumulated.metadata._chat_usage ,这样子思考过程就可以实时获取到损耗的tokens,方便中断计费或丢失计费补充tokens

AgentScope-Java Version

AgentScope-Java 1.0.11-SNAPSHOT

Description

To retrieve the current token consumption during the reasoning process, assign a value to ChatUsage in ReasoningChunkEvent.accumulated

Checklist

Please check the following items before code is ready to be reviewed.

  • [ ✔] Code has been formatted with mvn spotless:apply
  • [ ✔] All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • [ ✔] Code is ready for review

To retrieve the current token consumption during the reasoning process, assign a value to `ChatUsage` in `ReasoningChunkEvent.accumulated`:
1. Add the `getChatUsage()` method to `ReasoningContext`.
2. In `ReActAgent.notifyReasoningChunk`, assign `ReasoningContext.getChatUsage()` to `accumulated.metadata._chat_usage`. This allows real-time retrieval of consumed tokens during the reasoning process, facilitating interrupted billing recovery or token replenishment for missing billing records.

chinese:
为了在思考过程中获取到当前的tokens损耗,所以在 ReasoningChunkEvent.accumulated 里为 ChatUsage 赋值
1、ReasoningContext 增加 getChatUsage() 方法
2、ReActAgent.notifyReasoningChunk 将 ReasoningContext.getChatUsage() 赋予 accumulated.metadata._chat_usage ,这样子思考过程就可以实时获取到损耗的tokens,方便中断计费或丢失计费补充tokens
@MrYang-Jia MrYang-Jia requested a review from a team March 12, 2026 09:57
@cla-assistant
Copy link

cla-assistant bot commented Mar 12, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant
Copy link

cla-assistant bot commented Mar 12, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...scope/core/agent/accumulator/ReasoningContext.java 85.71% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Add test cases for ReasoningContext.getChatUsage() to cover the partial uncovered line, fix patch coverage from 85.71% to 100%
@MrYang-Jia
Copy link
Author

我已补签了CLA协议,请继续

…eve full coverage testing for accumulated message metadata chat usage

test: 新增 testChatUsageInAccumulatedMessageMetadata 测试案例,进行覆盖测试
…Test.testFixedDelayReschedulesAndRunsMultipleTimes to prevent test failures due to slower execution speed in CI environment

test: Modify the timeout configuration in QuartzFixedDelayIntegrationTest.testFixedDelayReschedulesAndRunsMultipleTimes to prevent test failures due to slower execution speed in CI environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants