Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor hook registration and processing methods (#2853)
* Refactor hook registration and processing methods - Refactored the `hook_lists` dictionary to use type hints for better readability. - Updated the `register_hook` method signature to include type hints for the `hook` parameter. - Added type hints to the `process_last_received_message` method parameters and return value. This commit refactors the code related to hook registration and processing in the `conversable_agent.py` file. The changes improve code readability and maintainability by using type hints and updating method signatures. * Refactor hook_lists initialization and add type hints - Refactored the initialization of `hook_lists` to use a colon instead of an equal sign. - Added type hints for the parameters and return types of `process_last_received_message` method. * Refactor hook registration and processing in conversable_agent.py - Refactored the `hook_lists` dictionary to use a more generic type for the list of hooks. - Updated the signature check for `process_message_before_send`, `process_all_messages_before_reply`, and `process_last_received_message` hooks to ensure they are callable with the correct signatures. - Added error handling to raise a ValueError or TypeError if any hook does not have the expected signature. * Refactor hook processing in conversable_agent.py - Simplify the code by removing unnecessary type checks and error handling. - Consolidate the logic for processing hooks in `_process_message_before_send`, `process_all_messages_before_reply`, and `process_last_received_message` methods. * Refactor register_hook method signature for flexibility The commit changes the signature of the `register_hook` method in `conversable_agent.py`. The second argument, `hook`, is now of type `Callable` instead of `Callable[[List[Dict]], List[Dict]]`. This change allows for more flexibility when registering hooks.
- Loading branch information