Skip to content

Commit 725d573

Browse files
ekzhujackgerrits
andauthored
Update tutorial content; move selector group chat and swarm outside of tutorial. (#4915)
* Update tutorial content; move selector group chat and swarm outside of tutorial. * Add redirect --------- Co-authored-by: Jack Gerrits <[email protected]>
1 parent 5b9be79 commit 725d573

File tree

12 files changed

+75
-58
lines changed

12 files changed

+75
-58
lines changed

python/packages/autogen-core/docs/src/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"sphinx.ext.viewcode",
3434
"sphinx.ext.intersphinx",
3535
"sphinx.ext.graphviz",
36+
"sphinxext.rediraffe",
3637
"sphinx_design",
3738
"sphinx_copybutton",
3839
"_extension.gallery_directive",
@@ -165,6 +166,11 @@
165166
('code_lint', 'text/plain', 100)
166167
]
167168

169+
rediraffe_redirects = {
170+
"user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb": "user-guide/agentchat-user-guide/selector-group-chat.ipynb",
171+
"user-guide/agentchat-user-guide/tutorial/swarm.ipynb": "user-guide/agentchat-user-guide/swarm.ipynb",
172+
}
173+
168174

169175
def setup_to_main(
170176
app: Sphinx, pagename: str, templatename: str, context, doctree

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/index.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,28 @@ How to install AgentChat
3131
Build your first agent
3232
:::
3333

34-
:::{grid-item-card} {fas}`book;pst-color-primary` Magentic-One
35-
:link: ./magentic-one.html
34+
:::{grid-item-card} {fas}`graduation-cap;pst-color-primary` Tutorial
35+
:link: ./tutorial/models.html
3636

37-
Get started with Magentic-One
37+
Step-by-step guide to using AgentChat, learn about agents, teams, and more
3838
:::
3939

40-
:::{grid-item-card} {fas}`graduation-cap;pst-color-primary` Tutorial
41-
:link: ./tutorial/models.html
40+
:::{grid-item-card} {fas}`book;pst-color-primary` Selector Group Chat
41+
:link: ./selector-group-chat.html
42+
43+
Multi-agent coordination through a shared context and centralized, customizable selector
44+
:::
45+
46+
:::{grid-item-card} {fas}`book;pst-color-primary` Swarm
47+
:link: ./swarm.html
48+
49+
Multi-agent coordination through a shared context and localized, tool-based selector
50+
:::
4251

43-
Step-by-step guide to using AgentChat
52+
:::{grid-item-card} {fas}`book;pst-color-primary` Magentic-One
53+
:link: ./magentic-one.html
54+
55+
Get started with Magentic-One
4456
:::
4557

4658
:::{grid-item-card} {fas}`code;pst-color-primary` Examples
@@ -62,7 +74,6 @@ How to migrate from AutoGen 0.2.x to 0.4.x.
6274
6375
installation
6476
quickstart
65-
magentic-one
6677
migration-guide
6778
```
6879

@@ -76,13 +87,21 @@ tutorial/messages
7687
tutorial/agents
7788
tutorial/teams
7889
tutorial/human-in-the-loop
79-
tutorial/selector-group-chat
80-
tutorial/swarm
8190
tutorial/termination
8291
tutorial/custom-agents
8392
tutorial/state
8493
```
8594

95+
```{toctree}
96+
:maxdepth: 1
97+
:hidden:
98+
:caption: Advanced
99+
100+
selector-group-chat
101+
swarm
102+
magentic-one
103+
```
104+
86105
```{toctree}
87106
:maxdepth: 1
88107
:hidden:

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/migration-guide.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ for more details.
600600
In `v0.4`, you get a {py:class}`~autogen_agentchat.base.TaskResult` object from a `run` or `run_stream` method.
601601
The {py:class}`~autogen_agentchat.base.TaskResult` object contains the `messages` which is the message history
602602
of the chat, including both agents' private (tool calls, etc.) and public messages.
603-
603+
604604
There are some notable differences between {py:class}`~autogen_agentchat.base.TaskResult` and `ChatResult`:
605605

606606
- The `messages` list in {py:class}`~autogen_agentchat.base.TaskResult` uses different message format than the `ChatResult.chat_history` list.
@@ -610,7 +610,6 @@ There are some notable differences between {py:class}`~autogen_agentchat.base.Ta
610610

611611
## Conversion between v0.2 and v0.4 Messages
612612

613-
614613
You can use the following conversion functions to convert between a v0.4 message in
615614
{py:attr}`autogen_agentchat.base.TaskResult.messages` and a v0.2 message in `ChatResult.chat_history`.
616615

@@ -809,7 +808,7 @@ asyncio.run(main())
809808
```
810809

811810
For LLM-based speaker selection, you can use the {py:class}`~autogen_agentchat.teams.SelectorGroupChat` instead.
812-
See [Selector Group Chat Tutorial](./tutorial/selector-group-chat.ipynb)
811+
See [Selector Group Chat Tutorial](./selector-group-chat.ipynb)
813812
and {py:class}`~autogen_agentchat.teams.SelectorGroupChat` for more details.
814813

815814
> **Note**: In `v0.4`, you do not need to register functions on a user proxy to use tools
@@ -912,7 +911,7 @@ as the tools are directly executed within the {py:class}`~autogen_agentchat.agen
912911
which publishes the response from the tool to the group chat.
913912
So the group chat manager does not need to be involved in routing tool calls.
914913

915-
See [Selector Group Chat Tutorial](./tutorial/selector-group-chat.ipynb) for an example
914+
See [Selector Group Chat Tutorial](./selector-group-chat.ipynb) for an example
916915
of using tools in a group chat.
917916

918917
## Group Chat with Custom Selector (Stateflow)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"- Customizable selection function to override the default model-based selection\n",
2323
"\n",
2424
"```{note}\n",
25-
"{py:class}`~autogen_agentchat.teams.SelectorGroupChat` is a high-level API. For more control and customization, refer to the [Group Chat Pattern](../../core-user-guide/design-patterns/group-chat.ipynb) in the Core API documentation to implement your own group chat logic.\n",
25+
"{py:class}`~autogen_agentchat.teams.SelectorGroupChat` is a high-level API. For more control and customization, refer to the [Group Chat Pattern](../core-user-guide/design-patterns/group-chat.ipynb) in the Core API documentation to implement your own group chat logic.\n",
2626
"```\n",
2727
"\n",
2828
"## How Does it Work?\n",
@@ -32,7 +32,7 @@
3232
"When the team receives a task through {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run` or {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run_stream`,\n",
3333
"the following steps are executed:\n",
3434
"\n",
35-
"1. The team analyzes the current conversation context, including the conversation history and participants' {py:attr}`~autogen_agentchat.base.ChatAgent.name` and {py:attr}`~autogen_agentchat.base.ChatAgent.description` attributes, to determine the next speaker using a model. You can override the model by providing a custom selection function.\n",
35+
"1. The team analyzes the current conversation context, including the conversation history and participants' {py:attr}`~autogen_agentchat.base.ChatAgent.name` and {py:attr}`~autogen_agentchat.base.ChatAgent.description` attributes, to determine the next speaker using a model. By default, the team will not select the same speak consecutively unless it is the only agent available. This can be changed by setting `allow_repeated_speaker=True`. You can also override the model by providing a custom selection function.\n",
3636
"2. The team prompts the selected speaker agent to provide a response, which is then **broadcasted** to all other participants.\n",
3737
"3. The termination condition is checked to determine if the conversation should end, if not, the process repeats from step 1.\n",
3838
"4. When the conversation ends, the team returns the {py:class}`~autogen_agentchat.base.TaskResult` containing the conversation history from this task.\n",

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/swarm.ipynb renamed to python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/swarm.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"```{note}\n",
1919
"{py:class}`~autogen_agentchat.teams.Swarm` is a high-level API. If you need more\n",
2020
"control and customization that is not supported by this API, you can take a look\n",
21-
"at the [Handoff Pattern](../../core-user-guide/design-patterns/handoffs.ipynb)\n",
21+
"at the [Handoff Pattern](../core-user-guide/design-patterns/handoffs.ipynb)\n",
2222
"in the Core API documentation and implement your own version of the Swarm pattern.\n",
2323
"```\n",
2424
"\n",

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages`: Send the agent a sequence of {py:class}`~autogen_agentchat.messages.ChatMessage` get a {py:class}`~autogen_agentchat.base.Response`. **It is important to note that agents are expected to be stateful and this method is expected to be called with new messages, not the complete history**.\n",
1515
"- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream`: Same as {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages` but returns an iterator of {py:class}`~autogen_agentchat.messages.AgentEvent` or {py:class}`~autogen_agentchat.messages.ChatMessage` followed by a {py:class}`~autogen_agentchat.base.Response` as the last item.\n",
1616
"- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_reset`: Reset the agent to its initial state.\n",
17+
"- {py:meth}`~autogen_agentchat.agents.BaseChatAgent.run` and {py:meth}`~autogen_agentchat.agents.BaseChatAgent.run_stream`: convenience methods that call {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages` and {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream` respectively but offer the same interface as [Teams](./teams.ipynb).\n",
1718
"\n",
1819
"See {py:mod}`autogen_agentchat.messages` for more information on AgentChat message types.\n",
1920
"\n",
@@ -115,7 +116,10 @@
115116
"Unlike in v0.2 AgentChat, the tools are executed by the same agent directly within\n",
116117
"the same call to {py:meth}`~autogen_agentchat.agents.AssistantAgent.on_messages`.\n",
117118
"By default, the agent will return the result of the tool call as the final response.\n",
118-
"```"
119+
"```\n",
120+
"\n",
121+
"You can also call the {py:meth}`~autogen_agentchat.agents.BaseChatAgent.run` method, which is a convenience method that calls {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages`. \n",
122+
"It follows the same interface as [Teams](./teams.ipynb) and returns a {py:class}`~autogen_agentchat.base.TaskResult` object."
119123
]
120124
},
121125
{
@@ -186,7 +190,9 @@
186190
"with the final item being the response message in the {py:attr}`~autogen_agentchat.base.Response.chat_message` attribute.\n",
187191
"\n",
188192
"From the messages, you can observe that the assistant agent utilized the `web_search` tool to\n",
189-
"gather information and responded based on the search results."
193+
"gather information and responded based on the search results.\n",
194+
"\n",
195+
"You can also use {py:meth}`~autogen_agentchat.agents.BaseChatAgent.run_stream` to get the same streaming behavior as {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream`. It follows the same interface as [Teams](./teams.ipynb)."
190196
]
191197
},
192198
{
@@ -310,45 +316,6 @@
310316
")"
311317
]
312318
},
313-
{
314-
"cell_type": "markdown",
315-
"metadata": {},
316-
"source": [
317-
"## User Proxy Agent\n",
318-
"\n",
319-
"{py:class}`~autogen_agentchat.agents.UserProxyAgent` is a built-in agent that\n",
320-
"provides one way for a user to intervene in the process. This agent will put the team in a temporary blocking state, and thus any exceptions or runtime failures while in the blocked state will result in a deadlock. It is strongly advised that this agent be coupled with a timeout mechanic and that all errors and exceptions emanating from it are handled."
321-
]
322-
},
323-
{
324-
"cell_type": "code",
325-
"execution_count": null,
326-
"metadata": {},
327-
"outputs": [],
328-
"source": [
329-
"from autogen_agentchat.agents import UserProxyAgent\n",
330-
"\n",
331-
"\n",
332-
"async def user_proxy_run() -> None:\n",
333-
" user_proxy_agent = UserProxyAgent(\"user_proxy\")\n",
334-
" response = await user_proxy_agent.on_messages(\n",
335-
" [TextMessage(content=\"What is your name? \", source=\"user\")], cancellation_token=CancellationToken()\n",
336-
" )\n",
337-
" print(f\"Your name is {response.chat_message.content}\")\n",
338-
"\n",
339-
"\n",
340-
"# Use asyncio.run(user_proxy_run()) when running in a script.\n",
341-
"await user_proxy_run()"
342-
]
343-
},
344-
{
345-
"cell_type": "markdown",
346-
"metadata": {},
347-
"source": [
348-
"The User Proxy agent is ideally used for on-demand human-in-the-loop interactions for scenarios such as Just In Time approvals, human feedback, alerts, etc. For slower user interactions, consider terminating a team using a termination condition and start another one from\n",
349-
"{py:meth}`~autogen_agentchat.base.TaskRunner.run` or {py:meth}`~autogen_agentchat.base.TaskRunner.run_stream` with another message."
350-
]
351-
},
352319
{
353320
"cell_type": "markdown",
354321
"metadata": {},
@@ -357,6 +324,7 @@
357324
"\n",
358325
"The following preset agents are available:\n",
359326
"\n",
327+
"- {py:class}`~autogen_agentchat.agents.UserProxyAgent`: An agent that takes user input returns it as responses.\n",
360328
"- {py:class}`~autogen_agentchat.agents.CodeExecutorAgent`: An agent that can execute code.\n",
361329
"- {py:class}`~autogen_ext.agents.openai.OpenAIAssistantAgent`: An agent that is backed by an OpenAI Assistant, with ability to use custom tools.\n",
362330
"- {py:class}`~autogen_ext.agents.web_surfer.MultimodalWebSurfer`: A multi-modal agent that can search the web and visit web pages for information.\n",

python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
"\n",
99
"In this section you'll learn how to create a _multi-agent team_ (or simply team) using AutoGen. A team is a group of agents that work together to achieve a common goal.\n",
1010
"\n",
11-
"We'll first show you how to create and run a team. We'll then explain how to observe the team's behavior, which is crucial for debugging and understanding the team's performance, and common operations to control the team's behavior."
11+
"We'll first show you how to create and run a team. We'll then explain how to observe the team's behavior, which is crucial for debugging and understanding the team's performance, and common operations to control the team's behavior.\n",
12+
"\n",
13+
"```{note}\n",
14+
"When to use a team? \n",
15+
"Teams can solve more complex tasks but they also need more scaffolding to steer than single agents.\n",
16+
"While AgentChat has made it easier for you to work with teams,\n",
17+
"you should first try to solve your problem with a single agent, and use a team\n",
18+
"when a single agent becomes insufficient.\n",
19+
"Make sure you have tried giving your single agent the right tools and instructions before\n",
20+
"moving to a team.\n",
21+
"```"
1222
]
1323
},
1424
{

python/packages/autogen-core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dev = [
7171
"sphinxcontrib-apidoc",
7272
"autodoc_pydantic~=2.2",
7373
"pygments",
74+
"sphinxext-rediraffe",
7475

7576
"autogen_ext==0.4.0.dev13",
7677

python/uv.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)