This example is based on the comedian example
The code in main.py sets up a conversation between two agents: a comedian agent and a user proxy agent.
Let's break down the code step by step:
-
Importing Modules:
- The code begins by importing the necessary modules:
AssistantAgent,UserProxyAgent, andTeachabilityfrom theautogen.agentchat.contrib.capabilitiespackage. - It also imports the
osmodule.
- The code begins by importing the necessary modules:
-
Configuration:
- The code defines a list called
config_listwhich contains a dictionary with configuration details for the agents. - The dictionary includes information such as the model, API key, API type, base URL, and API version. These values are retrieved from environment variables using the
os.environ.get()function.
- The code defines a list called
-
Creating the Comedian Agent:
- The code creates an instance of the
AssistantAgentclass calledcomedian. - The
AssistantAgentconstructor takes several parameters:name: The name of the agent, which is set to "comedian".system_message: A system message that describes the agent's role, which is set to "You are a professional comedian. You can tell jokes and entertain people."description: A description of the agent, which is set to "This agent is a great comedian telling interesting and funny jokes."llm_config: A configuration dictionary that includes theconfig_listcreated earlier.
- The code creates an instance of the
-
Teachability:
- The code creates an instance of the
Teachabilityclass calledteachability. - The
Teachabilityconstructor takes several parameters:reset_db: A boolean value indicating whether to reset the agent's database, which is set toFalse.path_to_db_dir: The path to the directory where the agent's experience will be stored, which is set to "./comedian_assistant_experience".llm_config: A configuration dictionary that includes theconfig_listcreated earlier.
- The code creates an instance of the
-
Adding Teachability to the Comedian Agent:
- The code adds the
teachabilityinstance to thecomedianagent using theadd_to_agent()method of theTeachabilityclass. - This allows the
comedianagent to learn from user interactions and improve its responses over time.
- The code adds the
-
Creating the User Proxy Agent:
- The code creates an instance of the
UserProxyAgentclass calleduser_proxy - The
UserProxyAgentconstructor takes several parameters:name: The name of the agent, which is set to "user_proxy".code_execution_config: A configuration dictionary for code execution, which includes the working directory and whether to use Docker. In this case, the working directory is set to "coding" and Docker is not used.
- The code creates an instance of the
-
Initiating the Chat:
- The code initiates a chat between the
comedianagent and theuser_proxyagent using theinitiate_chat()method of theUserProxyAgentclass. - The
initiate_chat()method takes two parameters:- The first parameter is the agent to initiate the chat with, which is the
comedianagent in this case. - The second parameter is the message to start the conversation, which is set to "Tell me a joke about cats and ninjas."
- The first parameter is the agent to initiate the chat with, which is the
- The code initiates a chat between the
Overall, this code sets up a conversation between a comedian agent and a user proxy agent, allowing the user to interact with the comedian agent and receive jokes or entertainment. The Teachability capability is also added to the comedian agent, enabling it to learn from user interactions and improve its responses.