mirror of https://github.com/microsoft/autogen.git
Allow different senders in nested chat (#2028)
* allow sender in nested chat * description * update example list * doc format * meta data * add test
This commit is contained in:
parent
c5536ee92b
commit
8844f86525
|
@ -364,6 +364,8 @@ class ConversableAgent(LLMAgent):
|
|||
chat_to_run = []
|
||||
for i, c in enumerate(chat_queue):
|
||||
current_c = c.copy()
|
||||
if current_c.get("sender") is None:
|
||||
current_c["sender"] = recipient
|
||||
message = current_c.get("message")
|
||||
# If message is not provided in chat_queue, we by default use the last message from the original chat history as the first message in this nested chat (for the first chat in the chat queue).
|
||||
# NOTE: This setting is prone to change.
|
||||
|
@ -377,7 +379,7 @@ class ConversableAgent(LLMAgent):
|
|||
chat_to_run.append(current_c)
|
||||
if not chat_to_run:
|
||||
return True, None
|
||||
res = recipient.initiate_chats(chat_to_run)
|
||||
res = initiate_chats(chat_to_run)
|
||||
return True, res[-1].summary
|
||||
|
||||
def register_nested_chats(
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 100 KiB |
Binary file not shown.
After Width: | Height: | Size: 127 KiB |
|
@ -15,7 +15,7 @@ def test_nested():
|
|||
llm_config = {"config_list": config_list}
|
||||
|
||||
tasks = [
|
||||
"""What's Microsoft's Stock price today?""",
|
||||
"""What's the date today?""",
|
||||
"""Make a pleasant joke about it.""",
|
||||
]
|
||||
|
||||
|
@ -60,6 +60,12 @@ def test_nested():
|
|||
# is_termination_msg=lambda x: x.get("content", "") == "",
|
||||
)
|
||||
|
||||
assistant_2 = autogen.AssistantAgent(
|
||||
name="Assistant",
|
||||
llm_config={"config_list": config_list},
|
||||
# is_termination_msg=lambda x: x.get("content", "") == "",
|
||||
)
|
||||
|
||||
user = autogen.UserProxyAgent(
|
||||
name="User",
|
||||
human_input_mode="NEVER",
|
||||
|
@ -71,6 +77,17 @@ def test_nested():
|
|||
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
|
||||
)
|
||||
|
||||
user_2 = autogen.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.
|
||||
)
|
||||
|
||||
writer = autogen.AssistantAgent(
|
||||
name="Writer",
|
||||
llm_config={"config_list": config_list},
|
||||
|
@ -82,7 +99,7 @@ def test_nested():
|
|||
""",
|
||||
)
|
||||
|
||||
reviewer = autogen.AssistantAgent(
|
||||
autogen.AssistantAgent(
|
||||
name="Reviewer",
|
||||
llm_config={"config_list": config_list},
|
||||
system_message="""
|
||||
|
@ -98,23 +115,19 @@ def test_nested():
|
|||
)
|
||||
|
||||
def writing_message(recipient, messages, sender, config):
|
||||
return f"Polish the content to make an engaging and nicely formatted blog post. \n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}"
|
||||
return f"Make a one-sentence comment. \n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}"
|
||||
|
||||
nested_chat_queue = [
|
||||
{"recipient": manager, "summary_method": "reflection_with_llm"},
|
||||
{"sender": user_2, "recipient": manager, "summary_method": "reflection_with_llm"},
|
||||
{"recipient": writer, "message": writing_message, "summary_method": "last_msg", "max_turns": 1},
|
||||
{
|
||||
"recipient": reviewer,
|
||||
"message": "Review the content provided.",
|
||||
"summary_method": "last_msg",
|
||||
"max_turns": 1,
|
||||
},
|
||||
]
|
||||
assistant.register_nested_chats(
|
||||
nested_chat_queue,
|
||||
trigger=user,
|
||||
)
|
||||
user.initiate_chats([{"recipient": assistant, "message": tasks[0]}, {"recipient": assistant, "message": tasks[1]}])
|
||||
user.initiate_chats(
|
||||
[{"recipient": assistant, "message": tasks[0], "max_turns": 1}, {"recipient": assistant_2, "message": tasks[1]}]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -31,7 +31,8 @@ Links to notebook examples:
|
|||
|
||||
1. **Nested Chats**
|
||||
- Solving Complex Tasks with Nested Chats - [View Notebook](/docs/notebooks/agentchat_nestedchat)
|
||||
- OptiGuide for Solving a Supply Chain Optimization Problem with Nested Chats with a Coding Agent and a Safeguard Agent - [View Notebook](/docs/notebooks/agentchat_nestedchat_optiguide)
|
||||
- Solving Complex Tasks with A Sequence of Nested Chats - [View Notebook](/docs/notebooks/agentchat_nested_sequential_chats)
|
||||
- OptiGuide for Solving a Supply Chain Optimization Problem with Nested Chats with a Coding Agent and a Safeguard Agent - [View Notebook](/docs/notebooks/agentchat_nestedchat_optiguide)
|
||||
|
||||
1. **Applications**
|
||||
|
||||
|
|
Loading…
Reference in New Issue