├── .devcontainer └── .devcontainer.json ├── .env.template ├── .gitignore ├── 01_agents_and_conversation ├── README.md └── main.py ├── 02_agents_with_tools └── README.md ├── 03_agents_that_learn ├── README.md ├── comedian_assistant_experience │ └── readme.md └── main.py ├── 04_travel_agency_front_office └── README.md ├── 05_travel_agency_with_front_and_back_office ├── README.md ├── customer_assistant_experience │ └── readme.md ├── main.py ├── tools │ └── travel_tools.py └── trip_assistant_experience │ └── readme.md ├── 06_travel_agency_with_solver └── README.md ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── docs ├── autogen.md ├── components.md └── domain_driven_design.md └── requirements.txt /.devcontainer/.devcontainer.json: -------------------------------------------------------------------------------- 1 | // Adopting the default GitHub codespaces-jupyter template as starter 2 | // https://github.com/github/codespaces-jupyter 3 | { 4 | "name": "AgenticCookBook", 5 | "image": "mcr.microsoft.com/devcontainers/universal:2", 6 | "hostRequirements": { 7 | "cpus": 4 8 | }, 9 | "waitFor": "onCreateCommand", 10 | "updateContentCommand": "python3 -m pip install -r requirements.txt", 11 | "postCreateCommand": "bash .devcontainer/post-create.sh", 12 | "customizations": { 13 | "codespaces": { 14 | "openFiles": [] 15 | }, 16 | "vscode": { 17 | "extensions": [ 18 | "ms-python.python", 19 | "ms-toolsai.jupyter" 20 | ], 21 | "postCreateCommand": "pip3 --disable-pip-version-check --no-cache-dir install -r requirements.txt" 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /.env.template: -------------------------------------------------------------------------------- 1 | # Open AI details 2 | AZURE_OPENAI_MODEL="gpt-4-32k" 3 | AZURE_OPENAI_EMBEDDING_MODEL="text-embedding-ada-002" 4 | AZURE_OPENAI_KEY="" 5 | AZURE_OPENAI_ENDPOINT="" 6 | AZURE_OPENAI_API_VERSION="2024-02-01" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Visual C++ cache files 114 | ipch/ 115 | *.aps 116 | *.ncb 117 | *.opendb 118 | *.opensdf 119 | *.sdf 120 | *.cachefile 121 | *.VC.db 122 | *.VC.VC.opendb 123 | 124 | # Visual Studio profiler 125 | *.psess 126 | *.vsp 127 | *.vspx 128 | *.sap 129 | 130 | # Visual Studio Trace Files 131 | *.e2e 132 | 133 | # TFS 2012 Local Workspace 134 | $tf/ 135 | 136 | # Guidance Automation Toolkit 137 | *.gpState 138 | 139 | # ReSharper is a .NET coding add-in 140 | _ReSharper*/ 141 | *.[Rr]e[Ss]harper 142 | *.DotSettings.user 143 | 144 | # TeamCity is a build add-in 145 | _TeamCity* 146 | 147 | # DotCover is a Code Coverage Tool 148 | *.dotCover 149 | 150 | # AxoCover is a Code Coverage Tool 151 | .axoCover/* 152 | !.axoCover/settings.json 153 | 154 | # Coverlet is a free, cross platform Code Coverage Tool 155 | coverage*.json 156 | coverage*.xml 157 | coverage*.info 158 | 159 | # Visual Studio code coverage results 160 | *.coverage 161 | *.coveragexml 162 | 163 | # NCrunch 164 | _NCrunch_* 165 | .*crunch*.local.xml 166 | nCrunchTemp_* 167 | 168 | # MightyMoose 169 | *.mm.* 170 | AutoTest.Net/ 171 | 172 | # Web workbench (sass) 173 | .sass-cache/ 174 | 175 | # Installshield output folder 176 | [Ee]xpress/ 177 | 178 | # DocProject is a documentation generator add-in 179 | DocProject/buildhelp/ 180 | DocProject/Help/*.HxT 181 | DocProject/Help/*.HxC 182 | DocProject/Help/*.hhc 183 | DocProject/Help/*.hhk 184 | DocProject/Help/*.hhp 185 | DocProject/Help/Html2 186 | DocProject/Help/html 187 | 188 | # Click-Once directory 189 | publish/ 190 | 191 | # Publish Web Output 192 | *.[Pp]ublish.xml 193 | *.azurePubxml 194 | # Note: Comment the next line if you want to checkin your web deploy settings, 195 | # but database connection strings (with potential passwords) will be unencrypted 196 | *.pubxml 197 | *.publishproj 198 | 199 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 200 | # checkin your Azure Web App publish settings, but sensitive information contained 201 | # in these scripts will be unencrypted 202 | PublishScripts/ 203 | 204 | # NuGet Packages 205 | *.nupkg 206 | # NuGet Symbol Packages 207 | *.snupkg 208 | # The packages folder can be ignored because of Package Restore 209 | **/[Pp]ackages/* 210 | # except build/, which is used as an MSBuild target. 211 | !**/[Pp]ackages/build/ 212 | # Uncomment if necessary however generally it will be regenerated when needed 213 | #!**/[Pp]ackages/repositories.config 214 | # NuGet v3's project.json files produces more ignorable files 215 | *.nuget.props 216 | *.nuget.targets 217 | 218 | # Microsoft Azure Build Output 219 | csx/ 220 | *.build.csdef 221 | 222 | # Microsoft Azure Emulator 223 | ecf/ 224 | rcf/ 225 | 226 | # Windows Store app package directories and files 227 | AppPackages/ 228 | BundleArtifacts/ 229 | Package.StoreAssociation.xml 230 | _pkginfo.txt 231 | *.appx 232 | *.appxbundle 233 | *.appxupload 234 | 235 | # Visual Studio cache files 236 | # files ending in .cache can be ignored 237 | *.[Cc]ache 238 | # but keep track of directories ending in .cache 239 | !?*.[Cc]ache/ 240 | 241 | # Others 242 | ClientBin/ 243 | ~$* 244 | *~ 245 | *.dbmdl 246 | *.dbproj.schemaview 247 | *.jfm 248 | *.pfx 249 | *.publishsettings 250 | orleans.codegen.cs 251 | 252 | # Including strong name files can present a security risk 253 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 254 | #*.snk 255 | 256 | # Since there are multiple workflows, uncomment next line to ignore bower_components 257 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 258 | #bower_components/ 259 | 260 | # RIA/Silverlight projects 261 | Generated_Code/ 262 | 263 | # Backup & report files from converting an old project file 264 | # to a newer Visual Studio version. Backup files are not needed, 265 | # because we have git ;-) 266 | _UpgradeReport_Files/ 267 | Backup*/ 268 | UpgradeLog*.XML 269 | UpgradeLog*.htm 270 | ServiceFabricBackup/ 271 | *.rptproj.bak 272 | 273 | # SQL Server files 274 | *.mdf 275 | *.ldf 276 | *.ndf 277 | 278 | # Business Intelligence projects 279 | *.rdl.data 280 | *.bim.layout 281 | *.bim_*.settings 282 | *.rptproj.rsuser 283 | *- [Bb]ackup.rdl 284 | *- [Bb]ackup ([0-9]).rdl 285 | *- [Bb]ackup ([0-9][0-9]).rdl 286 | 287 | # Microsoft Fakes 288 | FakesAssemblies/ 289 | 290 | # GhostDoc plugin setting file 291 | *.GhostDoc.xml 292 | 293 | # Node.js Tools for Visual Studio 294 | .ntvs_analysis.dat 295 | node_modules/ 296 | 297 | # Visual Studio 6 build log 298 | *.plg 299 | 300 | # Visual Studio 6 workspace options file 301 | *.opt 302 | 303 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 304 | *.vbw 305 | 306 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 307 | *.vbp 308 | 309 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 310 | *.dsw 311 | *.dsp 312 | 313 | # Visual Studio 6 technical files 314 | *.ncb 315 | *.aps 316 | 317 | # Visual Studio LightSwitch build output 318 | **/*.HTMLClient/GeneratedArtifacts 319 | **/*.DesktopClient/GeneratedArtifacts 320 | **/*.DesktopClient/ModelManifest.xml 321 | **/*.Server/GeneratedArtifacts 322 | **/*.Server/ModelManifest.xml 323 | _Pvt_Extensions 324 | 325 | # Paket dependency manager 326 | .paket/paket.exe 327 | paket-files/ 328 | 329 | # FAKE - F# Make 330 | .fake/ 331 | 332 | # CodeRush personal settings 333 | .cr/personal 334 | 335 | # Python Tools for Visual Studio (PTVS) 336 | __pycache__/ 337 | *.pyc 338 | 339 | # Cake - Uncomment if you are using it 340 | # tools/** 341 | # !tools/packages.config 342 | 343 | # Tabs Studio 344 | *.tss 345 | 346 | # Telerik's JustMock configuration file 347 | *.jmconfig 348 | 349 | # BizTalk build output 350 | *.btp.cs 351 | *.btm.cs 352 | *.odx.cs 353 | *.xsd.cs 354 | 355 | # OpenCover UI analysis results 356 | OpenCover/ 357 | 358 | # Azure Stream Analytics local run output 359 | ASALocalRun/ 360 | 361 | # MSBuild Binary and Structured Log 362 | *.binlog 363 | 364 | # NVidia Nsight GPU debugger configuration file 365 | *.nvuser 366 | 367 | # MFractors (Xamarin productivity tool) working folder 368 | .mfractor/ 369 | 370 | # Local History for Visual Studio 371 | .localhistory/ 372 | 373 | # Visual Studio History (VSHistory) files 374 | .vshistory/ 375 | 376 | # BeatPulse healthcheck temp database 377 | healthchecksdb 378 | 379 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 380 | MigrationBackup/ 381 | 382 | # Ionide (cross platform F# VS Code tools) working folder 383 | .ionide/ 384 | 385 | # Fody - auto-generated XML schema 386 | FodyWeavers.xsd 387 | 388 | # VS Code files for those working on multiple tools 389 | .vscode/* 390 | !.vscode/settings.json 391 | !.vscode/tasks.json 392 | !.vscode/launch.json 393 | !.vscode/extensions.json 394 | *.code-workspace 395 | 396 | # Local History for Visual Studio Code 397 | .history/ 398 | 399 | # Windows Installer files from build outputs 400 | *.cab 401 | *.msi 402 | *.msix 403 | *.msm 404 | *.msp 405 | 406 | # JetBrains Rider 407 | *.sln.iml 408 | 409 | autogen/travel agency/logs.db 410 | 411 | logs.db 412 | 413 | *.sqlite3 414 | 415 | *.pkl 416 | *.bin 417 | -------------------------------------------------------------------------------- /01_agents_and_conversation/README.md: -------------------------------------------------------------------------------- 1 | # Tell me a joke 2 | 3 | The sample in [main.py](main.py) defines two agents: 4 | * comedian 5 | * user_proxy 6 | 7 | The `comedian` is configured to respond with jokes back to the user. 8 | 9 | The chat is then initiate with an request for a joke with cats and ninjas from teh user, from that the `user_proxy` will have oppotunities to ask for more or terminate the session. 10 | 11 | This code is a Python script that imports two classes, `AssistantAgent` and `UserProxyAgent`, from a module called `autogen`. It also imports the `os` module. 12 | 13 | The code defines a list called `config_list`which contains a dictionary with configuration information for an agent. The dictionary includes values for the model, API key, API type, base URL, and API version. These values are retrieved from environment variables using the `os.environ.get()' function. 14 | 15 | Next, an instance of the `AssistantAgent` class is created and assigned to the variable `comedian`. The `AssistantAgent` constructor is called with several arguments including the agent's name, system message, description, and a configuration list. The configuration list is passed as a keyword argument with the key `llm_config`. 16 | 17 | Then, an instance of the `UserProxyAgent` class is created and assigned to the variable `user_proxy`. The `UserProxyAgent` constructor is called with the agent's name and a code execution configuration dictionary. The code execution configuration includes a working directory and a flag indicating whether to use Docker. 18 | 19 | Finally, the `initiate_chat()` method is called on the `user_proxy` instance. This method takes two arguments: the `comedian` instance and a message string. It initiates a chat between the user proxy agent and the comedian agent, with the message "Tell me a joke about cats and ninjas." 20 | 21 | Overall, this code sets up a conversation between a user proxy agent and a comedian agent, using configuration information and message input. -------------------------------------------------------------------------------- /01_agents_and_conversation/main.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | # Import necessary modules 5 | 6 | from autogen import AssistantAgent, UserProxyAgent 7 | import os 8 | 9 | 10 | # Define a configuration list containing API credentials and settings 11 | config_list = [ 12 | { 13 | "model": os.environ.get("AZURE_OPENAI_MODEL", ""), 14 | "api_key": os.environ.get("AZURE_OPENAI_KEY", ""), 15 | "api_type": "azure", 16 | "base_url": os.environ.get("AZURE_OPENAI_ENDPOINT", ""), 17 | "api_version": os.environ.get("AZURE_OPENAI_API_VERSION", "") 18 | } 19 | ] 20 | 21 | # Create an instance of the AssistantAgent class for a comedian 22 | comedian = AssistantAgent( 23 | name="comedian", 24 | system_message="You are a professional comedian. You can tell jokes and entertain people.", 25 | description="This agent is a great comedian telling interesting and funny jokes.", 26 | llm_config={"config_list": config_list} 27 | ) 28 | 29 | # Create an instance of the UserProxyAgent class 30 | user_proxy = UserProxyAgent( 31 | name="user_proxy", 32 | code_execution_config={"work_dir": "coding", "use_docker": False} 33 | ) 34 | 35 | # Initiate a chat between the user_proxy agent and the comedian agent 36 | user_proxy.initiate_chat( 37 | comedian, 38 | message="Tell me a joke about cats and ninjas." 39 | ) -------------------------------------------------------------------------------- /02_agents_with_tools/README.md: -------------------------------------------------------------------------------- 1 | #TODO ADD MORE DETAILS -------------------------------------------------------------------------------- /03_agents_that_learn/README.md: -------------------------------------------------------------------------------- 1 | ## Comedian Assistant Experience 2 | 3 | This example is based on the [comedian example](../01_agents_and_conversation/README.md) 4 | 5 | The code in [main.py](main.py) sets up a conversation between two agents: a comedian agent and a user proxy agent. 6 | 7 | Let's break down the code step by step: 8 | 9 | 1. Importing Modules: 10 | - The code begins by importing the necessary modules: `AssistantAgent`, `UserProxyAgent`, and `Teachability` from the `autogen.agentchat.contrib.capabilities` package. 11 | - It also imports the `os` module. 12 | 13 | 2. Configuration: 14 | - The code defines a list called `config_list` which contains a dictionary with configuration details for the agents. 15 | - 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. 16 | 17 | 3. Creating the Comedian Agent: 18 | - The code creates an instance of the `AssistantAgent` class called `comedian`. 19 | - The `AssistantAgent` constructor takes several parameters: 20 | - `name`: The name of the agent, which is set to "comedian". 21 | - `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." 22 | - `description`: A description of the agent, which is set to "This agent is a great comedian telling interesting and funny jokes." 23 | - `llm_config`: A configuration dictionary that includes the `config_list`created earlier. 24 | 25 | 4. Teachability: 26 | - The code creates an instance of the `Teachability` class called `teachability`. 27 | - The `Teachability` constructor takes several parameters: 28 | - `reset_db`: A boolean value indicating whether to reset the agent's database, which is set to `False`. 29 | - `path_to_db_dir`: The path to the directory where the agent's experience will be stored, which is set to "./comedian_assistant_experience". 30 | - `llm_config`: A configuration dictionary that includes the `config_list` created earlier. 31 | 32 | 5. Adding Teachability to the Comedian Agent: 33 | - The code adds the `teachability` instance to the `comedian` agent using the `add_to_agent()` method of the `Teachability` class. 34 | - This allows the `comedian` agent to learn from user interactions and improve its responses over time. 35 | 36 | 6. Creating the User Proxy Agent: 37 | - The code creates an instance of the `UserProxyAgent` class called `user_proxy` 38 | - The `UserProxyAgent` constructor takes several parameters: 39 | - `name`: The name of the agent, which is set to "user_proxy". 40 | - `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. 41 | 42 | 7. Initiating the Chat: 43 | - The code initiates a chat between the `comedian` agent and the `user_proxy` agent using the `initiate_chat()` method of the `UserProxyAgent` class. 44 | - The `initiate_chat()` method takes two parameters: 45 | - The first parameter is the agent to initiate the chat with, which is the `comedian` agent in this case. 46 | - The second parameter is the message to start the conversation, which is set to "Tell me a joke about cats and ninjas." 47 | 48 | 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. -------------------------------------------------------------------------------- /03_agents_that_learn/comedian_assistant_experience/readme.md: -------------------------------------------------------------------------------- 1 | # Place holder for persistent experirence -------------------------------------------------------------------------------- /03_agents_that_learn/main.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | # Import necessary modules 5 | from autogen import AssistantAgent, UserProxyAgent 6 | from autogen.agentchat.contrib.capabilities.teachability import Teachability 7 | import os 8 | 9 | # Define the configuration list with environment variables 10 | config_list = [ 11 | { 12 | "model": os.environ.get("AZURE_OPENAI_MODEL", ""), 13 | "api_key": os.environ.get("AZURE_OPENAI_KEY", ""), 14 | "api_type": "azure", 15 | "base_url": os.environ.get("AZURE_OPENAI_ENDPOINT", ""), 16 | "api_version": os.environ.get("AZURE_OPENAI_API_VERSION", "") 17 | } 18 | ] 19 | 20 | # Create an instance of AssistantAgent for a comedian 21 | comedian = AssistantAgent( 22 | name="comedian", 23 | system_message="You are a professional comedian. You can tell jokes and entertain people.", 24 | description="This agent is a great comedian telling interesting and funny jokes.", 25 | llm_config={"config_list": config_list} 26 | ) 27 | 28 | # Create an instance of Teachability for the comedian, this will allow the comedian to learn from interactions 29 | teachability = Teachability( 30 | reset_db=False, 31 | path_to_db_dir="./comedian_assistant_experience", 32 | llm_config={"config_list": config_list} 33 | ) 34 | 35 | # Add the Teachability capability to the comedian agent 36 | teachability.add_to_agent(comedian) 37 | 38 | # Create an instance of UserProxyAgent 39 | user_proxy = UserProxyAgent( 40 | name="user_proxy", 41 | code_execution_config={"work_dir": "coding", "use_docker": False} 42 | ) 43 | 44 | # Initiate a chat between the user_proxy and the comedian agent 45 | user_proxy.initiate_chat( 46 | comedian, 47 | message="Tell me a joke about cats and ninjas." 48 | ) -------------------------------------------------------------------------------- /04_travel_agency_front_office/README.md: -------------------------------------------------------------------------------- 1 | #TODO README -------------------------------------------------------------------------------- /05_travel_agency_with_front_and_back_office/README.md: -------------------------------------------------------------------------------- 1 | # Travel Agency front and back office 2 | 3 | This example is based on a Travel Agency scenario. 4 | 5 | The code [main.py](main.py) sets up a conversation between a customer and the fron office agents: a `Customer Assistant` agent and a `Trip Specialist` agent. 6 | The front office agents work with back office (`Accommodation Booking Assistant`, `Activities Booking Assistant`, and `Flight Booking Assistant`) to create the pacakge for the customer. 7 | Front office and back office can use the terminal to perform various operations: 8 | * find flights 9 | * book flights 10 | * find accomodations 11 | * book accomodations 12 | * find tickets for activites 13 | * book tickets 14 | * retrieve current bookings for the customer 15 | * email the final bookings back to the customer 16 | 17 | Let's break down the code step by step: 18 | 19 | 1. Import Statements: 20 | - The script begins by importing necessary modules and classes from various packages. These include tools for creating conversational agents, handling group chats, registering functions, and integrating with Azure OpenAI services. 21 | 22 | 2. Setup Azure OpenAI Models: 23 | - It initializes two Azure OpenAI models - one for generating responses (llm) and another for embeddings (embed_model). The models are configured with parameters such as deployment name, temperature, API key, endpoint, and version, fetched from environment variables. 24 | 25 | 3. Configuration for Conversational Agents: 26 | - A configuration list (config_list) is defined with details required to interact with the Azure OpenAI API, including model, API key, base URL, and API version. 27 | 28 | 4. Creation of Conversational Agents: 29 | - Several ConversableAgent instances are created for different roles within the travel agency system, such as: 30 | - `customer proxy` 31 | - Front office : 32 | - `customer assistant` 33 | - `trip specialist assistant` 34 | - Back office 35 | - `flight booking assistant` 36 | - `accommodation booking assistant` 37 | - `activities booking assistant` 38 | - `terminal for executing tools` 39 | 40 | 5. Teachability Feature: 41 | - The Teachability capability is added to the `customer assistant` and `trip specialist assistant agents`, allowing them to learn from interactions and improve over time. 42 | 43 | 6. Tool Registration: 44 | - Functions for :finding and booking flights, accommodations, and attraction tickets are registered with the appropriate agents using register_function. This step links the conversational agents with the actual functionalities they are supposed to handle. 45 | 46 | 7. Group Chat Setup: 47 | - A `GroupChat` instance is created, including all the agents involved in the system. This setup defines how agents can communicate within the system, specifying allowed speaker transitions to control the flow of conversation. 48 | 49 | 8. Group Chat Manager: 50 | - A `GroupChatManager` is instantiated to manage the group chat, equipped with the configuration for interacting with the Azure OpenAI API. 51 | 52 | 9. Initiating a Chat: 53 | - Finally, the script initiates a chat session through the `customer proxy agent`, simulating a customer's request to book a travel package. The conversation is managed by the group chat manager. 54 | -------------------------------------------------------------------------------- /05_travel_agency_with_front_and_back_office/customer_assistant_experience/readme.md: -------------------------------------------------------------------------------- 1 | # TODO README -------------------------------------------------------------------------------- /05_travel_agency_with_front_and_back_office/main.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | from autogen import ConversableAgent 5 | from autogen import GroupChat 6 | from autogen import GroupChatManager 7 | from autogen import register_function 8 | from autogen.agentchat.contrib.capabilities.teachability import Teachability 9 | from llama_index.core import Settings 10 | from llama_index.core.agent import ReActAgent 11 | from llama_index.core.memory import ChatSummaryMemoryBuffer 12 | from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding 13 | from llama_index.llms.azure_openai import AzureOpenAI 14 | from llama_index.tools.wikipedia import WikipediaToolSpec 15 | from autogen.agentchat.contrib.llamaindex_conversable_agent import LLamaIndexConversableAgent 16 | from tools.travel_tools import find_flights, book_flight, find_accommodations, book_accommodation, get_bookings, send_booking_email, book_attraction_tickets, find_attractions_tickets 17 | import os 18 | 19 | # setup llamaindex 20 | llm = AzureOpenAI( 21 | deployment_name= os.environ.get("AZURE_OPENAI_MODEL", ""), 22 | temperature=0.0, 23 | api_key= os.environ.get("AZURE_OPENAI_KEY", ""), 24 | azure_endpoint= os.environ.get("AZURE_OPENAI_ENDPOINT", ""), 25 | api_version= os.environ.get("AZURE_OPENAI_API_VERSION", ""), 26 | ) 27 | 28 | embed_model = AzureOpenAIEmbedding( 29 | deployment_name= os.environ.get("AZURE_OPENAI_EMBEDDING_MODEL", ""), 30 | temperature=0.0, 31 | api_key= os.environ.get("AZURE_OPENAI_KEY", ""), 32 | azure_endpoint= os.environ.get("AZURE_OPENAI_ENDPOINT", ""), 33 | api_version= os.environ.get("AZURE_OPENAI_API_VERSION", ""), 34 | ) 35 | 36 | Settings.llm = llm 37 | Settings.embed_model = embed_model 38 | 39 | # setup autogen 40 | 41 | config_list = [ 42 | { 43 | "model": os.environ.get("AZURE_OPENAI_MODEL", ""), 44 | "api_key": os.environ.get("AZURE_OPENAI_KEY", ""), 45 | "api_type": "azure", 46 | "base_url": os.environ.get("AZURE_OPENAI_ENDPOINT", ""), 47 | "api_version": os.environ.get("AZURE_OPENAI_API_VERSION", "") 48 | } 49 | ] 50 | 51 | # create autogen agents 52 | 53 | # create the back office agents 54 | 55 | # create the customer agent as user proxy 56 | customer_proxy = ConversableAgent( 57 | "customer", 58 | description="This the customer trying to book a trip, flights and accommodations.", 59 | human_input_mode="ALWAYS", 60 | ) 61 | 62 | # create the flight booking assistant agent 63 | flight_booking_assistant = ConversableAgent( 64 | "flight_booking_assistant", 65 | system_message="You help customers finding flights and booking them. All retrieved information will be sent to the customer service which will present informations to the customer. Use the tool find_flights(origin='London', destination='Tokyo', date=2025-04-15) to find flights and book_flight(flight_name='Flight 01',origin='London', destination='Tokyo', departure_date=2025-04-15, passengers=1) to book a flight.", 66 | description="This agent helps customers find flights and book them. It can use external resources to provide more details.", 67 | llm_config={"config_list": config_list}, 68 | # human_input_mode="ALWAYS" 69 | ) 70 | 71 | # create the accommodation booking assistant agent 72 | accommodation_booking_assistant = ConversableAgent( 73 | "accommodation_booking_assistant", 74 | system_message="You help customers finding hotels and accommodations and booking them. When looking up accommodations, you can use external resources to provide more details. All retrieved information will be sent to the customer service which will present informations to the customer. use find_accomodations(location='Tokyo', date=2025-04-15) to find accomodations and book_accomodation(accomodation_name='Tokyo', check_in_date=2025-04-15, nights=3, guests=1) to book accomodation.", 75 | description="This agent helps customers find accommodations and hotels and book them. It can use external resources to provide more details.", 76 | llm_config={"config_list": config_list}, 77 | ) 78 | 79 | # create the activities booking assistant agent 80 | activities_booking_assistant = ConversableAgent( 81 | "activities_booking_assistant", 82 | system_message="You help customers finding finding tickets for the attractions and activities they want to do.", 83 | description="This agent helps customers find tickets for activities, venues and events and book them. It can use external resources to provide more details.", 84 | llm_config={"config_list": config_list}, 85 | ) 86 | 87 | # create the front office agents 88 | 89 | # create the customer assistant agent 90 | customer_assistant = ConversableAgent( 91 | "customer_service", 92 | system_message="You handle all the final communication, sending booking confirmations and other details. You can access the current customer bookings details and use them in email and communications. use get_bookings() to get the bookings and send_booking_email(email='customer@domain.com', booking_details = \{\}) to send an email with booking details. As you learn more about the customers and their booking habits, you can use this information to provide better service.", 93 | description="This agent handles all the final communication with the customer, sending booking confirmations and other details. To do this, it can access the current customer bookings details and bookings and use them in email and communications.", 94 | llm_config={"config_list": config_list}, 95 | ) 96 | 97 | # add teachability to the customer assistant, this will allow the agent to learn from interactions 98 | customer_assistant_experience = Teachability( 99 | reset_db=False, 100 | path_to_db_dir="./customer_assistant_experience", 101 | llm_config={"config_list": config_list}) 102 | 103 | customer_assistant_experience.add_to_agent(customer_assistant) 104 | 105 | # create the computer terminal agent, this will have the ability to execute tools 106 | terminal = ConversableAgent( 107 | "computer_terminal", 108 | description="This computer terminal can be used to execute tools like booking flight and accommodations.", 109 | ) 110 | 111 | 112 | # create a react agent to use wikipedia tool 113 | # Get the wikipedia tool spec for llamaindex agents 114 | 115 | wiki_spec = WikipediaToolSpec() 116 | wikipedia_tool = wiki_spec.to_tool_list()[1] 117 | 118 | # create a memory buffer for the react agent 119 | memory = ChatSummaryMemoryBuffer(llm=llm, token_limit=16000) 120 | 121 | # create the location specialist agent using the ReAct agent pattern 122 | location_specialist = ReActAgent.from_tools( 123 | tools=[wikipedia_tool], 124 | llm=llm, 125 | max_iterations=8, 126 | memory=memory, 127 | verbose=True) 128 | 129 | 130 | # create an autogen agent using the integration for llamaindex 131 | trip_specialist_assistant = LLamaIndexConversableAgent( 132 | "trip_specialist", 133 | llama_index_agent= location_specialist, 134 | system_message="You help customers finding more about places they would like to visit. You can use external resources to provide more details as you engage with the customer. As you learn more about the customers and their interests and passions, you can use this information to provide better service.", 135 | description="This agents helps customers discover locations to visit, things to do, and other details about a location. It can use external resources to provide more details. This agent helps in finding attractions, history and all that there si to know abotu a place", 136 | ) 137 | 138 | # add teachability to the trip assistant, this will allow the agent to learn from interactions 139 | trip_assistant_experience = Teachability( 140 | reset_db=False, 141 | path_to_db_dir="./trip_assistant_experience", 142 | llm_config={"config_list": config_list}) 143 | 144 | trip_assistant_experience.add_to_agent(trip_specialist_assistant) 145 | 146 | # register the tools with the agents 147 | register_function( 148 | find_flights, 149 | executor=terminal, 150 | caller=flight_booking_assistant, 151 | name="find_flights", 152 | description="A tool for finding flight options between two locations. usage find_flights(origin='London', destination='Tokyo', date=2025-04-15) to find flights.", 153 | ) 154 | 155 | register_function( 156 | book_flight, 157 | executor=customer_proxy, 158 | caller=flight_booking_assistant, 159 | name="book_flight", 160 | description="A tool for booking flights between two locations. use book_flight(flight_name='Flight 01',origin='London', destination='Tokyo', departure_date=2025-04-15, passengers=1) to book a flight.", 161 | ) 162 | 163 | register_function( 164 | find_accommodations, 165 | executor=terminal, 166 | caller=accommodation_booking_assistant, 167 | name="find_accommodations", 168 | description="A tool for finding accommodation options in a location. use find_accommodations(location='Tokyo', date=2025-04-15) to find accommodations.", 169 | ) 170 | 171 | register_function( 172 | book_accommodation, 173 | executor=customer_proxy, 174 | caller=accommodation_booking_assistant, 175 | name="book_accommodation", 176 | description="A tool for booking accommodation. use book_accommodation(accommodation_name='Tokyo', check_in_date=2025-04-15, nights=3, guests=1) to book accommodation.", 177 | ) 178 | 179 | register_function( 180 | find_attractions_tickets, 181 | executor=terminal, 182 | caller=activities_booking_assistant, 183 | name="find_attractions_tickets", 184 | description="A tool for finding accommodation options in a location. use find_attractions_tickets(attraction='british museum', , number_of_people=1) to find tickets for activities and attractions.", 185 | ) 186 | 187 | register_function( 188 | book_attraction_tickets, 189 | executor=customer_proxy, 190 | caller=activities_booking_assistant, 191 | name="book_attraction_tickets", 192 | description="A tool for booking attraction tickets. use book_attraction_tickets(attraction='british museum', date='01/04/2025', number_of_people=1) to book tickets for activities and attractions.", 193 | ) 194 | 195 | register_function( 196 | get_bookings, 197 | executor=terminal, 198 | caller=customer_assistant, 199 | name="get_bookings", 200 | description="Retrieves the current bookings for the customer. call get_bookings() to get the bookings.", 201 | ) 202 | 203 | register_function( 204 | send_booking_email, 205 | executor=terminal, 206 | caller = customer_assistant, 207 | name="send_booking_email", 208 | description="A tool for sending booking confirmation emails, call send_booking_email(email=dd@cp.com, booking_details = \{\}) to send an email with booking details.", 209 | ) 210 | 211 | 212 | # create a group chat, note that only the terminal agents can communicate only with the front nad back office agents 213 | group_chat = GroupChat( 214 | agents=[ 215 | customer_proxy, 216 | activities_booking_assistant, 217 | flight_booking_assistant, 218 | accommodation_booking_assistant, 219 | trip_specialist_assistant, 220 | customer_assistant, 221 | terminal 222 | ], 223 | messages=[], 224 | max_round=1000, 225 | send_introductions=False, 226 | speaker_transitions_type="disallowed", 227 | allowed_or_disallowed_speaker_transitions={ 228 | terminal: [customer_proxy], 229 | customer_proxy: [terminal], 230 | }, 231 | ) 232 | 233 | 234 | # create a group chat manager 235 | group_chat_manager = GroupChatManager( 236 | groupchat=group_chat, 237 | llm_config={"config_list": config_list}, 238 | # human_input_mode="ALWAYS" 239 | ) 240 | 241 | # initiate a chat between the customer and the group chat manager 242 | chat_result = customer_proxy.initiate_chat( 243 | group_chat_manager, 244 | message="Hi I would like to book a travel package.", 245 | summary_method="reflection_with_llm", 246 | ) 247 | -------------------------------------------------------------------------------- /05_travel_agency_with_front_and_back_office/tools/travel_tools.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | from datetime import date 5 | import random 6 | from pydantic import Field 7 | import json 8 | 9 | bookings = { 10 | "flights": [], 11 | "accommodations": [] , 12 | "attractions": [] 13 | } 14 | 15 | emails = [] 16 | 17 | # apis to send emails 18 | def send_booking_email(email: str, booking_details: dict) -> str: 19 | """Send an email with full booking details. The booking details must be a dictionary.""" 20 | print(f"Sending email to {email}") 21 | email_booking = [] 22 | value = {} 23 | if not isinstance(booking_details, dict ): 24 | value = booking_details.__dict__ 25 | else: 26 | value = booking_details 27 | email_booking.append(value) 28 | 29 | message = f"Dear traveller, \n\nWe are happy to confirm your booking. Here are the details: \n\n{json.dumps(obj= value, indent=4)}\n\nHave a great trip!\n\nThe travel team" 30 | print(f"Email sent to {email} : { message}") 31 | emails.append(message) 32 | return f"Email sent to {email}" 33 | 34 | # apis to get bookings 35 | def get_bookings() -> dict: 36 | """Useful for getting bookings.""" 37 | return bookings 38 | 39 | # apis to find and book tickets 40 | def find_attractions_tickets(attraction: str, number_of_people:int) -> dict: 41 | """Find tickets for an attraction for a given number of people.""" 42 | return { 43 | "attraction": attraction, 44 | "date": date.today(), 45 | "price_pp": f"€{random.randrange(10, 50)}", 46 | "number_of_people": number_of_people 47 | } 48 | 49 | 50 | def book_attraction_tickets(attraction: str, date: date, number_of_people: int) -> dict: 51 | """Book tickets for an attraction for a given number of people.""" 52 | attraction_booking = { 53 | "attraction": attraction, 54 | "date": date, 55 | "number_of_people": number_of_people, 56 | "booking_reference": random.randrange(1000, 9999) 57 | } 58 | 59 | bookings["attractions"].append(attraction_booking) 60 | 61 | return attraction_booking 62 | 63 | # apis to find and book flights 64 | def find_flights( 65 | origin: str, 66 | destination:str, 67 | date: date 68 | ) -> list[dict]: 69 | """Can find flights on a specific date between a departure and destination.""" 70 | values : list[dict] = [] 71 | for i in range(random.randrange(3, 10)): 72 | values.append({ 73 | "name": f"Flight {i}", 74 | "date": date, 75 | "origin": origin, 76 | "departure_time": f"{random.randrange(3, 19)}:00", 77 | "price_pp": f"€{random.randrange(100, 1000)}", 78 | "destination": destination 79 | }) 80 | 81 | return values 82 | 83 | def book_flight( 84 | flight_name: str, 85 | origin: str, 86 | destination: str, 87 | departure_date: date, 88 | passengers: int 89 | ) -> dict: 90 | """Can book a flight on a date for any number of passengers. It returns the booking confirmation.""" 91 | flight_booking ={ 92 | "name": flight_name, 93 | "date": departure_date, 94 | "passengers": passengers, 95 | "origin": origin, 96 | "destination": destination, 97 | "booking_reference": random.randrange(1000, 9999) 98 | } 99 | 100 | bookings["flights"].append(flight_booking) 101 | 102 | return flight_booking 103 | 104 | # apis to find and book accommodations 105 | def find_accommodations( 106 | location: str, 107 | date: date 108 | ) -> list[dict]: 109 | """Can find accommodations for a given location and date.""" 110 | values : list[dict] = [] 111 | for i in range(random.randrange(3, 10)): 112 | values.append( 113 | { 114 | "name": f"Accommodation {i}", 115 | "location": location, 116 | "date": date, 117 | "price_pn": f"€{random.randrange(100, 333)}", 118 | } 119 | ) 120 | 121 | 122 | return values 123 | 124 | def book_accommodation( 125 | accommodation_name: str, 126 | check_in_date: date, 127 | nights:int, 128 | guests: int 129 | ) -> dict: 130 | """Can book accommodation for a group of guests on specific date and number on nights. It returns the booking confirmation including the booking reference.""" 131 | accommodation_booking = { 132 | "name": accommodation_name, 133 | "date": check_in_date, 134 | "nights": nights, 135 | "guests": guests, 136 | "booking_reference": random.randrange(1000, 9999) 137 | } 138 | 139 | bookings["accommodations"].append(accommodation_booking) 140 | 141 | return accommodation_booking -------------------------------------------------------------------------------- /05_travel_agency_with_front_and_back_office/trip_assistant_experience/readme.md: -------------------------------------------------------------------------------- 1 | # Place holder for persistent experirence -------------------------------------------------------------------------------- /06_travel_agency_with_solver/README.md: -------------------------------------------------------------------------------- 1 | # Travel Agency with solver -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Microsoft Agentic Cookbook** 2 | 3 | The cookbooks are focused on conversational agents, all the samples are using the [Autogen](https://github.com/microsoft/autogen) framework. 4 | 5 | ## Contents 6 | 7 | This cookbook includes: 8 | 9 | * [Introduction](✅) 10 | * [What is AutoGen](./docs/autogen.md)(✅) 11 | * [Understanding Key Components](./docs/components.md)(✅) 12 | * [What is Domain Driven Design](./docs/domain_driven_design.md)(✅) 13 | * [tutorials](🔜) 14 | * [Tell me a joke, agents conversing style](./01_agents_and_conversation/README.md)(✅) 15 | * [Give tools to agents](./02_agents_with_tools/README.md)(🔜) 16 | * [Teachable agent](./03_agents_that_learn/README.md)(✅) 17 | * [Travel Agency front office](./04_travel_agency_front_office/README.md)(🔜) 18 | * [Travel Agency front and back office](./05_travel_agency_with_front_and_back_office/README.md)(✅) 19 | * [Travel Agency with solver](./06_travel_agency_with_solver/README.md)(🔜) 20 | 21 | ## Opening the Resource in Codespace 22 | [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/microsoft/AgenticCookBook/tree/autogen) 23 | 24 | ### Storing Your API Keys 25 | 26 | Keeping your API keys safe and secure is important when building any type of application. We recommend not to store any API keys directly in your code. Committing those details to a public repository could result in security issues and even unwanted costs if used by a bad actor. 27 | 28 | # IMPORTANT! 29 | ## Setup environment variables 30 | - Duplicate the `.env.template` file and rename the new file to `.env`. 31 | - Open your new `.env` file and modify all the endpoints and api keys for all deployments as follows: 32 | 33 | # Open AI details 34 | - AZURE_OPENAI_MODEL="gpt-4-32k" 35 | - AZURE_OPENAI_EMBEDDING_MODEL="text-embedding-ada-002" 36 | - AZURE_OPENAI_KEY="" 37 | - AZURE_OPENAI_ENDPOINT="" 38 | - AZURE_OPENAI_API_VERSION="2024-02-01" 39 | 40 | ## How to Run locally on your computer 41 | 42 | To run the code locally on your computer, you would need to have some version of [Python installed](https://www.python.org/downloads). 43 | 44 | To then use the repository, you need to clone it: 45 | 46 | ```shell 47 | git clone https://github.dev/microsoft/AgenticCookBook 48 | cd AgenticCookBook 49 | ``` 50 | 51 | Once you have everything checked out, you can get started! 52 | 53 | ### Installing Miniconda (optional step) 54 | [Miniconda](https://conda.io/en/latest/miniconda.html) is a lightweight installer for installing [Conda](https://docs.conda.io/en/latest), Python, as well as a few packages. 55 | Conda itself is a package manager, that makes it easy to setup and switch between different Python [**virtual environments**](https://docs.python.org/3/tutorial/venv.html) and packages. It also comes in handy for installing packages that are not available via `pip`. 56 | 57 | You can follow the [MiniConda installation guide](https://docs.anaconda.com/free/miniconda/#quick-command-line-install) to set it up. 58 | 59 | With Miniconda installed, you need to clone the [repository](https://github.dev/leestott/AzureOpenAISamples) (if you haven't already) 60 | 61 | Next, you need to create a virtual environment. To do this with Conda, go ahead and create a new environment file (_environment.yml_). If you are following along using Codespaces, create this within the `.devcontainer` directory, thus `.devcontainer/environment.yml`. 62 | 63 | Go ahead and populate your environment file with the snippet below: 64 | ```yml 65 | name: 66 | channels: 67 | - defaults 68 | dependencies: 69 | - python= 70 | - openai 71 | - python-dotenv 72 | ``` 73 | 74 | The environment file specifies the dependencies we need. `` refers to the name you would like to use for your Conda environment, and `` is the version of Python you would like to use, for example, `3` is the latest major version of Python. 75 | 76 | With that done, you can go ahead and create your Conda environment by running the commands below in your command line/terminal 77 | 78 | ```bash 79 | conda env create --name ai4beg --file .devcontainer/environment.yml # .devcontainer sub path applies to only Codespace setups 80 | conda activate ai4beg 81 | ``` 82 | 83 | Refer to the [Conda environments guide](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) if you run into any issues. 84 | 85 | ### Using Visual Studio Code with the Python support extension 86 | 87 | We recommend using the [Visual Studio Code (VS Code)](http://code.visualstudio.com/) editor with the [Python support extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) installed for this course. This is, however, more of a recommendation and not a definite requirement 88 | 89 | > **Note**: By opening the course repository in VS Code, you have the option to set the project up within a container. This is because of the [special `.devcontainer`](https://code.visualstudio.com/docs/devcontainers/containers) directory found within the course repository. More on this later. 90 | 91 | > **Note**: Once you clone and open the directory in VS Code, it will automatically suggest you install a Python support extension. 92 | 93 | > **Note**: If VS Code suggests you re-open the repository in a container, decline this request in other to use the locally installed version of Python. 94 | 95 | ### Using Jupyter in the Browser 96 | 97 | You can also work on the project using the [Jupyter environment](https://jupyter.org) right within your browser. Both classic Jupyter and [Jupyter Hub](https://jupyter.org/hub provide quite a pleasant development environment with features such as auto-completion, code highlighting, etc. 98 | 99 | To start Jupyter locally, head over to the terminal/command line, navigate to the course directory, and execute: 100 | 101 | ```bash 102 | jupyter notebook 103 | ``` 104 | 105 | or 106 | 107 | ```bash 108 | jupyterhub 109 | ``` 110 | 111 | This will start a Jupyter instance and the URL to access it will be shown within the command line window. 112 | 113 | Once you access the URL, you should see the course outline and be able to navigate to any `*.ipynb` file. For example, `08-building-search-applications/python/oai-solution.ipynb`. 114 | 115 | ### Running in a container 116 | 117 | An alternative to setting everything up on your computer or Codespace is to use a [container](https://en.wikipedia.org/wiki/Containerization_(computing). The special `.devcontainer` folder within the course repository makes it possible for VS Code to set up the project within a container. Outside of Codespaces, this will require the installation of Docker, and quite frankly, it involves a bit of work, so we recommend this only to those with experience working with containers. 118 | 119 | One of the best ways to keep your API keys secure when using GitHub Codespaces is by using Codespace Secrets. Please follow the [Codespaces secrets management](https://docs.github.com/en/codespaces/managing-your-codespaces/managing-secrets-for-your-codespaces) guide to learn more about this. 120 | 121 | ## Using the Azure OpenAI Service for the first time 122 | 123 | If this is your first time working with the Azure OpenAI service, please follow this guide on how to [create and deploy an Azure OpenAI Service resource.](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) 124 | 125 | ## Using the OpenAI API for the first time 126 | 127 | If this is your first time working with the OpenAI API, please follow the guide on how to [create and use the Interface.](https://platform.openai.com/docs/quickstart?context=python) 128 | 129 | ## Meet Other Learners 130 | 131 | We have our official [AI Community Discord server](https://aka.ms/genai-discord) for meeting other learners. This is a great way to network with other like-minded entrepreneurs, builders, students, and anyone looking to level up in Generative AI. 132 | 133 | [![Join discord channel](https://dcbadge.vercel.app/api/server/ByRwuEEgH4)](https://aka.ms/genai-discord) 134 | 135 | The project team will also be on this Discord server to help any learners. 136 | 137 | # Requirements 138 | - Visual Studio Code 139 | - Python (tested with 3.10, 3.12) 140 | - Python virtual environment tool (venv) 141 | - An Azure account 142 | - Azure subscription onboarded into Azure OpenAI 143 | - Necessary permissions to deploy resources in the subscription 144 | 145 | # Preparation 146 | 147 | ## Git repository 148 | - Clone this repository to your local machine and open a terminal in the cloned directory. 149 | 150 | ## Visual Studio Code 151 | - Windows 152 | - Install [Visual Studio Code](https://code.visualstudio.com/) 153 | - Linux 154 | - Install [Visual Studio Code](https://code.visualstudio.com/) 155 | - Mac 156 | - Install [Visual Studio Code](https://code.visualstudio.com/) 157 | 158 | ## Python 159 | - Windows 160 | - Install [Python 3.12.2](https://www.python.org/downloads/release/python-3122/) 161 | - Linux 162 | - It is usually pre-installed. Check version with `python3 --version`. 163 | - Mac 164 | - `brew install python3` 165 | 166 | ### Python Virtual Environment Setup 167 | - To install virtualenv via pip run: 168 | - Windows / Mac / Linux: 169 | 170 | `pip3 install virtualenv` 171 | 172 | - Creation of virtualenv (in the cloned Azure/AOAI-workshop directory): 173 | - Windows: 174 | 175 | `python -m virtualenv venv` 176 | - Mac / Linux: 177 | 178 | `virtualenv -p python3 venv` 179 | 180 | - Activate the virtualenv: 181 | - Windows: 182 | 183 | `.\venv\Scripts\activate.ps1` 184 | - Mac / Linux 185 | 186 | `source ./venv/bin/activate` 187 | 188 | ### Install required libraries in your virtual environment 189 | - Run the following command in the terminal: 190 | - Windows / Mac / Linux: 191 | 192 | `pip3 install -r requirements.txt` 193 | 194 | ## Contributing 195 | 196 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 197 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 198 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 199 | 200 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 201 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 202 | provided by the bot. You will only need to do this once across all repos using our CLA. 203 | 204 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 205 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 206 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 207 | 208 | ## Trademarks 209 | 210 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft 211 | trademarks or logos is subject to and must follow 212 | [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). 213 | Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. 214 | Any use of third-party trademarks or logos are subject to those third-party's policies. 215 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # TODO: The maintainer of this repo has not yet edited this file 2 | 3 | **REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project? 4 | 5 | - **No CSS support:** Fill out this template with information about how to file issues and get help. 6 | - **Yes CSS support:** Fill out an intake form at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). CSS will work with/help you to determine next steps. 7 | - **Not sure?** Fill out an intake as though the answer were "Yes". CSS will help you decide. 8 | 9 | *Then remove this first heading from this SUPPORT.MD file before publishing your repo.* 10 | 11 | # Support 12 | 13 | ## How to file issues and get help 14 | 15 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing 16 | issues before filing new issues to avoid duplicates. For new issues, file your bug or 17 | feature request as a new Issue. 18 | 19 | For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE 20 | FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER 21 | CHANNEL. WHERE WILL YOU HELP PEOPLE?**. 22 | 23 | ## Microsoft Support Policy 24 | 25 | Support for this **PROJECT or PRODUCT** is limited to the resources listed above. 26 | -------------------------------------------------------------------------------- /docs/autogen.md: -------------------------------------------------------------------------------- 1 | # What is AutoGen? 2 | 3 | AutoGen is a multi-agent conversation framework. 4 | 5 | AutoGen enables you to: 6 | 7 | - Build applications based on multi-agent conversations. 8 | - Compose and orchestrate complex workflows using a diverse set of conversation patterns. 9 | 10 | ## What is an agent? 11 | 12 | An agent refers to a system designed to achieve specific objectives for a user. 13 | 14 | Agents can have varying degrees of autonomy when accomplishing goals. 15 | 16 | To effectively carry out its functions, an agent may use a range of tools, including AI models, knowledge bases, and software, which assist in data processing, executing actions, and successfully accomplishing the intended tasks. 17 | 18 | ## What are multi-agent systems? 19 | 20 | Multi-agent systems consist of multiple specialized agents that work together to achieve a common objective. These systems are well-suited for complex tasks that require collaboration and coordination. 21 | 22 | Consider the task of planning a winter vacation to a warm destination. This involves several steps: 23 | 24 | 1. Researching online for potential travel spots. 25 | 1. Checking personal and, if applicable, others' availability by consulting calendars. 26 | 1. Reviewing bank accounts to determine a travel budget based on the planned dates. 27 | 1. Utilizing travel tools to find the best deals on flights and hotels, while considering reward programs and more affordable travel periods. 28 | 1. Conducting further online research for activities at each potential location. 29 | 1. Synthesizing all gathered information—availability, expenses, and activities—to make an informed decision. 30 | 1. Proceeding with the actual bookings of flights, hotels, and reservations. 31 | 32 | This process requires extensive information gathering, planning, and execution. 33 | 34 | Creating an application to handle this as a single agent could be challenging due to the varied contexts and domains involved. 35 | 36 | On the other hand, designing it as a multi-agent system simplifies the problem. Each agent can focus on a specific aspect of the task - managing calendars, booking travel, conducting web searches, handling finances - allowing the collective effort to be more efficient and effective in achieving the goal. 37 | 38 | ## Additional resources 39 | 40 | - [AutoGen documentation](https://microsoft.github.io/autogen/docs/Getting-Started) -------------------------------------------------------------------------------- /docs/components.md: -------------------------------------------------------------------------------- 1 | # Components of AI agents 2 | 3 | Agents are composed of various components. These include: 4 | 5 | - Agents 6 | - Tools 7 | 8 | ## Agents 9 | 10 | In AutoGen, there are two types of agents: 11 | 12 | - Conversable Agent 13 | - User Proxy Agent 14 | - Assistant Agent 15 | - Group Chat Manager Agent 16 | 17 | ### Conversable Agent 18 | 19 | This is the base type of agent available in AutoGen. The core functionality of a Conversable Agent is being able to interact with other agents through messages. 20 | 21 | ### Assistant Agent 22 | 23 | An Assistant Agent uses language models such as GPT to solve problems. Using these language models, Assistant Agents can: 24 | 25 | - Write code to solve a problem 26 | - Evaluate code execution results 27 | - Suggest corrections and bug fixes. 28 | 29 | ### User Proxy Agent 30 | 31 | A User Proxy agent is an agent that interacts with human users. By default, these agents solicit user input at each turn of the conversation. Additionally, User Proxy Agents can: 32 | 33 | - Trigger code execution 34 | - Generate replies using a language model 35 | 36 | ## Group Chat Manager 37 | 38 | A Group Chat Manager is an agent that manages the interactions between various agents. With a Group Chat Manager, you can define the strategy for choosing the next agent to use during a conversation 39 | 40 | ## Tools 41 | 42 | Agents can make use of tools to complete tasks. 43 | 44 | Some examples of these tools include: 45 | 46 | - **Local functions** - Enable agents to use code you've already written in your application. 47 | - **Code interpreters** - Run code generated by agents to solve a problem. 48 | - **Knowledge-bases** - Augment the context and knowledge of your agents by providing it access to data sources. These data sources can include web search engines and databases. 49 | 50 | ## Additional Resources 51 | 52 | - [AutoGen tool use examples](https://microsoft.github.io/autogen/docs/Examples/#tool-use) -------------------------------------------------------------------------------- /docs/domain_driven_design.md: -------------------------------------------------------------------------------- 1 | # Domain Driven Design and Agents 2 | 3 | ## What is Domain Driven Design (DDD) 4 | 5 | Domain-Driven Design (DDD) is a software design approach that emphasizes the importance of understanding the business domain in which a software system operates. 6 | 7 | The approach is useful in complex domains where the shared model and understanding adds significant clarity and helps in formulating a common understanding of the domain. 8 | 9 | ## Designing multi-agent systems using Domain Driven Design 10 | 11 | Domain-Driven Design (DDD) fosters a collaborative environment where domain experts and system designers come together to create a common language. This shared language is essential for translating business objectives into technical specifications. DDD employs bounded contexts to simplify complex mappings, with each context possessing its own domain model. 12 | 13 | In multi-agent systems, each agent operates within its own distinct context, mirroring the bounded contexts of DDD. By applying DDD principles, multi-agent systems can be designed to ensure that each agent’s actions are aligned with overarching business goals. This approach not only streamlines the design process but also ensures that the agents collectively contribute to the business’s strategic objectives. -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | chromadb==0.5.0 2 | duckdb==1.0.0 3 | langchainhub==0.1.19 4 | llama-index-core==0.10.44 5 | llama-index-embeddings-azure-openai==0.1.10 6 | llama-index-llms-azure-openai==0.1.8 7 | llama-index-llms-llama-cpp==0.1.3 8 | llama-index-llms-openai==0.1.22 9 | llama-index-multi-modal-llms-azure-openai==0.1.4 10 | llama-index-postprocessor-rankgpt-rerank==0.1.6 11 | llama-index-readers-file==0.1.25 12 | llama-index-readers-smart-pdf-loader==0.1.4 13 | llama-index-readers-web==0.1.18 14 | llama-index-readers-wikipedia==0.1.4 15 | llama-index-tools-wikipedia==0.1.3 16 | llama-index==0.10.44 17 | llmsherpa==0.1.4 18 | matplotlib 19 | meteostat 20 | openmeteo-requests 21 | pandas 22 | pika==1.3.2 23 | pillow==10.3.0 24 | poppler-utils==0.1.0 25 | pyautogen==0.2.29 26 | pydub==0.25.1 27 | PyMuPDF==1.24.5 28 | pypdf==4.2.0 29 | requests-cache 30 | retry-requests 31 | wikipedia==1.4.0 32 | yfinance --------------------------------------------------------------------------------