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 Optional Async Shutdown Method to BaseChatAgent and BaseGroupChat for Cleanup Operations #3850

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zboyles
Copy link
Contributor

@zboyles zboyles commented Oct 20, 2024

Why are these changes needed?

These changes introduce an optional shutdown method to the BaseChatAgent class and ensure it is called on all participants in the BaseGroupChat class. This allows for proper cleanup of resources and necessary teardown operations for custom agents.

  • Simplifies Agent Cleanup: Developers no longer need to manually manage context managers or explicit cleanup code.
  • Encourages Agent Lifecycle Management: Agents and teams can be defined upfront, facilitating flexible configurations.
  • Maintains Backward Compatibility: Existing agents and codebases continue to work without modification.

What changes are included?

  • BaseChatAgent: Added an async shutdown method with a default implementation (pass).
  • BaseGroupChat: Updated the run method to call shutdown on all participants after the runtime stops.

Hypothetical Usage

For example, an agent like CodeExecutorAgent could handle both initialization and cleanup internally with minimal effort. This pattern simplifies teardown tasks such as closing open connections or stopping subprocesses.

What needs to be done before merging?

  • Identify custom agents that could benefit from the new shutdown method.
  • Add implementation-specific shutdown code in those custom agents, where applicable.
  • Write tests to ensure the shutdown method is invoked and behaves as expected (e.g., proper resource cleanup).

Notes

  • This is a draft PR to gather feedback on the approach and implementation. Feedback from maintainers or contributors is especially welcome.

@ekzhu
Copy link
Collaborator

ekzhu commented Oct 22, 2024

Thanks @zboyles! The design needs some more thinking. We have an issue here for a similar feature: #3860.

Would you like to contribute to the discussion under that issue with your proposal? We can revisit this PR when we have a collective plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants