Skip to content

feat: Agent and thread management #173

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

Merged
merged 5 commits into from
Jul 18, 2025
Merged

Conversation

Shreyas-Microsoft
Copy link
Collaborator

Purpose

This pull request introduces improvements to resource management and error handling in the CommsManager class and its usage within the convert_script function. The changes ensure proper cleanup of resources, even in cases of failure, by leveraging Python's asynchronous context management and adding robust cleanup mechanisms.

Enhancements to resource management:

  • Transition to asynchronous context management in convert_script: The CommsManager is now used as an asynchronous context manager (async with), which automatically handles resource cleanup upon exit. This replaces the previous manual instantiation and ensures cleanup is performed consistently. (src/backend/sql_agents/convert_script.py, src/backend/sql_agents/convert_script.pyL47-R52)

  • Addition of cleanup method in CommsManager: A dedicated cleanup method has been introduced to reset the AgentGroupChat resources, clear conversation state, and delete remote threads. This method is invoked in multiple scenarios, including context manager exit (__aexit__) and during object destruction (__del__). (src/backend/sql_agents/helpers/comms_manager.py, src/backend/sql_agents/helpers/comms_manager.pyR266-R306)

Improvements to error handling:

  • Ensuring cleanup during failures: The invoke_async and async_invoke methods now include finally blocks to call the cleanup method, guaranteeing resource cleanup regardless of whether the operation succeeds or fails. (src/backend/sql_agents/helpers/comms_manager.py, [1] [2]

Codebase consistency:

  • Context manager methods in CommsManager: Added __aenter__ and __aexit__ methods to support usage with async with, aligning with Python's asynchronous context management best practices. (src/backend/sql_agents/helpers/comms_manager.py, src/backend/sql_agents/helpers/comms_manager.pyR266-R306)

  • Destructor for fallback cleanup: Implemented a __del__ method to ensure cleanup is attempted if the object is garbage-collected without explicit cleanup, with safeguards for cases where no event loop is running. (src/backend/sql_agents/helpers/comms_manager.py, src/backend/sql_agents/helpers/comms_manager.pyR266-R306)

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

@Roopan-Microsoft Roopan-Microsoft merged commit 2a9c143 into dev Jul 18, 2025
9 checks passed
@Roopan-Microsoft Roopan-Microsoft deleted the psl-thread-management branch July 18, 2025 12:00
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.

2 participants