Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Token Usage as part of the Final Answer #559

Open
mattmarcin opened this issue Feb 8, 2025 · 0 comments
Open

Getting Token Usage as part of the Final Answer #559

mattmarcin opened this issue Feb 8, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@mattmarcin
Copy link

mattmarcin commented Feb 8, 2025

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
For cost/usage tracking it would be nice to be able to get the used input and output token count or even actual API usage expense.

Is this not possible with the current options.
It appears it may be possible to hook into the Monitor to get the token usage data or wrap it into the agent's run.

Describe alternatives you've considered
I looked into modifying the MultStepAgent.run function to bring in the token counts from the monitor.

if stream:
    # The steps are returned as they are executed through a generator to iterate on.
    return self._run(task=self.task, images=images)
# Outputs are returned only at the end as a string. We only look at the last step
final_step = deque(self._run(task=self.task, images=images), maxlen=1)[0]

if include_tokens and final_step.final_answer is not None:
    token_counts = self.monitor.get_total_token_counts()
    return {
        "answer": final_step.final_answer,
        "token_counts": token_counts
    }
return final_step

Additional context
Being able to get usage/cost data from API calls would help from a business perspective to track cost of execution and aid in iterating on agents to lower costs.

@mattmarcin mattmarcin added the enhancement New feature or request label Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant