feat: Agent and thread management #173
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
This pull request introduces improvements to resource management and error handling in the
CommsManager
class and its usage within theconvert_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
: TheCommsManager
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 inCommsManager
: A dedicatedcleanup
method has been introduced to reset theAgentGroupChat
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:
invoke_async
andasync_invoke
methods now includefinally
blocks to call thecleanup
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 withasync 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?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid
Other Information