AutoGen Studio (2/4) – Next-level prompt engineering

Hi and welcome to this tutorial series on AutoGen Studio. My name is Dirk van Meerveld, and I’ll be your host and guide for this three part tutorial series where we’ll take a look at AutoGen Studio.

๐Ÿ‘‰ Go Back to the Full Course: Next Level Prompt Engineering with AutoGen Studio

AutoGen Studio is an open-source interface that runs on top of AutoGen. This combination will allow us to work with LLMs and give them skills (like tools/functions) that they can use and also allows us to use agents and even define multi-agent workflows. Think of it as a multi-agent framework. One of the most amazing features is that it can write and execute code on the fly to solve problems!

On top of that AutoGen Studio provides us with a sleek and easy-to-use interface to define all the above and chat with our agents, much of it without even having to write code! This truly is next-level prompt engineering and over the coming lessons, we will harness the power of digital agents and see them collaborate with each other!

In this first part, we’ll focus on the setup and take some time to properly get started. If you’re a more seasoned developer and intimately familiar with a particular topic like Docker, feel free to skip ahead a bit here and there, but we’ll cover all the bases so that everybody can follow along nicely. This is especially so as much of AutoGen Studio can be used via the interface which makes it more accessible to non-coders. We will leave no man or woman behind!

AutoGen safety measures

In order to answer more complex requests AutoGen will actually write Python code for you and execute this Python code on your local computer.

For example, there is a demo question where you ask the following question: "Plot a chart of NVDA and TESLA stock price for 2023. Save the result to a file named nvda_tesla.png". AutoGen will solve this question by writing Python code to get the stock prices, install needed libraries to execute the code, write code for creating the graph in MathPlotLib, etcโ€ฆ It will then execute this code on your local computer and return the result to you.

The problem occurs where operating systems of course have some kind of built-in security. Generally, the Execution Policy on your OS will prevent AutoGen (and others) from just running random code and scripts on your computer. And this is a good thing! One solution would be to loosen up the Execution Policy on your computer, but this is not really the best idea. Even if you don’t have an Execution Policy problem on your system, do you really want to have any and all AI-generated code running on your machine without any checks or balances? It’s a bit dangerous, to say the least.

Why we won’t use Anaconda

Many tutorials try to take the 100% no-code approach, using Anaconda for virtual environments and not using an IDE like VS Code altogether in an attempt to claim that ‘You don’t need to know any code at all’. Then you will:

  • Still have to install Docker as well as Anaconda, in order to allow safe code execution inside of a Docker container.
  • Set your API key over and over every time you reload.
  • Type the same Anaconda commands over and over.
  • You might be stuck with a buggy experience trying to get it to use Docker for safe code execution, causing you a lot of frustration.

While there is absolutely nothing wrong with Anaconda, it doesn’t remove the need for Docker for safe code execution as it doesn’t provide any isolation from your local system. So why don’t we just use Docker instead of Anaconda AND Docker? This biting the bullet will make this part 1 of the tutorial a bit harder, but after that, it will be smooth sailing all the way! โ›ต

Docker to the rescue

Using this approach we can skip Anaconda altogether as Docker will also be separate from our system-wide Python environment, and we have only 1 piece of software to worry about for both the separate environment and the safe code execution. We will use some bare basic code in the form of a ‘docker file’ and basic commands, but you can just copy mine, so no worries! Again, if you’re already a Docker expert, feel free to just skip ahead to the Dockerfile and get started.

Docker uses operating system-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files. All containers are run by a single operating system kernel and are thus more lightweight than virtual machines. Crudely stated this means that docker will let us have a separate container with Linux, Python, and all the libraries we need to run AutoGen Studio in it, kind of like running a different computer system within a virtual machine.

We will use this ‘virtual machine’, or Docker container, to run AutoGen Studio inside of it, which automatically also means that any code it generates is executed within the container, solving our code execution policy problems and safety concerns in one go. Caveat: Theoretically even Docker is not 100% secure and isolated from the rest of your system, but it’s a lot better than just running code directly on your local machine and good enough for non-enterprise use.

Getting Docker installed and running – WSL2

I’m going to assume you’re on a Windows machine. If you’re on a Mac or Linux machine, you’re in luck and can probably just run the installer for ‘Docker Desktop’ and be done with it. Just head over here and scroll down to select the Docker download for your platform. https://docs.docker.com/desktop/ (or Google for the updated link).

Continuing for the Windows users now, as they have a couple of extra steps to take. Most tutorials will just tell you to install Docker and give no details which might leave you will a hard and long process of figuring out why it won’t work on your system. So let’s cover the pitfalls and make sure we get it right the first time!

First, we need to install WSL2 (Windows Subsystem for Linux 2) on our system. This is a Windows feature that allows us to run Linux on our Windows machine. This is needed because Docker Desktop for Windows requires WSL2 to run. (You can also use Hyper-Vinstead, but WSL2 is the recommended way).

(If you already use WSL but need to check if you have version 2, you can check your version by entering the command: wsl -l -v in PowerShell or Windows Command Prompt.)

You can find the details for installing WSL2 here, but basically you do this:

  • Open a PowerShell or Windows Command Prompt in administrator mode by right-clicking and selecting “Run as administrator”
  • Run the following command in the terminal: wsl --install
  • Restart your computer when prompted

This will enable WSL on your Windows machine and install a Linux distribution (Ubuntu) on your system. You may need to create a Username and Password for your Linux distribution and save them somewhere. More details can be found here or google "Setting up your Linux username and password."

Some things to check before we install Docker Desktop

A quick caveat: If anywhere along the way you run into problems I haven’t covered here, you’ll need to do some googling to find out what it means and what needs to be done, as I cannot prepare you for every possible problem you might run into.

The software development world sometimes requires messing around and googling for an hour or even two before you get something to work, it’s part of the game. That being said I will try my best to cover all bases so you’ll hopefully have a very smooth experience ๐Ÿ˜€.

We have a couple more things to check before we can install Docker Desktop. First, we need to make sure the Virtual Machine Platform option is enabled. This is fairly easy! Just press the Windows key or click in the Windows search bar and search for “Turn Windows features on or off”.

Open this and make sure the “Virtual Machine Platform” option is checked. If it’s not, check it and click OK. You may need to restart your computer after this.

(You don’t have to match the other checkboxes with the settings in the image!)

Next, we need to make sure that Virtualization is enabled in our BIOS. The easiest way to check if this is enabled is to open the Windows Task Manager by pressing Ctrl+Alt+Delete and selecting Task Manager. Then click on the Performance tab and click on CPU on the left-hand side. If Virtualization is enabled, you will see “Virtualization: Enabled” in the bottom right information block like this:

If Virtualization is not enabled, you will have to go into your BIOS settings and enable Virtualization. This is where you will have to do some googling and research on your own, as every system has slightly different keys to get into the BIOS setup menu, and the settings may be located in different parts of the BIOS menu for different manufacturers. I’ll leave you with two links to get you started, the first one describes the general process of getting this setting enabled in your BIOS:

When you’ve got that ready and set up to go, let’s continue on.

Installing Docker Desktop ๐Ÿš€

Finally, it’s time! Head over to the Docker Desktop download page here and download the appropriate Docker version for your OS. I’m running Docker 4.26.1, but just download the latest version and you should be fine. When the download finishes start the installer. The installer will give you the following options:

Just accept both of these options and click OK, unless you chose not to install WSL 2 and use Hyper-V instead. Whether or not you want a shortcut on your desktop is entirely up to you of course ๐Ÿ˜‰.

Now just let the installer do its magic:

Done!

Then go ahead and run the Docker Desktop application, where you’ll have to accept the service agreement:

And then just choose “Use recommended settings” and click Finish:

Now Docker Desktop will start and you will be prompted to either sign up or sign in. Docker is free for personal and even small-business use, so press the button to sign up and create an account. You can even use your Google or GitHub account to create one really fast. (You can also continue without signing in if you want to, and it should still work fine). I’m just going to go ahead and sign in with my Google account.

If everything was successful, you should be greeted by the following screen:

Congratulations! You’ve now installed Docker Desktop and are ready to go! If you still have problems, first try the below, and if that doesn’t work, google will have a solution. Never despair!

(Only for those who still have problems ๐Ÿ™ˆ๐Ÿ™‚)

- Hypervisor enabled at Windows startup -
If you have completed the steps described above and are still experiencing Docker Desktop startup issues, this could be because the Hypervisor is installed, but not launched during Windows startup. Some tools (such as older versions of Virtual Box) and video game installers turn off hypervisor on boot. To turn it back on:

    - Open an administrative console prompt.
    - Run bcdedit /set hypervisorlaunchtype auto.
    - Restart Windows.

Creating a Dockerfile

Ok, now that we all have Docker Desktop installed and running, let’s move on to the next step! I’ll be using VS Code for this, just because it feels convenient to me. You can also use any other code editor or literally just copy the text into Notepad and use a separate terminal window, it makes no difference.

Create a base project directory and open it in VS Code. I’ll simply call my directory AUTOGEN:

๐Ÿ“AUTOGEN (root project folder)

Now inside the AUTOGEN folder create a new file called Dockerfile.base: