agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Feature]: implement a GroupChatPipeline that agents can freely talk rather than speak one by one sequencely

Open Morriaty-The-Murderer opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I'm trying to implement a GroupChatPipeline that agents can freely talk rather than speak one by one sequencely

SisterAgent: @MomAgent mommmmm! Tom hit me!!!!
MomAgent: oh my baby, let me check your injuries
MomAgent: em fine. That's not a big problem
SisterAgent: ouch! mom I really feel hurt
MomAgent: TOM YOU BASTARD! COME HERE RIGHT NOW!
BrotherAgent: what happended?

Describe the solution you'd like

# -*- coding:utf-8 -*-
# built-in packages
from typing import Callable, List

# third-party packages
from agentscope.agents import AgentBase


# self-defined packages


class GroupContext(object):
    pass


class BaseAgentAttendStrategy(object):
    # should an agent attend the group chat of current topic?
    pass


class KeywordsAgentAttendStrategy(BaseAgentAttendStrategy):
    # attend current topic if match some keywords
    pass


class BeenMentionedAgentAttendStrategy(BaseAgentAttendStrategy):
    # attend current topic if been mentioned
    pass


class AgentWithAttendStrategy(object):
    agent: AgentBase
    attend_strategies: List[BaseAgentAttendStrategy]


class GroupChatPipeline(object):
    def __init__(self):
        self.context = GroupContext()
        self.members: List[AgentWithAttendStrategy] = []

    def trigger_next_speaker(self, msg) -> AgentBase:
        pass

    def __call__(self,
                 start_agent: AgentBase,
                 start_words: str,
                 max_rounds: int,
                 ending_func: Callable[[GroupContext], bool]
                 ):
        next_speaker = start_agent
        msg = start_words
        n_round = 0
        while n_round < max_rounds and not ending_func(self.context):
            n_round += 1
            msg = next_speaker(msg)
            next_speaker = self.trigger_next_speaker(msg)

Additional context I am wondering:

  1. Is there any existing workaround functions or tools to achieve the GroupChatPipeline?
  2. if Q1 answer is not. Do the team have a plan to make something alike?

Morriaty-The-Murderer avatar May 24 '24 04:05 Morriaty-The-Murderer

@Morriaty-The-Murderer I'm not sure if the example conversation with mentions meets your requirements?

DavdGao avatar May 24 '24 10:05 DavdGao

hi @DavdGao , the example conversation with mentions is not very similar to the new feature I want to request.

The key point is freely chat, there is no fixed order, a group of Agents will decide whether to join the conversation based on the context and their own personality and memory. They can refuse to respond even if they have been metioned.

In short logic:

init_msg = Msg(role="assistant", content="....")

if SomeForcedRules:
    speaker = select_agent_by_forced_rules(agents, SomeForcedRules)
else:
    speaker = None
    max_prob = 0
    for bot in agents:
        possibilities = bot.think(f"how possible should I respond the msg: {init_msg}")
        if possibilities > max_prob:
            max_prob = possibilities
            speaker = bot
            
response = speaker()

Morriaty-The-Murderer avatar May 29 '24 06:05 Morriaty-The-Murderer