Open
Conversation
Collaborator
Author
Screen.Recording.2026-02-24.at.14.47.55.mp4The video shows that the token is updated with each tool call (request). |
Collaborator
Author
|
pending camel-ai/camel#3872 |
Wendong-Fan
reviewed
Mar 4, 2026
Wendong-Fan
reviewed
Mar 4, 2026
Contributor
There was a problem hiding this comment.
seems in streaming mode _stream_chunks / _astream_chunks call _send_agent_deactivate(accumulated_content, total_tokens) in their finally block with the full step token count, while request_usage events have already reported those same tokens, the frontend adds both, resulting in inflated token counts?
added pr #1439
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes #https://github.com/eigent-ai/eigent_server/issues/46
Description
Summary
This PR adapts Eigent to CAMEL request-level usage reporting for non-stream
mode by introducing a dedicated SSE event
request_usage, enabling real-timetoken accumulation during a step loop.
Background
Previously, Eigent consumed token usage mainly via
deactivate_agent(step-level). This is too coarse for long multi-request loops inside a single step
and can delay downstream billing/accounting actions.
What Changed
Action.request_usageActionRequestUsageDataListenChatAgent:ChatAgentsupportson_request_usagerequest_usageper model request with:tokens(request total tokens)request_indexresponse_idstep_total_tokenschat_servicenow emitsrequest_usageAgentStep.REQUEST_USAGEchatStoreconsumesrequest_usageand callsaddTokens(...)immediately
deactivate_agent.tokensis set to0request_usage+deactivate_agent)request_usageincrements tokens in real timedeactivate_agent(tokens=0)does not over-countCompatibility
on_request_usage, Eigent falls back toprevious step-level behavior automatically.
Validation
python3 -m py_compile backend/app/agent/listen_chat_agent.py backend/app/ service/task.py backend/app/service/chat_service.pynpm run test -- test/unit/store/chatStore.test.tsScope
Testing Evidence (REQUIRED)
What is the purpose of this pull request?
Contribution Guidelines Acknowledgement