Skip to content

Commit 9b56ce5

Browse files
authored
adjust order of side bars (microsoft#2040)
* adjust order of side bars * doc improvement * limit max turns * improve tests * improve doc * improve docstr
1 parent accd16b commit 9b56ce5

File tree

8 files changed

+121
-118
lines changed

8 files changed

+121
-118
lines changed

autogen/agentchat/chat.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,20 @@ def initiate_chats(chat_queue: List[Dict[str, Any]]) -> List[ChatResult]:
139139
Args:
140140
chat_queue (List[Dict]): a list of dictionaries containing the information about the chats.
141141
142-
Each dictionary should contain the input arguments for `ConversableAgent.initiate_chat`. For example:
143-
"sender": the sender agent.
144-
"recipient": the recipient agent.
145-
"clear_history" (bool): whether to clear the chat history with the agent. Default is True.
146-
"silent" (bool or None): (Experimental) whether to print the messages in this conversation. Default is False.
147-
"cache" (Cache or None): the cache client to use for this conversation. Default is None.
148-
"max_turns" (int or None): maximum number of turns for the chat. If None, the chat will continue until a termination condition is met. Default is None.
149-
"summary_method" (str or callable): a string or callable specifying the method to get a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg".
150-
"summary_args" (dict): a dictionary of arguments to be passed to the summary_method. Default is {}.
151-
"message" (str, callable or None): if None, input() will be called to get the initial message.
152-
**context: additional context information to be passed to the chat.
153-
"carryover": It can be used to specify the carryover information to be passed to this chat.
154-
If provided, we will combine this carryover with the "message" content when generating the initial chat
155-
message in `generate_init_message`.
142+
Each dictionary should contain the input arguments for [`ConversableAgent.initiate_chat`](/docs/reference/agentchat/conversable_agent#initiate_chat). For example:
143+
- "sender": the sender agent.
144+
- "recipient": the recipient agent.
145+
- "clear_history" (bool): whether to clear the chat history with the agent. Default is True.
146+
- "silent" (bool or None): (Experimental) whether to print the messages in this conversation. Default is False.
147+
- "cache" (Cache or None): the cache client to use for this conversation. Default is None.
148+
- "max_turns" (int or None): maximum number of turns for the chat. If None, the chat will continue until a termination condition is met. Default is None.
149+
- "summary_method" (str or callable): a string or callable specifying the method to get a summary from the chat. Default is DEFAULT_summary_method, i.e., "last_msg".
150+
- "summary_args" (dict): a dictionary of arguments to be passed to the summary_method. Default is {}.
151+
- "message" (str, callable or None): if None, input() will be called to get the initial message.
152+
- **context: additional context information to be passed to the chat.
153+
- "carryover": It can be used to specify the carryover information to be passed to this chat.
154+
If provided, we will combine this carryover with the "message" content when generating the initial chat
155+
message in `generate_init_message`.
156156
157157
Returns:
158158
(list): a list of ChatResult objects corresponding to the finished chats in the chat_queue.

autogen/agentchat/conversable_agent.py

+66-61
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,18 @@ def register_reply(
296296
from both sync and async chats. However, an async reply function will only be triggered from async
297297
chats (initiated with `ConversableAgent.a_initiate_chat`). If an `async` reply function is registered
298298
and a chat is initialized with a sync function, `ignore_async_in_sync_chat` determines the behaviour as follows:
299-
- if `ignore_async_in_sync_chat` is set to `False` (default value), an exception will be raised, and
300-
- if `ignore_async_in_sync_chat` is set to `True`, the reply function will be ignored.
299+
if `ignore_async_in_sync_chat` is set to `False` (default value), an exception will be raised, and
300+
if `ignore_async_in_sync_chat` is set to `True`, the reply function will be ignored.
301301
302302
Args:
303303
trigger (Agent class, str, Agent instance, callable, or list): the trigger.
304-
- If a class is provided, the reply function will be called when the sender is an instance of the class.
305-
- If a string is provided, the reply function will be called when the sender's name matches the string.
306-
- If an agent instance is provided, the reply function will be called when the sender is the agent instance.
307-
- If a callable is provided, the reply function will be called when the callable returns True.
308-
- If a list is provided, the reply function will be called when any of the triggers in the list is activated.
309-
- If None is provided, the reply function will be called only when the sender is None.
310-
Note: Be sure to register `None` as a trigger if you would like to trigger an auto-reply function with non-empty messages and `sender=None`.
304+
If a class is provided, the reply function will be called when the sender is an instance of the class.
305+
If a string is provided, the reply function will be called when the sender's name matches the string.
306+
If an agent instance is provided, the reply function will be called when the sender is the agent instance.
307+
If a callable is provided, the reply function will be called when the callable returns True.
308+
If a list is provided, the reply function will be called when any of the triggers in the list is activated.
309+
If None is provided, the reply function will be called only when the sender is None.
310+
Note: Be sure to register `None` as a trigger if you would like to trigger an auto-reply function with non-empty messages and `sender=None`.
311311
reply_func (Callable): the reply function.
312312
The function takes a recipient agent, a list of messages, a sender agent and a config as input and returns a reply message.
313313
position: the position of the reply function in the reply function list.
@@ -880,66 +880,71 @@ def initiate_chat(
880880
silent (bool or None): (Experimental) whether to print the messages for this conversation. Default is False.
881881
cache (Cache or None): the cache client to be used for this conversation. Default is None.
882882
max_turns (int or None): the maximum number of turns for the chat between the two agents. One turn means one conversation round trip. Note that this is different from
883-
[max_consecutive_auto_reply](#max_consecutive_auto_reply) which is the maximum number of consecutive auto replies; and it is also different from [max_rounds in GroupChat](./groupchat#groupchat-objects) which is the maximum number of rounds in a group chat session.
884-
If max_turns is set to None, the chat will continue until a termination condition is met. Default is None.
885-
summary_method (string or callable) : a method to get a summary from the chat. Default is DEFAULT_SUMMARY_METHOD, i.e., "last_msg".
886-
- Supported string are "last_msg" and "reflection_with_llm":
887-
when set "last_msg", it returns the last message of the dialog as the summary.
888-
when set "reflection_with_llm", it returns a summary extracted using an llm client.
889-
`llm_config` must be set in either the recipient or sender.
890-
"reflection_with_llm" requires the llm_config to be set in either the sender or the recipient.
891-
- A callable summary_method should take the recipient and sender agent in a chat as input and return a string of summary. E.g,
892-
```python
893-
def my_summary_method(
894-
sender: ConversableAgent,
895-
recipient: ConversableAgent,
896-
summary_args: dict,
897-
):
898-
return recipient.last_message(sender)["content"]
899-
```
883+
[max_consecutive_auto_reply](#max_consecutive_auto_reply) which is the maximum number of consecutive auto replies; and it is also different from [max_rounds in GroupChat](./groupchat#groupchat-objects) which is the maximum number of rounds in a group chat session.
884+
If max_turns is set to None, the chat will continue until a termination condition is met. Default is None.
885+
summary_method (str or callable): a method to get a summary from the chat. Default is DEFAULT_SUMMARY_METHOD, i.e., "last_msg".
886+
887+
Supported strings are "last_msg" and "reflection_with_llm":
888+
- when set to "last_msg", it returns the last message of the dialog as the summary.
889+
- when set to "reflection_with_llm", it returns a summary extracted using an llm client.
890+
`llm_config` must be set in either the recipient or sender.
891+
892+
A callable summary_method should take the recipient and sender agent in a chat as input and return a string of summary. E.g.,
893+
894+
```python
895+
def my_summary_method(
896+
sender: ConversableAgent,
897+
recipient: ConversableAgent,
898+
summary_args: dict,
899+
):
900+
return recipient.last_message(sender)["content"]
901+
```
900902
summary_args (dict): a dictionary of arguments to be passed to the summary_method.
901-
E.g., a string of text used to prompt a LLM-based agent (the sender or receiver agent) to reflext
902-
on the conversation and extract a summary when summary_method is "reflection_with_llm".
903-
Default is DEFAULT_SUMMARY_PROMPT, i.e., "Summarize takeaway from the conversation. Do not add any introductory phrases. If the intended request is NOT properly addressed, please point it out."
903+
One example key is "summary_prompt", and value is a string of text used to prompt a LLM-based agent (the sender or receiver agent) to reflect
904+
on the conversation and extract a summary when summary_method is "reflection_with_llm".
905+
The default summary_prompt is DEFAULT_SUMMARY_PROMPT, i.e., "Summarize takeaway from the conversation. Do not add any introductory phrases. If the intended request is NOT properly addressed, please point it out."
904906
message (str, dict or Callable): the initial message to be sent to the recipient. Needs to be provided. Otherwise, input() will be called to get the initial message.
905-
- If a string or a dict is provided, it will be used as the initial message. `generate_init_message` is called to generate the initial message for the agent based on this string and the context.
906-
If dict, it may contain the following reserved fields (either content or function_call need to be provided).
907-
1. "content": content of the message, can be None.
908-
2. "function_call": a dictionary containing the function name and arguments. (deprecated in favor of "tool_calls")
909-
3. "tool_calls": a list of dictionaries containing the function name and arguments.
910-
4. "role": role of the message, can be "assistant", "user", "function".
911-
This field is only needed to distinguish between "function" or "assistant"/"user".
912-
5. "name": In most cases, this field is not needed. When the role is "function", this field is needed to indicate the function name.
913-
6. "context" (dict): the context of the message, which will be passed to
914-
[OpenAIWrapper.create](../oai/client#create).
915-
- If a callable is provided, it will be called to get the initial message in the form of a string or a dict. If the returned value is a dict, it should contain the following reserved fields:
907+
- If a string or a dict is provided, it will be used as the initial message. `generate_init_message` is called to generate the initial message for the agent based on this string and the context.
908+
If dict, it may contain the following reserved fields (either content or tool_calls need to be provided).
909+
910+
1. "content": content of the message, can be None.
911+
2. "function_call": a dictionary containing the function name and arguments. (deprecated in favor of "tool_calls")
912+
3. "tool_calls": a list of dictionaries containing the function name and arguments.
913+
4. "role": role of the message, can be "assistant", "user", "function".
914+
This field is only needed to distinguish between "function" or "assistant"/"user".
915+
5. "name": In most cases, this field is not needed. When the role is "function", this field is needed to indicate the function name.
916+
6. "context" (dict): the context of the message, which will be passed to
917+
[OpenAIWrapper.create](../oai/client#create).
918+
919+
- If a callable is provided, it will be called to get the initial message in the form of a string or a dict.
916920
If the returned type is dict, it may contain the reserved fields mentioned above.
917921
918922
Example of a callable message (returning a string):
919-
```python
920-
def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: dict) -> Union[str, Dict]:
921-
carryover = context.get("carryover", "")
922-
if isinstance(message, list):
923-
carryover = carryover[-1]
924-
final_msg = "Write a blogpost." + "\nContext: \n" + carryover
925-
return final_msg
926-
```
923+
924+
```python
925+
def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: dict) -> Union[str, Dict]:
926+
carryover = context.get("carryover", "")
927+
if isinstance(message, list):
928+
carryover = carryover[-1]
929+
final_msg = "Write a blogpost." + "\\nContext: \\n" + carryover
930+
return final_msg
931+
```
927932
928933
Example of a callable message (returning a dict):
929-
```python
930-
def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: dict) -> Union[str, Dict]:
931-
final_msg = {}
932-
carryover = context.get("carryover", "")
933-
carryover = context.get("carryover", "")
934-
if isinstance(message, list):
935-
carryover = carryover[-1]
936-
final_msg["content"] = "Write a blogpost." + "\nContext: \n" + carryover
937-
final_msg["context"] = {"prefix": "Today I feel"}
938-
return final_msg
939-
```
934+
935+
```python
936+
def my_message(sender: ConversableAgent, recipient: ConversableAgent, context: dict) -> Union[str, Dict]:
937+
final_msg = {}
938+
carryover = context.get("carryover", "")
939+
if isinstance(message, list):
940+
carryover = carryover[-1]
941+
final_msg["content"] = "Write a blogpost." + "\\nContext: \\n" + carryover
942+
final_msg["context"] = {"prefix": "Today I feel"}
943+
return final_msg
944+
```
940945
**context: any context information. It has the following reserved fields:
941-
"carryover": a string or a list of string to specify the carryover information to be passed to this chat.
942-
If provided, we will combine this carryover (by attaching a "context: "string and the carryover content after the message content) with the "message" content when generating the initial chat
946+
- "carryover": a string or a list of string to specify the carryover information to be passed to this chat.
947+
If provided, we will combine this carryover (by attaching a "context: " string and the carryover content after the message content) with the "message" content when generating the initial chat
943948
message in `generate_init_message`.
944949
945950
Raises:

autogen/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.19"
1+
__version__ = "0.2.20"

test/agentchat/test_async_chats.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env python3 -m pytest
22

3-
from autogen import AssistantAgent, UserProxyAgent
4-
from autogen import GroupChat, GroupChatManager
5-
import asyncio
6-
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
73
import pytest
8-
from conftest import skip_openai
4+
import sys
5+
import os
96
import autogen
10-
from typing import Literal
11-
from typing_extensions import Annotated
12-
from autogen import initiate_chats
7+
from autogen import AssistantAgent, UserProxyAgent
8+
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
9+
10+
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
11+
from conftest import skip_openai # noqa: E402
1312

1413

1514
@pytest.mark.skipif(skip_openai, reason="requested to skip openai tests")
@@ -31,6 +30,7 @@ async def test_async_chats():
3130
financial_assistant_1 = AssistantAgent(
3231
name="Financial_assistant_1",
3332
llm_config={"config_list": config_list},
33+
system_message="You are a knowledgeable AI Assistant.",
3434
)
3535
financial_assistant_2 = AssistantAgent(
3636
name="Financial_assistant_2",
@@ -60,7 +60,7 @@ async def test_async_chats():
6060
)
6161

6262
def my_summary_method(recipient, sender, summary_args):
63-
return recipient.chat_messages[sender][0].get("content", "")
63+
return recipient.chat_messages[sender][-1].get("content", "")
6464

6565
chat_res = await user.a_initiate_chats(
6666
[
@@ -78,6 +78,7 @@ def my_summary_method(recipient, sender, summary_args):
7878
"message": financial_tasks[1],
7979
"silent": True,
8080
"summary_method": "reflection_with_llm",
81+
"max_turns": 3,
8182
},
8283
{
8384
"chat_id": 3,

0 commit comments

Comments
 (0)