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

Refactor AssistantAgent on_message_stream #5642

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lspinheiro
Copy link
Collaborator

@lspinheiro lspinheiro commented Feb 21, 2025

Why are these changes needed?

I'm unsure if everyone will agree, but I started to look into adding new logic and found that refactoring into smaller functions would make it more maintainable.

There is no change in functionality, only a breakdown into smaller methods to make it more modular and improve readability. There is a lot of logic in the method and this refactor breaks it down into context management, llm call and result processing.

Related issue number

Checks

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 7 lines in your changes missing coverage. Please review.

Project coverage is 75.64%. Comparing base (a226966) to head (108397c).

Files with missing lines Patch % Lines
...t/src/autogen_agentchat/agents/_assistant_agent.py 94.11% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5642      +/-   ##
==========================================
+ Coverage   75.56%   75.64%   +0.08%     
==========================================
  Files         171      171              
  Lines       10483    10542      +59     
==========================================
+ Hits         7921     7975      +54     
- Misses       2562     2567       +5     
Flag Coverage Δ
unittests 75.64% <94.11%> (+0.08%) ⬆️

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.

@jackgerrits
Copy link
Member

I think a refactor is good, but I think it can hurt understandability of the function. Is it possible to make any of these inner functions static? That way we know exactly what is going in and out of each of them

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 21, 2025

Yeah, there are a lot of things going on in the on_messages_stream now. I think static methods are useful for better visibility.

@lspinheiro
Copy link
Collaborator Author

I updated it to make the inner methods either static or class to make it clearer which state goes into each call. It makes it more verbose because there is a lot of class state reuse (not necessarily being changed) such as the model client and tools being passed internally.

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.

4 participants