Skip to content
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

Makes select_speaker more robust by checking for mentions anywhere. #669

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
import sys
from typing import Dict, List, Optional, Union
import re
from .agent import Agent
from .conversable_agent import ConversableAgent
import logging
Expand Down Expand Up @@ -100,6 +101,20 @@ def select_speaker(self, last_speaker: Agent, selector: ConversableAgent):
if not final:
# i = self._random.randint(0, len(self._agent_names) - 1) # randomly pick an id
return self.next_agent(last_speaker, agents)

# Find mentions of any agents
mentions = dict()
for agent in self.agents:
regex = r"\b" + re.escape(agent.name) + r"\b" # Finds agent mentions, taking word boundaries into account
count = len(re.findall(regex, name))
if count > 0:
mentions[agent.name] = count
afourney marked this conversation as resolved.
Show resolved Hide resolved

# If exactly one agent is found, use it. Otherwise, leave the OAI response unmodified
if len(mentions) == 1:
name = next(iter(mentions))
afourney marked this conversation as resolved.
Show resolved Hide resolved

# Return the result
try:
return self.agent_by_name(name)
except ValueError:
Expand Down
Loading