AutoGen Quickstart 🤖 Build POWERFUL AI Applications in MINUTES

Leon van Zyl
2 Nov 202313:18

Summary

TLDRThis video tutorial introduces Autogen, an open-source framework by Microsoft for creating AI applications with multiple agents. It guides viewers through setting up Autogen locally, including installing Python 3.8, creating an OpenAI API key, and using a code editor like VS Code. The process involves creating a virtual environment, installing the Autogen package, and configuring AI models and API keys. The tutorial demonstrates creating a user proxy agent for interaction and an assistant agent for tasks, culminating in a demo where the agents collaborate to plot stock price changes for Nvidia and Tesla, showcasing Autogen's potential for complex problem-solving.

Takeaways

  • 🌐 Autogen is an open-source framework by Microsoft for creating AI applications with multiple agents.
  • 💻 To set up Autogen locally, you need Python 3.8 or higher, an OpenAI API key, and a code editor like VS Code.
  • 🛠️ It's recommended to create a virtual environment for Autogen to manage dependencies specific to the project.
  • 🔑 The OpenAI API key is stored in a file named 'oaioreconfig.json' in the project's root folder.
  • 📝 The 'oaioreconfig.json' file specifies AI models available to the application, with 'GPT-4' used as an example.
  • 🤖 Autogen applications require at least one user proxy agent for user interaction and one assistant agent to perform tasks.
  • 💬 The user proxy agent serves as a middleman, receiving user input and directing it to other agents, and can execute code.
  • 🔧 In the demo, the 'coder' assistant agent is tasked with generating code to plot stock price changes for Nvidia and Tesla.
  • 📊 The coder agent proposes using Python libraries to generate the required code, which is then executed by the user proxy agent.
  • 🔄 The process involves iterative communication between agents, with opportunities for user feedback or termination of the session.

Q & A

  • What is Autogen and who created it?

    -Autogen is an open-source framework created by Microsoft that simplifies the creation of AI applications using multiple agents.

  • How does Autogen facilitate problem-solving?

    -Autogen allows adding agents to a chat room where they collaborate to solve complex problems, either with or without user input, by assigning unique roles to the agents.

  • What are the minimum requirements to set up Autogen locally?

    -To set up Autogen locally, you need Python 3.8 or greater, an OpenAI API key, and a code editor like VS Code.

  • Why is it recommended to create a virtual environment before installing Autogen?

    -Creating a virtual environment ensures that all dependencies are installed only for the project and not globally on the machine, avoiding conflicts.

  • How do you create a virtual environment for Autogen in VS Code?

    -In the integrated terminal of VS Code, you type 'python -m venv .venv' on Mac or Linux, then activate it by running '.venv/bin/activate'.

  • What is the purpose of the 'oaoreconfig.json' file in an Autogen project?

    -The 'oaoreconfig.json' file is used to store a list of AI models that will be made available to the application, along with their API keys.

  • What is a user proxy agent in the context of Autogen?

    -A user proxy agent is a middleman between the user and other agents, receiving user input and passing it to the agents, and possibly asking for additional feedback based on agent responses.

  • How does the user proxy agent execute code on behalf of the user?

    -The user proxy agent receives coding instructions from the user, hands them over to an assistant agent to generate the code, and then executes the code in a designated folder.

  • What is the role of the 'initiate chat' method in Autogen applications?

    -The 'initiate chat' method is used to start a conversation with the application, specifying the recipient (an assistant agent) and the message containing the task instruction.

  • What happens if the user proxy agent encounters an error during code execution?

    -If an error occurs, such as a missing module, the assistant agent will inform the user proxy agent and suggest the necessary dependencies to install to proceed.

  • How can users provide feedback or make changes to the solution in an Autogen application?

    -Users can provide feedback or request changes by typing new instructions, which the user proxy agent passes to the assistant agent for adjustments.

Outlines

00:00

💻 Setting Up Autogen for AI Applications

The video introduces Autogen, an open-source framework by Microsoft, designed to simplify the creation of AI applications using multiple agents. It allows users to integrate agents into a chat room to collaboratively solve complex problems, either autonomously or with user input. The setup process involves installing Python 3.8 or higher, creating an OpenAI API key, and using a code editor like VS Code. The tutorial guides viewers through creating a virtual environment, installing the Autogen package, and storing the API key in a project file. It also covers the creation of a configuration file for AI models and the fundamental concepts of user proxy and assistant agents in Autogen applications.

05:00

👨‍💻 Creating User Proxy and Assistant Agents

This segment of the video script details the creation of a user proxy agent and an assistant agent named 'coder' within the Autogen framework. The user proxy agent serves as an intermediary between the user and other agents, capable of executing code on the user's behalf. The assistant agent, in this case, is tasked with generating code. The video demonstrates how to import these agents, set their attributes, and specify the AI models they can access. It also explains how to set up the environment for code execution and how the agents interact to fulfill a user's request to plot a chart of stock price changes.

10:02

📈 Testing the Autogen Application and Iterating on Agent Responses

The final paragraph of the script describes the process of testing the Autogen application. It outlines how the user proxy agent communicates with the assistant agent to execute a task, such as plotting a stock price chart. The video shows the interaction between agents, the user's opportunity to provide feedback or terminate the session, and the handling of errors like missing dependencies. It also demonstrates how to install necessary modules and rerun the code successfully. The script concludes with a user request to modify the task, which the assistant agent accommodates, and a teaser for the next video, which will explore adding multiple agents to create an AI workforce.

Mindmap

Keywords

💡Autogen

Autogen is an open-source framework developed by Microsoft that simplifies the creation of AI applications using multiple agents. It allows for the addition of agents to a chat room where they collaborate to solve complex problems, either with or without user input. In the video, Autogen is the central theme, as the tutorial demonstrates how to set it up locally and create the first application using this framework.

💡Agents

In the context of Autogen, agents are the individual components that perform specific tasks within the AI application. They can be assigned unique roles and work together to achieve a common goal. The video explains how to set up agents like the user proxy agent and assistant agents, which are crucial for creating a digital workforce.

💡User Proxy Agent

The user proxy agent in Autogen serves as an intermediary between the user and other agents within the application. It receives user input and passes it along to the appropriate agents. The video script provides an example of creating a user proxy agent named 'user proxy', which is set to execute code on behalf of the user.

💡Assistant Agent

Assistant agents in Autogen are designed to perform tasks such as generating code or processing data. In the script, an assistant agent named 'coder' is created to write code for visualizing stock price changes. This demonstrates how assistant agents can be specialized for different functions within an AI application.

💡Open AI API Key

An Open AI API key is a unique identifier required to access OpenAI's services, such as their AI models. In the video, the script instructs viewers to create an Open AI API key and store it in a configuration file within the project. This key is essential for integrating Autogen with AI models like GPT-4.

💡Virtual Environment

A virtual environment in Python is a self-contained directory tree that includes a Python installation for a particular version of Python, plus a number of additional packages. The video script recommends creating a virtual environment for the Autogen project to manage dependencies and avoid conflicts with system-wide packages.

💡Dependencies

Dependencies in the context of the video refer to external libraries or packages that the Autogen application needs to function correctly. The script mentions installing dependencies like 'why Finance' for the coder agent to execute the stock price visualization code successfully.

💡Code Execution

Code execution in the video refers to the process where the user proxy agent runs the code generated by the assistant agent. The script illustrates a scenario where the user proxy agent attempts to execute the code but encounters a failure due to missing dependencies, which are then installed to enable successful execution.

💡Digital Workforce

The term 'digital workforce' is used in the video to describe a collection of AI agents working together to perform tasks. The video outlines the process of setting up Autogen to create a digital workforce by adding multiple agents, each with a specific role, to solve complex problems.

💡Configuration File

A configuration file in the video is a text file that stores settings for the Autogen application, such as the list of AI models and their corresponding API keys. The script guides viewers through creating a 'oaore config uncore list' file where the model 'GPT-4' and its API key are specified.

Highlights

Autogen is an open-source framework by Microsoft for creating AI applications with multiple agents.

Agents in Autogen can solve complex problems with or without user input by assuming unique roles.

Setting up Autogen locally requires Python 3.8 or greater, an OpenAI API key, and a code editor like VS Code.

Creating a virtual environment for Autogen installation is recommended to manage dependencies.

Autogen can be installed using pip by typing 'pip install py autogen'.

An OpenAI API key should be stored in a project file named 'oaioreconfig.json' for secure access.

The 'oaioreconfig.json' file specifies AI models available to the application.

Autogen applications require at least one user proxy agent for user interaction.

User proxy agents can execute code on behalf of the user, facilitating tasks like writing code.

Assistant agents in Autogen perform tasks assigned by the user proxy agent, such as generating code.

The 'initiate chat' method allows the user proxy agent to interact with assistant agents.

Autogen applications can dynamically adjust solutions based on user feedback during interactions.

Dependencies for code execution generated by Autogen can be installed using provided instructions.

Autogen allows for the execution of generated code, showcasing its capability to perform practical tasks.

The coder agent in Autogen can modify its solution based on user requests, like plotting percentage changes.

Autogen supports the creation of a digital workforce by integrating multiple agents with distinct roles.

Future videos will explore adding multiple agents to Autogen applications for complex problem-solving.

Transcripts

play00:00

autogen is an open- Source framework

play00:02

created by Microsoft that simplifies the

play00:04

creation of AI applications using

play00:07

multiple agents basically autogen allows

play00:10

you to add agents to a chat room where

play00:12

they will then work together to solve

play00:15

complex problems this can be done with

play00:18

or without the user's input by assigning

play00:21

unique roles to the agents you can

play00:23

easily create your very own digital

play00:25

Workforce in this video we will set up

play00:28

autogen locally and you will learn the

play00:31

fundamentals of creating your very first

play00:33

autogen applications setting up autogen

play00:37

locally is quite straightforward all you

play00:39

need is to install python 3.8 or greater

play00:42

you also need to create an open AI API

play00:45

key and you will need a code editor like

play00:48

vs code open up a new folder in VSS code

play00:52

and then open the integrated terminal by

play00:55

clicking on Terminal and then new

play00:58

terminal before installing the autogen

play01:00

package it is recommended to First

play01:03

create a virtual environment this will

play01:05

ensure that all dependencies are

play01:07

installed for this project only and not

play01:10

globally on our machines creating a

play01:13

virtual environment is quite easy simply

play01:15

type python if you're using Mac or Linux

play01:19

type Python 3 followed by dasm then

play01:25

VV space

play01:28

VV again press enter this will now

play01:31

create this VV folder in order to

play01:34

activate our virtual environment we can

play01:37

simply type V EnV tab scripts and within

play01:43

scripts activate and then press enter if

play01:46

everything was done correctly you should

play01:48

see the virtual environment name at the

play01:50

start of this command we can now go

play01:53

ahead and install autogen by typing pep

play01:57

install py autogen gen and this will now

play02:01

install the auto genen package we are

play02:03

nearly done with the setup there's only

play02:05

one more step now we need to store our

play02:09

open AI API key somewhere in the project

play02:12

so after copying your open AI API key go

play02:16

back to the project and in the root

play02:18

folder create a new file and call it o

play02:23

aore config uncore list in this file we

play02:27

will specify a list of AI models that we

play02:31

will make available to our application

play02:34

in this example we will only make use of

play02:36

one model but if you want you can add

play02:38

multiple models to this list to add a

play02:41

model we will create a dictionary using

play02:45

curly braces and this dictionary will

play02:47

accept two key value pairs the first

play02:51

value is model followed by a value which

play02:55

is the name of the model that we'd like

play02:57

to use in our example that model will be

play03:01

GPT 4 if you want you can also replace

play03:04

this with something like GPT 3.5 turbo

play03:08

but for this example I will use GPT 4 as

play03:11

this will provide better results the

play03:14

second value is API key with the value

play03:18

of the open AI API key if you want you

play03:22

can add additional models to this list

play03:25

simply by typing comma and then adding

play03:27

another dictionary but we will only use

play03:30

one model this is all the setup we need

play03:33

to create our autogen application let's

play03:36

close this file and then in the root of

play03:38

this folder let's create our first demo

play03:41

let's create a new file and let's call

play03:43

it demo 1. piy the first thing we need

play03:46

to do is to pull in this list of AI

play03:50

models into our application to do that

play03:53

we'll type the following from Auto Jen

play03:56

import config list and in the auto

play03:59

complete we can see the different

play04:01

functions that are available for

play04:03

importing this config we will use the

play04:05

fromjson function then we will create a

play04:08

new variable called config list which we

play04:12

will set equal to the config list from

play04:15

Json function and this function takes an

play04:18

argument called EnV or file which we

play04:22

will set equal to the name of our config

play04:25

list file which was O aior config uncore

play04:30

list now in order to create autogen

play04:33

applications we need at least the

play04:36

following first we need a user proxy

play04:39

agent and then second we need at least

play04:42

one assistant agent let me explain what

play04:45

these are the user proxy agent allows us

play04:49

the users to interact with our

play04:52

application this agent is sort of the

play04:54

middleman between the user and the

play04:57

agents and it plays quite an important

play05:00

role the user proxy agent will receive

play05:03

input from the user and then pass that

play05:05

input to the agents and depending on the

play05:08

responses from the agents this proxy

play05:11

agent might ask the user for additional

play05:14

feedback another important note about

play05:16

proxy agents is that they are able to

play05:19

execute code on the user's behalf so

play05:22

let's go ahead and create this proxy

play05:24

agent from autogen we will now also

play05:27

import the user proxy agent agent and

play05:30

now we can create a new variable called

play05:33

user proxy but you are welcome to call

play05:35

this whatever you want we will set this

play05:38

equal to the user proxy agent class and

play05:41

this class takes in a couple of

play05:43

attributes the first one being the name

play05:46

of this agent which will call user proxy

play05:50

but you are welcome to call this agent

play05:52

whatever you want then we will specify

play05:55

another attribute called code uncore

play05:58

execution underscore config and this

play06:01

argument takes a dictionary as input

play06:04

with a key value of work uncore dur

play06:08

which we can give any value that we want

play06:10

I'll just call it coding as I mentioned

play06:13

earlier these user proxy agents are able

play06:16

to execute code on the user's behalf so

play06:19

in this demo we'll actually ask our

play06:21

agent to write code for us and the proxy

play06:24

agent will hand that coding instruction

play06:27

over to an assistant agent which will

play06:29

then generate the code that code will

play06:32

then be saved in a folder called coding

play06:34

and the user proxy agent will then

play06:37

execute the code in that coding folder

play06:39

so with that said let's go ahead and

play06:41

create our coding agent we can do that

play06:44

by creating an assistant agent so from

play06:47

autogen let's also import an assistant

play06:50

agent then under assistant agent let's

play06:52

create a new variable called coder you

play06:55

are welcome to call this whatever you

play06:57

want if this was a tester or a document

play07:00

writer or a project manager you will

play07:02

call this variable whatever you want we

play07:05

can set this equal to the assistant

play07:08

agent class which also takes a couple of

play07:10

attributes like the name of the agent

play07:13

which will simply call coder for these

play07:16

assistant agents we need to specify the

play07:19

llm models that it has access to so as a

play07:22

second argument we need to specify the

play07:25

llm config argument which will set equal

play07:28

to a dictionary with a key value of

play07:33

config list with a value of the config

play07:36

list variable that we created up here so

play07:39

now we have an assistant with a name

play07:41

coder which has access to the models

play07:44

specified in this file we will look at

play07:47

this later in this video but you are

play07:49

also able to specify other attributes

play07:52

like the system message which you can

play07:54

use to Prime this agent but we will have

play07:57

a look at that a bit later one in

play07:59

announcement I do recommend you do is to

play08:02

remove this dictionary and instead

play08:05

create a new variable called llm config

play08:09

which is equal to that dictionary so

play08:12

when we create a new agent we simply

play08:15

pass in the llm config variable and this

play08:18

makes sense for autogen applications

play08:21

since the whole purpose of using autogen

play08:24

is to have multiple assistant agents in

play08:27

your application and the just simplif

play08:29

things if you can reuse the same

play08:31

variable so now that we have a proxy

play08:33

agent that we as the users can interact

play08:36

with and we have one assistant agent

play08:39

that will perform a task we can now

play08:42

finally test out our application in

play08:44

order to chat with our application we

play08:47

can call user proxy and on user proxy

play08:50

there's a method called initiate chat

play08:54

the initiate chat method takes in an

play08:56

argument of recipient and recipient is

play09:00

this assistant agent that it needs to

play09:02

interact with so let's simply add coder

play09:05

to this argument so now that the proxy

play09:07

agent knows which agent it's talking to

play09:10

we now need to tell it what the message

play09:13

is by specifying an argument called

play09:16

message and the string value containing

play09:19

our task instruction let's go with this

play09:21

example where we say Plott a chart of

play09:24

Nvidia and Tesla's stock price change

play09:27

year to date let's say this file and

play09:30

then in the terminal let's just expand

play09:33

this a bit so in the terminal we can go

play09:35

ahead and run this file by typing py

play09:39

demo 1. py in the terminal we can see a

play09:43

few important things first you will

play09:45

notice this message is from the user

play09:47

proxy and in Brackets it's saying which

play09:51

agent it's talking to and in this

play09:53

example it's talking to the coder agent

play09:56

and it's passing our instruction to the

play09:59

the coder agent after a few seconds we

play10:01

can now see a message from the coder

play10:04

agent and it is passing the message to

play10:06

the user proxy and this is the message

play10:09

from the coder basically it's saying

play10:11

that it will use these python libraries

play10:14

to write the code to visualize this

play10:16

output and we can also see the code that

play10:19

it's written also at the bottom of the

play10:21

terminal we now have an opportunity to

play10:24

change the solution or to provide

play10:27

feedback or we can type X it to just

play10:30

terminate this session alternatively we

play10:32

can just press enter and that will allow

play10:34

the agents to continue by themselves so

play10:37

after pressing enter we can see this

play10:40

message saying that no human input was

play10:43

received and therefore the agents just

play10:45

kept going the user proxy agent tried to

play10:48

execute the code generated by the coder

play10:50

agent we can also see that the user

play10:53

proxy agent tried to execute the code

play10:56

but the execution of the code failed and

play10:58

the reason reason for the failure was no

play11:01

module named why Finance so the coder

play11:04

then replied back to user proxy saying

play11:07

that in order for this code to work we

play11:09

need to install a couple of dependencies

play11:11

and it also tells us how to install

play11:14

those dependencies so let's do that we

play11:16

can simply copy this code I'll open up a

play11:19

new terminal I'll paste in that code and

play11:22

just run this after installing these

play11:24

dependencies I'll just go back to this

play11:27

terminal and let's let just press enter

play11:30

so now the user proxy is telling the

play11:32

coder that those packages have already

play11:34

been installed because we just installed

play11:37

them ourselves and we can now see the

play11:39

coder responding to the user proxy

play11:41

saying great now that you have these

play11:43

modules installed we can now proceed to

play11:46

execute this code and it's giving us the

play11:48

code again so what I'll do now is just

play11:51

press enter and the user proxy agent

play11:54

just executed that code and now we can

play11:56

see this graph being returned what we

play11:59

can also see in our project folder is

play12:02

that within the coding folder we can see

play12:04

the code that was generated by the coder

play12:07

agent and if we expand this we can see

play12:09

all the code and this is the code that

play12:12

our user proxy agent executed after

play12:14

closing the popup we can see the user

play12:16

proxy telling the coder that the

play12:18

execution was successful and we can see

play12:21

the coder respond back to the user proxy

play12:24

saying it's glad the code execution was

play12:26

successful and now we have another

play12:28

opportunity to make changes to the

play12:30

solution or to terminate the session

play12:33

let's try making a simple change let's

play12:35

type something like plot the percentage

play12:38

change instead we can see the user proxy

play12:41

agent passing our instruction back to

play12:43

the coder the coder is now politely

play12:45

apologizing to the user proxy agent and

play12:48

it's explaining the changes that it will

play12:50

make to the solution let just press

play12:52

enter and now we are seeing a different

play12:54

graph for the percentage change in the

play12:57

stock price for in video and Tesla in

play13:00

the next video we will have a look at

play13:02

adding multiple agents to our

play13:05

application in order to create our very

play13:07

own AI Workforce if you enjoyed this

play13:10

video please hit the like button and

play13:12

consider subscribing to my channel I'll

play13:15

see you in the next one bye-bye

Rate This

5.0 / 5 (0 votes)

Related Tags
Autogen FrameworkAI ApplicationsMicrosoft TechMulti-agent SystemChat Room AIDigital WorkforcePython DevelopmentAPI IntegrationCode ExecutionAI Collaboration