Skip to content

Commit

Permalink
hook-list are updated to accept a sender argument (microsoft#1799)
Browse files Browse the repository at this point in the history
* hook-list are updated to accept a sender argument

* Update the hook function Signature & add assertions for Sender
  • Loading branch information
RohitRathore1 authored Feb 28, 2024
1 parent f501e8f commit c22b335
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def _process_message_before_send(
"""Process the message before sending it to the recipient."""
hook_list = self.hook_lists["process_message_before_send"]
for hook in hook_list:
message = hook(message, recipient, silent)
message = hook(sender=self, message=message, recipient=recipient, silent=silent)
return message

def send(
Expand Down
6 changes: 4 additions & 2 deletions test/agentchat/test_conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,11 @@ def test_max_turn():
def test_process_before_send():
print_mock = unittest.mock.MagicMock()

def send_to_frontend(message, recipient, silent):
# Updated to include sender parameter
def send_to_frontend(sender, message, recipient, silent):
assert sender.name == "dummy_agent_1", "Sender is not the expected agent"
if not silent:
print(f"Message sent to {recipient.name}: {message}")
print(f"Message sent from {sender.name} to {recipient.name}: {message}")
print_mock(message=message)
return message

Expand Down

0 comments on commit c22b335

Please sign in to comment.