Skip to content

Refactor hook registration and processing methods #2853

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
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def __init__(

# Registered hooks are kept in lists, indexed by hookable method, to be called in their order of registration.
# New hookable methods should be added to this list as required to support new agent capabilities.
self.hook_lists = {
self.hook_lists: Dict[str, List[Callable]] = {
"process_last_received_message": [],
"process_all_messages_before_reply": [],
"process_message_before_send": [],
Expand Down Expand Up @@ -2724,7 +2724,7 @@ def process_all_messages_before_reply(self, messages: List[Dict]) -> List[Dict]:
processed_messages = hook(processed_messages)
return processed_messages

def process_last_received_message(self, messages):
def process_last_received_message(self, messages: List[Dict]) -> List[Dict]:
"""
Calls any registered capability hooks to use and potentially modify the text of the last message,
as long as the last message is not a function call or exit command.
Expand Down Expand Up @@ -2758,6 +2758,7 @@ def process_last_received_message(self, messages):
processed_user_content = user_content
for hook in hook_list:
processed_user_content = hook(processed_user_content)

if processed_user_content == user_content:
return messages # No hooks actually modified the user's message.

Expand Down
Loading