[Feature Request] Tracking token usage for each tool call in a single step of `ChatAgent`
Motivation
In a single step of ChatAgent, there could be multiple tool calls. here can be multiple tool calls. Different tool calls consume different amounts of tokens: some are more expensive, while others are cheaper. For example, the search agent of Eigent may use both the Google Search API (which typically costs fewer tokens) and browser tools (which usually cost more) to complete a task.
Having a tool-level token tracking mechanism can help us better understand the agent’s working process and the cost of each tool call. This can also serve as a potential reward function for future reinforcement learning research, enabling the agent to optimize its workflow for greater cost efficiency.
The expectation of this sub-issue
Currently ChatAgent already tracks the tool-call trajectory and token usage for each step in the info field of ChatAgentResponse. We now hope to have a finer-grained tracking mechanism that records the token usage of each individual tool call.
Hi @Wendong-Fan @boerz-coding , I've created a PR for this issue to ramp up my current works: https://github.com/camel-ai/camel/pull/3327
In this update, each ToolCallingRecord now stores a token_usage dictionary containing {prompt_tokens, completion_tokens, total_tokens}, representing the input, output and total token usage of this tool calling. It stores in tool_call_records variable when executing step(), and finally integrated into info['tool_calls'] field of ChatAgentResponse.
Please take a look when you have a moment. This is an initial version, and I’d be happy to revise or improve it based on your feedback and suggestions.
Thanks!