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

New initiate_chats Interface for Managing Dependent Chats in ConversableAgent #1402

Merged
merged 60 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7f61936
add initiate_chats implementation and example
qingyun-wu Jan 24, 2024
9ff1e7c
update notebook
qingyun-wu Jan 25, 2024
666d0e0
improve takeaway method
qingyun-wu Jan 25, 2024
343f3c7
improve print
qingyun-wu Jan 25, 2024
65e8eae
improve print
qingyun-wu Jan 25, 2024
a459f72
improve print
qingyun-wu Jan 25, 2024
731c2b0
improve print
qingyun-wu Jan 25, 2024
a98f120
add tests
qingyun-wu Jan 25, 2024
b65fee4
minor changes
qingyun-wu Jan 25, 2024
70f11c0
format
qingyun-wu Jan 25, 2024
9328496
correct typo
qingyun-wu Jan 25, 2024
4e140bb
make prompt a parameter
qingyun-wu Jan 26, 2024
0213ceb
add takeaway method
qingyun-wu Jan 26, 2024
5b5ae34
groupchat messages
qingyun-wu Jan 27, 2024
a509ef1
add SoM example
qingyun-wu Jan 27, 2024
67df1e7
fix typo
qingyun-wu Jan 27, 2024
8b30631
fix SoM typo
qingyun-wu Jan 27, 2024
a8cbdbb
Merge branch 'multi-task-chat' of github.com:microsoft/autogen into m…
qingyun-wu Jan 27, 2024
59cb368
simplify chat function
qingyun-wu Jan 27, 2024
319dde8
Merge branch 'main' into multi-task-chat
sonichi Jan 27, 2024
a3d02d3
add carryover
qingyun-wu Jan 28, 2024
e5ccfb7
update notebook
qingyun-wu Jan 28, 2024
812949b
doc
qingyun-wu Jan 28, 2024
f6110f6
remove async for now
qingyun-wu Jan 28, 2024
cb42cdb
remove condition on reply
qingyun-wu Jan 28, 2024
37c1afc
Merge branch 'main' into multi-task-chat
qingyun-wu Jan 28, 2024
72fff52
correct argument name
qingyun-wu Jan 28, 2024
60b1f52
add notebook in website
qingyun-wu Jan 28, 2024
7dfa78c
format
qingyun-wu Jan 28, 2024
5a62aef
make get_chat_takeaway private
qingyun-wu Jan 29, 2024
00b8ffa
rename takeaway method and add example
qingyun-wu Feb 1, 2024
9132996
Merge remote-tracking branch 'origin/main' into multi-task-chat
qingyun-wu Feb 1, 2024
3047b14
removing SoM example for now
qingyun-wu Feb 1, 2024
a133c54
carryover test
qingyun-wu Feb 1, 2024
5e4f5d3
add test
qingyun-wu Feb 1, 2024
0e5bbca
takeaway_method
qingyun-wu Feb 1, 2024
c6635cc
update tests
qingyun-wu Feb 1, 2024
5c9b428
update notebook
qingyun-wu Feb 1, 2024
a78c4ad
Merge branch 'main' into multi-task-chat
qingyun-wu Feb 1, 2024
ff280ae
chats_queue
qingyun-wu Feb 1, 2024
579861d
Merge remote-tracking branch 'origin/main' into multi-task-chat
qingyun-wu Feb 4, 2024
c43e403
add get_chat_takeaway
qingyun-wu Feb 4, 2024
a58aa70
delete
qingyun-wu Feb 4, 2024
2a92049
add test
qingyun-wu Feb 4, 2024
d969c42
Update autogen/agentchat/conversable_agent.py
qingyun-wu Feb 5, 2024
063ce84
docstr
qingyun-wu Feb 5, 2024
4ca3f25
Merge branch 'multi-task-chat' of github.com:microsoft/autogen into m…
qingyun-wu Feb 5, 2024
ccb39db
wording etc
qingyun-wu Feb 5, 2024
e7d4310
add chat res
qingyun-wu Feb 5, 2024
6e4516b
revise title
qingyun-wu Feb 5, 2024
ff9c61d
update agent_utils
qingyun-wu Feb 5, 2024
4c188f3
unify the async method
sonichi Feb 5, 2024
55d7469
Merge branch 'main' into multi-task-chat
sonichi Feb 5, 2024
a7da422
add todo about overriding
sonichi Feb 5, 2024
6ed5c55
attribute check
sonichi Feb 5, 2024
0fa55dd
ChatResult type
qingyun-wu Feb 5, 2024
9830d5f
revise test
qingyun-wu Feb 5, 2024
b80d504
takeaway to summary
qingyun-wu Feb 6, 2024
b9a8408
cache and documentation
qingyun-wu Feb 6, 2024
959052d
Use cache in summarize chat; polish tests
ekzhu Feb 6, 2024
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
5 changes: 2 additions & 3 deletions autogen/agent_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import List, Dict, Tuple
from autogen import Agent


def gather_usage_summary(agents: List[Agent]) -> Tuple[Dict[str, any], Dict[str, any]]:
def gather_usage_summary(agents: List) -> Tuple[Dict[str, any], Dict[str, any]]:
"""Gather usage summary from all agents.

Args:
Expand Down Expand Up @@ -44,7 +43,7 @@ def aggregate_summary(usage_summary: Dict[str, any], agent_summary: Dict[str, an
actual_usage_summary = {"total_cost": 0}

for agent in agents:
if agent.client:
if getattr(agent, "client", None):
aggregate_summary(total_usage_summary, agent.client.total_usage_summary)
aggregate_summary(actual_usage_summary, agent.client.actual_usage_summary)

Expand Down
15 changes: 15 additions & 0 deletions autogen/agentchat/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import logging
qingyun-wu marked this conversation as resolved.
Show resolved Hide resolved
from typing import Dict, List
from dataclasses import dataclass

logger = logging.getLogger(__name__)


@dataclass
ekzhu marked this conversation as resolved.
Show resolved Hide resolved
class ChatResult:
"""(Experimental) The result of a chat. Almost certain to be changed."""

chat_history: List[Dict[str, any]] = None
summary: str = None
cost: dict = None # (dict, dict) - (total_cost, actual_cost_with_cache)
human_input: List[str] = None
272 changes: 250 additions & 22 deletions autogen/agentchat/conversable_agent.py

Large diffs are not rendered by default.

556 changes: 217 additions & 339 deletions notebook/agentchat_auto_feedback_from_code_execution.ipynb

Large diffs are not rendered by default.

2,011 changes: 2,011 additions & 0 deletions notebook/agentchat_multi_task_chats.ipynb
qingyun-wu marked this conversation as resolved.
Show resolved Hide resolved
qingyun-wu marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

209 changes: 209 additions & 0 deletions test/agentchat/test_chats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
from autogen import AssistantAgent, UserProxyAgent
from autogen import GroupChat, GroupChatManager
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
import pytest
from conftest import skip_openai
import autogen

try:
import openai
except ImportError:
skip = True
else:
skip = False or skip_openai


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
def test_chats_group():
config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST,
file_location=KEY_LOC,
)
financial_tasks = [
"""What are the full names of NVDA and TESLA.""",
"""Pros and cons of the companies I'm interested in. Keep it short.""",
]

writing_tasks = ["""Develop a short but engaging blog post using any information provided."""]

user_proxy = UserProxyAgent(
name="User_proxy",
system_message="A human admin.",
human_input_mode="NEVER",
code_execution_config={
"last_n_messages": 1,
"work_dir": "groupchat",
"use_docker": False,
},
is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),
)

financial_assistant = AssistantAgent(
name="Financial_assistant",
llm_config={"config_list": config_list},
)

writer = AssistantAgent(
name="Writer",
llm_config={"config_list": config_list},
system_message="""
You are a professional writer, known for
your insightful and engaging articles.
You transform complex concepts into compelling narratives.
Reply "TERMINATE" in the end when everything is done.
""",
)

critic = AssistantAgent(
name="Critic",
system_message="""Critic. Double check plan, claims, code from other agents and provide feedback. Check whether the plan includes adding verifiable info such as source URL.
Reply "TERMINATE" in the end when everything is done.
""",
llm_config={"config_list": config_list},
)

groupchat_1 = GroupChat(agents=[user_proxy, financial_assistant, critic], messages=[], max_round=50)

groupchat_2 = GroupChat(agents=[user_proxy, writer, critic], messages=[], max_round=50)

manager_1 = GroupChatManager(
groupchat=groupchat_1,
name="Research_manager",
llm_config={"config_list": config_list},
code_execution_config={
"last_n_messages": 1,
"work_dir": "groupchat",
"use_docker": False,
},
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
)
manager_2 = GroupChatManager(
groupchat=groupchat_2,
name="Writing_manager",
llm_config={"config_list": config_list},
code_execution_config={
"last_n_messages": 1,
"work_dir": "groupchat",
"use_docker": False,
},
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
)

user = UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),
code_execution_config={
"last_n_messages": 1,
"work_dir": "tasks",
"use_docker": False,
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
)
chat_res = user.initiate_chats(
[
{
"recipient": financial_assistant,
"message": financial_tasks[0],
"summary_method": "last_msg",
},
{
"recipient": manager_1,
"message": financial_tasks[1],
"summary_method": "reflection_with_llm",
},
{"recipient": manager_2, "message": writing_tasks[0]},
]
)

chat_w_manager = chat_res[manager_2]
print(chat_w_manager.chat_history, chat_w_manager.summary, chat_w_manager.cost)

manager_2_res = user.get_chat_results(manager_2)
all_res = user.get_chat_results()
print(manager_2_res.summary, manager_2_res.cost)
print(all_res[financial_assistant].human_input)
print(all_res[manager_1].summary)


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
def test_chats():
config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST,
file_location=KEY_LOC,
)

financial_tasks = [
"""What are the full names of NVDA and TESLA.""",
"""Pros and cons of the companies I'm interested in. Keep it short.""",
]

writing_tasks = ["""Develop a short but engaging blog post using any information provided."""]

financial_assistant_1 = AssistantAgent(
name="Financial_assistant_1",
llm_config={"config_list": config_list},
)
financial_assistant_2 = AssistantAgent(
name="Financial_assistant_2",
llm_config={"config_list": config_list},
)
writer = AssistantAgent(
name="Writer",
llm_config={"config_list": config_list},
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
system_message="""
You are a professional writer, known for
your insightful and engaging articles.
You transform complex concepts into compelling narratives.
Reply "TERMINATE" in the end when everything is done.
""",
)

user = UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
code_execution_config={
"last_n_messages": 1,
"work_dir": "tasks",
"use_docker": False,
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
)

chat_res = user.initiate_chats(
[
{
"recipient": financial_assistant_1,
"message": financial_tasks[0],
"clear_history": True,
"silent": False,
"summary_method": "last_msg",
},
{
"recipient": financial_assistant_2,
"message": financial_tasks[1],
"summary_method": "reflection_with_llm",
},
{
"recipient": writer,
"message": writing_tasks[0],
"carryover": "I want to include a figure or a table of data in the blogpost.",
"summary_method": "last_msg",
},
]
)

chat_w_writer = chat_res[writer]
print(chat_w_writer.chat_history, chat_w_writer.summary, chat_w_writer.cost)

writer_res = user.get_chat_results(writer)
all_res = user.get_chat_results()
print(writer_res.summary, writer_res.cost)
print(all_res[financial_assistant_1].human_input)
print(all_res[financial_assistant_1].summary)
# print(blogpost.summary, insights_and_blogpost)


if __name__ == "__main__":
# test_chats()
test_chats_group()
3 changes: 2 additions & 1 deletion website/docs/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Links to notebook examples:
- Automated Task Solving with agents divided into 2 groups - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_hierarchy_flow_using_select_speaker.ipynb)
- Automated Task Solving with transition paths specified in a graph - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_graph_modelling_language_using_select_speaker.ipynb)
- Running a group chat as an inner-monolgue via the SocietyOfMindAgent - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_society_of_mind.ipynb)

1. **Sequential Multi-Agent Chats**
- Automated Sequential Multi-Agent Chats - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_multi_task_chats.ipynb)
1. **Applications**

- Automated Chess Game Playing & Chitchatting by GPT-4 Agents - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_chess.ipynb)
Expand Down
Loading