This notebook has been updated as swarms can now accommodate any ConversableAgent.
Install
ag2
:Note: If you have been usingFor more information, please refer to the installation guide.autogen
orag2
, all you need to do is upgrade it using:orasautogen
, andag2
are aliases for the same PyPI package.
Set your API Endpoint
Theconfig_list_from_json
function loads a list of configurations from an environment variable or
a json file.
Prompts & Utility Functions
The prompts and utility functions remain unchanged from the original example.Define Agents and register functions
Register Handoffs
Now we register the handoffs for the agents. Note that you don’t need to define the transfer functions and pass them in. Instead, you can directly register the handoffs using theOnCondition
class.
Run the code
Finally, callinitiate_swarm_chat
to start the conversation.
For this example, it requires human interaction with the agents. So we
pass in a user
agent, and set the after_work
parameter to
AfterWorkOption.REVERT_TO_USER
. This means, each time a swarm agent
finishes its work, the conversation will be reverted back to the user to
give the next input.
You need to interact with the agents for this example. (You can try different inputs to see how they react!)Here is a sequence of messages entered in this example: To initialize the conversation, we pass
I want to cancel flight
to the
initiate_swarm_chat
function. 1. please cancel it
(Ask for reason
but don’t provide one) 2. 1919
(The flight number) 3.
I want flight credits
4. No
(No further questions) 5. exit
(End
the conversation)