Closed LotusPhilip closed 3 days 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
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?
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])
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
Is there any example of