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

Add usage summary for agents #1269

Merged
merged 9 commits into from
Jan 17, 2024
Merged

Add usage summary for agents #1269

merged 9 commits into from
Jan 17, 2024

Conversation

yiranwu0
Copy link
Collaborator

@yiranwu0 yiranwu0 commented Jan 15, 2024

Why are these changes needed?

  • Agent.print_usage_summary() will print the cost summary for the agent.
  • Agent.get_actual_usage() and Agent.get_total_usage() will return the usage summary in a dict. When an agent doesn't use LLM, they will return None.
  • Agent.reset() will reset the usage summary.
  • autogen.agent_utils.gather_usage_summary will gather the usage summary for a list of agents.

Related issue number

Closes #1070

Checks

@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (563b1bb) 32.08% compared to head (5c141ca) 66.57%.

Files Patch % Lines
autogen/agentchat/conversable_agent.py 60.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1269       +/-   ##
===========================================
+ Coverage   32.08%   66.57%   +34.48%     
===========================================
  Files          32       33        +1     
  Lines        4394     4431       +37     
  Branches     1025     1090       +65     
===========================================
+ Hits         1410     2950     +1540     
+ Misses       2867     1178     -1689     
- Partials      117      303      +186     
Flag Coverage Δ
unittests 66.50% <83.78%> (+34.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yiranwu0 yiranwu0 requested a review from ekzhu January 15, 2024 20:36
@afourney
Copy link
Member

Wait , how does this work for agents like GroupChatManager or agents that are enabled as Teachable? These agents make additional LLM calls outside the usual flow.

@sonichi
Copy link
Contributor

sonichi commented Jan 16, 2024

I'm fixing the test failure in #1284

@yiranwu0
Copy link
Collaborator Author

Wait , how does this work for agents like GroupChatManager or agents that are enabled as Teachable? These agents make additional LLM calls outside the usual flow.

Thanks for the comment!
GroupChatManager inherits Conversable_agent, so the print_usage_summary and gather_usage_summary works for it.
But you are right for agents that doesn't follow a usual flow. If there are additional flow defined inside an agent, the user need to take them out explicitly to pass to gather_usage_summary. This still doesn't work if there are additional client defined. For example, Compressible_Agent has a self.client and a self.compress_client, where this method doesn't count for self.compress_client.

Based on these observations, I am considering the following changes for this PR:

  • remove the Agent.print_usage_summary(), Agent.get_actual_usage() and Agent.get_total_usage(), as they may not reflect real usage by the agent.
  • only add a gather_usage_summary_from_clients utility function. We explicitly ask users to collect all the defined OpenAIWrapper instance from agents

In the next step, maybe we can provide an abstract class method in conversable_agent for users to register additional usage. (and for our existing Contrib Agents), then we can add back Agent.print_usage_summary(), Agent.get_actual_usage() and Agent.get_total_usage(), and usage collection for agents.

@sonichi
Copy link
Contributor

sonichi commented Jan 16, 2024

@kevin666aa we can also merge this PR and make the proposed change in the next PR (create an issue first).

@sonichi sonichi added this pull request to the merge queue Jan 17, 2024
Merged via the queue into main with commit acf81ac Jan 17, 2024
87 checks passed
@sonichi sonichi deleted the costagent branch January 17, 2024 02:02
joshkyh pushed a commit that referenced this pull request Jan 17, 2024
* update

* update

* Update notebook/oai_client_cost.ipynb

Co-authored-by: Chi Wang <wang.chi@microsoft.com>

* update doc and test

---------

Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
* update

* update

* Update notebook/oai_client_cost.ipynb

Co-authored-by: Chi Wang <wang.chi@microsoft.com>

* update doc and test

---------

Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
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.

Cost calculation for the whole chat session
6 participants