modelscope / agentscope

Start building LLM-empowered multi-agent applications in an easier way.
https://doc.agentscope.io/
Apache License 2.0
4.81k stars 294 forks source link

Need some more examples or tutorials. #432

Closed LotusPhilip closed 3 days ago

LotusPhilip commented 1 week ago

Is there any example of

  1. one agent sends message to two another agents meanwhile;
  2. two agents respectively send their message to a third agent meanwhile?
DavdGao commented 1 week ago

Thanks for your attention.

@LotusPhilip For conversation with more than two agents, refer to the msghub in our tutorial: https://doc.agentscope.io/en/tutorial/202-pipeline.html#creating-a-msghub

LotusPhilip commented 6 days ago

Can I get a more specific example, that how agents interact with each other?

Especially, like how an agent obtains a message from agent A and another message from agent B, then replays based on the two previous message?

DavdGao commented 6 days ago

Sure, the following is an example for message exchange, where agent Cate receives message from Alice and Bob, and replies based on these messages:

from agentscope.agents import DialogAgent
from agentscope.message import Msg
import agentscope

YOUR_CONFIG_NAME = "xxx"
agentscope.init(
    model_configs={
        "config_name": YOUR_CONFIG_NAME,
        # your config here
    }
)

# Init agents
cate = DialogAgent(
    name="Cate",
    sys_prompt="You're a helpful assistant named Cate",
    model_config_name=YOUR_CONFIG_NAME
)
alice = DialogAgent(
    name="Alice",
    sys_prompt="You're a helpful assistant named Alice",
    model_config_name=YOUR_CONFIG_NAME
)
bob = DialogAgent(
    name="Bob",
    sys_prompt="You're a helpful assistant named Bob",
    model_config_name=YOUR_CONFIG_NAME
)

msg_to_cate = Msg("system",
                  "Calculate the sum of the reported number from Alice and Bob",
                  "system")

# Tell cate his/her task (we don't need his reply)
cate(msg_to_cate)

# Tell alice and bob, and get the reported number
msg_to_ab = Msg("system", "Now report a number in the range of [0, 100]",
                "system")
msg_b = bob(msg_to_ab)
msg_a = alice(msg_to_ab)

# Calculate the sum by cate, and get the result
msg_res = cate([msg_a, msg_b])
DavdGao commented 6 days ago

For more complex cases, you can also use msghub in AgentScope. Refer to tutorial for more details:

https://doc.agentscope.io/en/tutorial/202-pipeline.html#msghub