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

Adding register_nested_chats to make nested chat easier #1753

Merged
merged 73 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a13fba7
add util
qingyun-wu Feb 7, 2024
8fb3dd7
add notebook
qingyun-wu Feb 9, 2024
cd7349f
SoM notebook
qingyun-wu Feb 9, 2024
3d63f94
doc
qingyun-wu Feb 9, 2024
b8f00cc
update notebook
qingyun-wu Feb 9, 2024
cb2924e
SoM
qingyun-wu Feb 9, 2024
ee1b7b5
optiguide
qingyun-wu Feb 9, 2024
40ee04f
rename
qingyun-wu Feb 9, 2024
4e3c7d0
add implementation
qingyun-wu Feb 10, 2024
24e2cd1
Merge remote-tracking branch 'origin/main' into nestchat
qingyun-wu Feb 10, 2024
e61a141
update notebook
qingyun-wu Feb 10, 2024
92153ae
update notebook
qingyun-wu Feb 10, 2024
4ab3d64
update notebook
qingyun-wu Feb 11, 2024
14ca65f
summary method
qingyun-wu Feb 11, 2024
33a3439
Merge remote-tracking branch 'origin/main' into nestchat
qingyun-wu Feb 11, 2024
64acda0
initiate_chats enhancements
qingyun-wu Feb 11, 2024
d87921a
callable summary_method
qingyun-wu Feb 11, 2024
f66df38
summary method
qingyun-wu Feb 11, 2024
69fa176
summary method default
qingyun-wu Feb 11, 2024
cac26bf
Merge branch 'main' into summary
qingyun-wu Feb 11, 2024
a6a1faa
docstr
qingyun-wu Feb 11, 2024
7125c90
add timeout to slient pip install test
ekzhu Feb 12, 2024
c48e26c
consolidate_chat_info
qingyun-wu Feb 12, 2024
4a65cef
Merge branch 'summary' of github.com:microsoft/autogen into summary
qingyun-wu Feb 12, 2024
48db528
a_initiate_chat
qingyun-wu Feb 12, 2024
f117d2d
Merge branch 'summary' into nestchat
qingyun-wu Feb 12, 2024
f6bcb9f
AssertionError tests
qingyun-wu Feb 12, 2024
d9739e9
AssertionError test
qingyun-wu Feb 12, 2024
dfaa118
update tests
qingyun-wu Feb 12, 2024
34672a8
Merge branch 'summary' into nestchat
qingyun-wu Feb 12, 2024
11e2959
update test
qingyun-wu Feb 12, 2024
588959a
Merge remote-tracking branch 'origin/main' into nestedchat-dev
qingyun-wu Feb 12, 2024
da7980b
remove redudant file
qingyun-wu Feb 12, 2024
edf3926
kwargs
qingyun-wu Feb 12, 2024
da378b7
Merge branch 'main' into nestedchat-dev
qingyun-wu Feb 13, 2024
e948d55
Merge remote-tracking branch 'origin/main' into nestedchat-dev
qingyun-wu Feb 14, 2024
1c7cac7
update notebook
qingyun-wu Feb 15, 2024
6495f9d
update notebook
qingyun-wu Feb 15, 2024
e12fc30
nested
qingyun-wu Feb 15, 2024
99e4314
update SoM
qingyun-wu Feb 15, 2024
540f3df
update notebook
qingyun-wu Feb 16, 2024
18d7f07
max_turns
qingyun-wu Feb 16, 2024
67b29f7
add notebook
qingyun-wu Feb 16, 2024
09e72f0
Merge branch 'turn-number' into nestedchat-dev
qingyun-wu Feb 16, 2024
053a99d
updatenotebook
qingyun-wu Feb 16, 2024
2609562
Merge remote-tracking branch 'origin/main' into nestedchat-dev
qingyun-wu Feb 19, 2024
4c7f761
Merge remote-tracking branch 'origin/main' into nestedchat-dev
qingyun-wu Feb 20, 2024
51248e7
add notebooks
qingyun-wu Feb 21, 2024
eefb51c
update notebook and test
qingyun-wu Feb 21, 2024
2d0558c
Merge remote-tracking branch 'origin/main' into nestedchat-dev
qingyun-wu Feb 21, 2024
856f86a
add links to the example page
qingyun-wu Feb 21, 2024
5cc316d
annotations
qingyun-wu Feb 24, 2024
0221b04
documentation
qingyun-wu Feb 24, 2024
d44ebeb
default values
qingyun-wu Feb 24, 2024
efe161c
Merge branch 'main' into nestedchat-dev
qingyun-wu Feb 24, 2024
bfe9e34
Expanded details about the purpose of each cell
signalprime Feb 24, 2024
fe76254
update default value
qingyun-wu Feb 25, 2024
ab5883f
default value for reply_func_from_nested_chats
qingyun-wu Feb 25, 2024
de8dede
default reply func name
qingyun-wu Feb 25, 2024
5fd028d
Merge pull request #1782 from signalprime/nestedchat-dev
qingyun-wu Feb 25, 2024
296aa67
update notebook
qingyun-wu Feb 25, 2024
28634b5
update optiGuide
qingyun-wu Feb 25, 2024
98a0aaa
upload fig
qingyun-wu Feb 25, 2024
d2b6148
optiGuide notebook
qingyun-wu Feb 25, 2024
1e73e99
doc
qingyun-wu Feb 25, 2024
f4447c1
update notebook
qingyun-wu Feb 25, 2024
7c8ca8d
update notebook
qingyun-wu Feb 25, 2024
9ad0a42
notebook format
qingyun-wu Feb 25, 2024
83aee24
update optiguide notebook
qingyun-wu Feb 25, 2024
b98e4a6
raise value error
qingyun-wu Feb 26, 2024
1364621
update notebook
qingyun-wu Feb 26, 2024
b976ddb
Improve language
gagb Feb 26, 2024
96b8aa7
Merge pull request #1796 from microsoft/gagb-nestedchat-dev
qingyun-wu Feb 27, 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
75 changes: 75 additions & 0 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import re
from collections import defaultdict
from functools import partial
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, TypeVar, Union
import warnings
from openai import BadRequestError
Expand Down Expand Up @@ -321,6 +322,80 @@ def reply_func(
if ignore_async_in_sync_chat and inspect.iscoroutinefunction(reply_func):
self._ignore_async_func_in_sync_chat_list.append(reply_func)

@staticmethod
def _summary_from_nested_chats(
chat_queue: List[Dict[str, Any]], recipient: Agent, messages: Union[str, Callable], sender: Agent, config: Any
) -> Tuple[bool, str]:
"""A simple chat reply function.
This function initiate one or a sequence of chats between the "recipient" and the agents in the
chat_queue.

It extracts and returns a summary from the nested chat based on the "summary_method" in each chat in chat_queue.

Returns:
Tuple[bool, str]: A tuple where the first element indicates the completion of the chat, and the second element contains the summary of the last chat if any chats were initiated.
"""
last_msg = messages[-1].get("content")
chat_to_run = []
for i, c in enumerate(chat_queue):
current_c = c.copy()
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.
if message is None and i == 0:
message = last_msg
if callable(message):
message = message(recipient, messages, sender, config)
# We only run chat that has a valid message. NOTE: This is prone to change dependin on applications.
if message:
current_c["message"] = message
chat_to_run.append(current_c)
if not chat_to_run:
return True, None
res = recipient.initiate_chats(chat_to_run)
return True, res[-1].summary

def register_nested_chats(
qingyun-wu marked this conversation as resolved.
Show resolved Hide resolved
self,
chat_queue: List[Dict[str, Any]],
trigger: Union[Type[Agent], str, Agent, Callable[[Agent], bool], List] = [Agent, None],
reply_func_from_nested_chats: Union[str, Callable] = "summary_from_nested_chats",
position: int = 2,
**kwargs,
) -> None:
"""Register a nested chat reply function.
Args:
chat_queue (list): a list of chat objects to be initiated.
trigger (Agent class, str, Agent instance, callable, or list): Default to [Agent, None]. Ref to `register_reply` for details.
reply_func_from_nested_chats (Callable, str): the reply function for the nested chat.
The function takes a chat_queue for nested chat, recipient agent, a list of messages, a sender agent and a config as input and returns a reply message.
Default to "summary_from_nested_chats", which corresponds to a built-in reply function that get summary from the nested chat_queue.
```python
def reply_func_from_nested_chats(
chat_queue: List[Dict],
recipient: ConversableAgent,
messages: Optional[List[Dict]] = None,
sender: Optional[Agent] = None,
config: Optional[Any] = None,
) -> Tuple[bool, Union[str, Dict, None]]:
```
position (int): Ref to `register_reply` for details. Default to 2. It means we first check the termination and human reply, then check the registered nested chat reply.
kwargs: Ref to `register_reply` for details.
"""
if reply_func_from_nested_chats == "summary_from_nested_chats":
reply_func_from_nested_chats = self._summary_from_nested_chats
if not callable(reply_func_from_nested_chats):
raise ValueError("reply_func_from_nested_chats must be a callable")
reply_func = partial(reply_func_from_nested_chats, chat_queue)
self.register_reply(
trigger,
reply_func,
position,
kwargs.get("config"),
kwargs.get("reset_config"),
ignore_async_in_sync_chat=kwargs.get("ignore_async_in_sync_chat"),
)

@property
def system_message(self) -> str:
"""Return the system message."""
Expand Down
Loading
Loading