To retrieve the current token consumption during the reasoning process, assign a value to ChatUsage in ReasoningChunkEvent.accumulated#935
Conversation
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
|
|
Codecov Report❌ Patch coverage is 📢 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%
|
我已补签了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
| .build(); | ||
| if (context.getChatUsage() != null) { | ||
| accumulated | ||
| .getMetadata() |
There was a problem hiding this comment.
Should we also add CHAT_USAGE to notifySummaryChunk for consistency?
There was a problem hiding this comment.
Yes, thank you very much for your help.
There was a problem hiding this comment.
I have fixed the issue you mentioned. The results from notifySummaryChunk and notifyReasoningChunk are now consistent, so the Hook system can access token usage when processing SummaryChunkEvent in both modules.
…constructing the accumulated message, consistent with notifyReasoningChunk. This allows the Hook system to access statistics such as token usage when processing SummaryChunkEvent. notifySummaryChunk 方法在构建 accumulated 消息时也会添加 CHAT_USAGE 元数据,与 notifyReasoningChunk 保持一致。这样 Hook 系统在处理 SummaryChunkEvent 时也能访问到 token 使用量等统计信息。
To retrieve the current token consumption during the reasoning process, assign a value to
ChatUsageinReasoningChunkEvent.accumulated:getChatUsage()method toReasoningContext.ReActAgent.notifyReasoningChunk, assignReasoningContext.getChatUsage()toaccumulated.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
ChatUsageinReasoningChunkEvent.accumulatedChecklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)