Reputation: 23
I am trying out autogen. I am trying to get multiple agents to communicate together, user_proxy, coder and critic. However, only user_proxy and coder are communicating.
Here is my code:
import autogen
config_list = [
{
'model': 'gpt-4-0613',
'api_key': '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'
}
]
llm_config={
"request_timeout": 600,
"seed": 42,
"config_list": config_list,
"temperature": 0,
}
coder = autogen.AssistantAgent(
name="Coder",
llm_config=llm_config,
)
critic = autogen.AssistantAgent(
name="Critic",
system_message="""Critic. You are a helpful assistant highly skilled in evaluating the quality of a given visualization code by providing a score from 1 to 10
- bugs (bugs): Are there bugs, logic errors, syntax errors or typos? Are there any reasons why the code may fail to compile? How should it be fixed?
- Data transformation (transformation): Is the data transformed appropriately for the visualization type?
- Goal: compliance (compliance): How well the code meets the specified visualization goals?
- Visualization type (type): CONSIDERING BEST PRACTICES, is the visualization type appropriate for the data and intent?
- Data encoding (encoding): Is the data encoded appropriately for the visualization type?
- Aesthetics (aesthetics): Are the aesthetics of the visualization appropriate for the visualization type and the data?
YOUMUST PROVIDE A SCORE for each of the above dimensions.
{bugs: 0, transformation: 0, compliance: 0, type: 0, encoding: 0, aesthetics: 0}
Do not suggest code.
Finally, based on the critique above, suggest a concrete list of actions that the coder should take to improve the code.
""",
llm_config=llm_config,
)
user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="TERMINATE",
max_consecutive_auto_reply=5,
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
code_execution_config={"work_dir": "web"},
llm_config=llm_config,
system_message="""Reply TERMINATE if the task has been solved at full satisfaction.
Otherwise, reply CONTINUE, or the reason why the task is not solved yet."""
)
task = """
build a simple snake game. add a score counter to the top left. every 10 points a special food appars and increases the score by 5.
"""
user_proxy.initiate_chat(
coder,
critic,
message=task
)
I added critic to check certain criteria:
critic = autogen.AssistantAgent(
name="Critic",
system_message="""Critic. You are a helpful assistant highly skilled in evaluating the quality of a given visualization code by providing a score from 1 to 10
- bugs (bugs): Are there bugs, logic errors, syntax errors or typos? Are there any reasons why the code may fail to compile? How should it be fixed?
- Data transformation (transformation): Is the data transformed appropriately for the visualization type?
- Goal: compliance (compliance): How well the code meets the specified visualization goals?
- Visualization type (type): CONSIDERING BEST PRACTICES, is the visualization type appropriate for the data and intent?
- Data encoding (encoding): Is the data encoded appropriately for the visualization type?
- Aesthetics (aesthetics): Are the aesthetics of the visualization appropriate for the visualization type and the data?
YOUMUST PROVIDE A SCORE for each of the above dimensions.
{bugs: 0, transformation: 0, compliance: 0, type: 0, encoding: 0, aesthetics: 0}
Do not suggest code.
Finally, based on the critique above, suggest a concrete list of actions that the coder should take to improve the code.
""",
llm_config=llm_config,
)
To make it "work" I added the critic agent here:
user_proxy.initiate_chat(
coder,
critic,
message=task
)
Upvotes: 1
Views: 2547
Reputation: 114
To enable multiple agents (user_proxy, coder, and critic) to communicate effectively in your autogen setup, you should consider using a GroupChat mechanism. This approach allows for a coordinated interaction among all the agents involved. Here's how you can set it up:
from autogen import GroupChat
# Assuming moderator, bob, peter, and user_proxy are defined as agents
groupchat = GroupChat(
agents=[moderator, bob, peter, user_proxy],
messages=[],
max_round=50
)
For a visual guide on setting up and managing such a group chat interaction, you can refer to the tutorial available at this link: https://www.youtube.com/watch?v=dW-qr_ntOgc. This video will provide you with step-by-step instructions on implementing this solution.
Upvotes: 0
Reputation: 136
YOU can use function calling if you want to have only two agents interacting as in this example: https://github.com/microsoft/autogen/blob/2e519b016a8bfa7a807721a1fc8a93b5d3be6c32/notebook/agentchat_planning.ipynb#L112
Upvotes: 0
Reputation: 35
You are missing the groupchat and groupchatmanager modules which are needed here. Refer https://github.com/microsoft/autogen/blob/main/notebook/agentchat_groupchat.ipynb.
In your case:
groupchat = autogen.GroupChat(agents=[user_proxy, coder, critic], messages=[], max_round=12)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)
user_proxy.initiate_chat(manager, message=task)
Upvotes: 0