Skip to content

Commit

Permalink
Merge pull request #60 from ag2ai/swarmdocfix
Browse files Browse the repository at this point in the history
Fix Swarm Doc
  • Loading branch information
qingyun-wu authored Nov 21, 2024
2 parents bc0543f + 3d6fc42 commit c6c94ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions website/blog/2024-11-17-Swarm/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ responder.register_hand_off(
You can specify the swarm-level after work handoff when initiating the swarm (here we nominate to terminate):
```python
history, context, last_agent = initiate_swarm_chat(
init_agent=responder,
initial_agent=responder,
agents=my_list_of_swarm_agents,
max_rounds=30,
messages=messages,
Expand Down Expand Up @@ -157,7 +157,7 @@ user = UserProxyAgent(name="User", code_execution_config=False)
# Returns the ChatResult, final context, and last speaker

chat_result, context_variables, last_speaker = initiate_swarm_chat(
init_agent=customer_service, # Starting agent
initial_agent=customer_service, # Starting agent
agents=[customer_service, refund_specialist, payment_processor, satisfaction_surveyor],
user_agent=user, # Human user
messages="Customer requesting refund for order #12345",
Expand Down
18 changes: 12 additions & 6 deletions website/docs/topics/swarm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,20 @@
"\n",
"```python\n",
"chat_history, context_variables, last_active_agent = initiate_swarm_chat(\n",
" init_agent=agent_1, # the first agent to start the chat\n",
" initial_agent=agent_1, # the first agent to start the chat\n",
" agents=[agent_1, agent_2, agent_3], # a list of agents\n",
" messages=[{\"role\": \"user\", \"content\": \"Hello\"}], # a list of messages to start the chat\n",
" messages=[{\"role\": \"user\", \"content\": \"Hello\"}], # a list of messages to start the chat, you can also pass in one string\n",
" user_agent=user_agent, # optional, if you want to revert to the user agent\n",
" context_variables={\"key\": \"value\"} # optional, initial context variables\n",
")\n",
"```\n",
"\n",
"How we handle messages: \n",
"- Case 1: If you pass in one single message \n",
" - If there is a name in that message, we will assume this message is from that agent. (It will be error if that name doesn't match any agent you passed in.) \n",
" - If there is no name, 1. User agent passed in: we assume this message is from the user agent. 2. No user agent passed in: we will create a temporary user agent just to start the chat. \n",
"- Case 2: We will use the [Resume GroupChat](https://ag2ai.github.io/ag2/docs/topics/groupchat/resuming_groupchat) feature to resume the chat. The `name` fields in these messages must be one of the names of the agents you passed in, otherwise, it will be an error.\n",
"\n",
"## Q&As\n",
"\n",
"> How are context variables updated?\n",
Expand Down Expand Up @@ -243,14 +249,14 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mAgent_1\u001b[0m (to chat_manager):\n",
"\u001b[33m_User\u001b[0m (to chat_manager):\n",
"\n",
"start\n",
"\n",
Expand Down Expand Up @@ -403,7 +409,7 @@
"source": [
"context_variables = {\"1\": False, \"2\": False, \"3\": False}\n",
"chat_result, context_variables, last_agent = initiate_swarm_chat(\n",
" init_agent=agent_1,\n",
" initial_agent=agent_1,\n",
" agents=[agent_1, agent_2, agent_3, agent_4, agent_5],\n",
" messages=\"start\",\n",
" context_variables=context_variables,\n",
Expand Down Expand Up @@ -554,7 +560,7 @@
")\n",
"\n",
"chat_result, _, _ = initiate_swarm_chat(\n",
" init_agent=agent_6,\n",
" initial_agent=agent_6,\n",
" agents=[agent_6, agent_7],\n",
" user_agent=user_agent,\n",
" messages=\"start\",\n",
Expand Down

0 comments on commit c6c94ab

Please sign in to comment.