From the course: Building AI Agents with AutoGen
Create agents
It's time to put our knowledge into practice. In this lesson, we'll focus on setting up our code-writing agent and a code executor agent. So let's see how to do that. I've imported the required libraries, but there is an important addition for code execution. We're going to use local command line code executor provided by the coding module of AutoGen. So import the libraries, configure the LLM. The next step is to add a code executor. Now since we are using local command line code execution, I have created an instance here where timeout is the timeout for each code execution in seconds. So this is 10 seconds. And then we have provided a work directory where all the code or the outputs are going to get stored. So I have provided coding. That means a coding directory is created within the system, and all the code files or assets are going to get stored within this directory. So let's run this. Our executor is also ready now. The next thing is to create our code executor agent. Now, to define our code executor agent, we are using ConversableAgent class from AutoGen. I have provided the name, code_executor_agent. This does not require LLM. So llm_config has been set to false because the agent doesn't need to generate any text. Then we provide a code_execution_config with the executor which we have defined earlier. And then human input mode is set to always allowing for human intervention if needed. We provide a default autoreply to guide the conversation flow. So let's run this cell to define the executor agent. Further, we define our code writing agent. So here we are using the assistant agent class from AutoGen. We have named it code_writer_agent. We have provided the llm_config, allowing the agent to generate text and code. We set the code_execution_config to false because this agent will write code, but not execute it. We set human input mode to never as we want the agent to operate autonomously. So run this and our writer agent is also created. If you want to check the system message of any of these agents, you can check that as well. So we can capture the system message attribute from the code writer agent here. So once you run this code_writer_agent_system_message, and there you go. You are a helpful AI assistant. Solve tasks for coding and language skills. So this is the complete system message for our code writer agent. Note that the system message is a crucial part of agent's configuration, as it defines the agent's role and capabilities. So in this lesson, we have set up the two main agents for our coding copilot, a code executor agent that can run the code and provide feedback, and a code writer agent that can generate the code based on requirements. In the next lesson, we'll define a specific task for our coding copilot.