#Welcome to the start of your adventure in Agentic AI
|
Are you ready for action??Have you completed all the setup steps in the setup folder?Have you read the README? Many common questions are answered here! Have you checked out the guides in the guides folder? Well in that case, you're ready!! |
|
This code is a live resource - keep an eye out for my updatesI push updates regularly. As people ask questions or have problems, I add more examples and improve explanations. As a result, the code below might not be identical to the videos, as I've added more steps and better comments. Consider this like an interactive book that accompanies the lectures.I try to send emails regularly with important updates related to the course. You can find this in the 'Announcements' section of Udemy in the left sidebar. You can also choose to receive my emails via your Notification Settings in Udemy. I'm respectful of your inbox and always try to add value with my emails! |
#And please do remember to contact me if I can help
And I love to connect: https://www.linkedin.com/in/eddonner/
#New to Notebooks like this one? Head over to the guides folder!
Just to check you've already added the Python and Jupyter extensions to Cursor, if not already installed:
- Open extensions (View >> extensions)
- Search for python, and when the results show, click on the ms-python one, and Install it if not already installed
- Search for jupyter, and when the results show, click on the Microsoft one, and Install it if not already installed
Then View >> Explorer to bring back the File Explorer.
And then:
- Click where it says "Select Kernel" near the top right, and select the option called
.venv (Python 3.12.12)or similar, which should be the first choice or the most prominent choice. You may need to choose "Python Environments" first. - Click in each "cell" below, starting with the cell immediately below this text, and press Shift+Enter to run
- Enjoy!
After you click "Select Kernel", if there is no option like .venv (Python 3.12.12) then please do the following:
- On Mac: From the Cursor menu, choose Settings >> VS Code Settings (NOTE: be sure to select
VSCode SettingsnotCursor Settings);
On Windows PC: From the File menu, choose Preferences >> VS Code Settings(NOTE: be sure to selectVSCode SettingsnotCursor Settings) - In the Settings search bar, type "venv"
- In the field "Path to folder with a list of Virtual Environments" put the path to the project root, like C:\Users\username\projects\agents (on a Windows PC) or /Users/username/projects/agents (on Mac or Linux).
And then try again.
# First let's do an import. If you get an Import Error, see Q5 and then Q25 here: https://edwarddonner.com/avatar
from dotenv import load_dotenv
# Next it's time to load the API keys into environment variables
# If this returns false, see the next cell!
load_dotenv(override=True)#Wait, did that just output False??
If so, the most common reason is that you didn't save your .env file after adding the key! Be sure to have saved.
Also, make sure the .env file is named precisely .env and is in the project root directory (agents)
By the way, your .env file might have a stop symbol next to it in Cursor on the left, and that's actually a good thing: that's Cursor saying to you, "hey, I realize this is a file filled with secret information, and I'm not going to send it to an external AI to suggest changes, because your keys should not be shown to anyone else."
|
Final reminders1. If you're not confident about Environment Variables or Web Endpoints / APIs, please read Topics 3 and 5 in this technical foundations guide.2. If you want to use AIs other than OpenAI, like Gemini, DeepSeek or Ollama (free), please see the first section in this AI APIs guide. 3. If you ever get a Name Error in Python, you can always fix it immediately; see the last section of this Python Foundations guide and follow both tutorials and exercises. |
# Check the key - if you're not using OpenAI, check whichever key you're using! Ollama doesn't need a key.
import os
openai_api_key = os.getenv('OPENAI_API_KEY')
if openai_api_key:
print(f"OpenAI API Key exists and begins {openai_api_key[:8]}")
else:
print("OpenAI API Key not set - please head to the troubleshooting guide in the setup folder")
# And now - the all important import statement
# If you get an import error - head over to Q5 and Q25 in the FAQ at https://edwarddonner.com/avatar
# Even for other LLM providers like Gemini, you still use this OpenAI import - see Guide 9 for why
from openai import OpenAI# And now we'll create an instance of the OpenAI class
# If you're not sure what it means to create an instance of a class - head over to the guides folder (guide 6)!
# If you get a NameError - head over to the guides folder (guide 6)to learn about NameErrors - always instantly fixable
# If you're not using OpenAI, you just need to slightly modify this - precise instructions are in the AI APIs guide (guide 9)
openai = OpenAI()# Create a list of messages in the familiar OpenAI format
messages = [{"role": "user", "content": "Tell me a fun fact"}]messages# And now call it! Any problems, head to the troubleshooting guide
# This uses GPT 5.4 nano, an incredibly cheap model
# The APIs guide (guide 9) has exact instructions for using even cheaper or free alternatives to OpenAI
# If you get a NameError, head to the guides folder (guide 6) to learn about NameErrors - always instantly fixable
response = openai.chat.completions.create(model="gpt-5.4-nano", messages=messages)
print(response.choices[0].message.content)# And now - let's ask for a question:
question = "Please propose a hard, challenging question to assess someone's IQ. Respond only with the question."
messages = [{"role": "user", "content": question}]# ask it - this uses GPT 5.4 mini, still cheap but more powerful than nano
response = openai.chat.completions.create(model="gpt-5.4-mini", messages=messages)
question = response.choices[0].message.content
print(question)
# form a new messages list
messages = [{"role": "user", "content": question}]
messages# Ask the model to answer the hard question
response = openai.chat.completions.create(model="gpt-5.4-mini", messages=messages)
answer = response.choices[0].message.content
print(answer)
from IPython.display import Markdown, display
display(Markdown(answer))message = f"""
Here is a question:
{question}
And here is a possible answer that might be correct or incorrect:
{answer}
Please evaluate if the answer is correct or incorrect.
"""
print(message)messages = [{"role": "user", "content": message}]
response = openai.chat.completions.create(model="gpt-5.4", messages=messages)
print(response.choices[0].message.content)#Congratulations!
That was a small, simple step in the direction of Agentic AI, with your new environment!
Next time things get more interesting...
|
ExerciseNow try this commercial application:First ask the LLM to pick a business area that might be worth exploring for an Agentic AI opportunity. Then ask the LLM to present a pain-point in that industry - something challenging that might be ripe for an Agentic solution. Finally have 3 third LLM call propose the Agentic AI solution. We will cover this at up-coming labs, so don't worry if you're unsure.. just give it a try! |
# First create the messages:
messages = [{"role": "user", "content": "Something here"}]
# Then make the first call:
response =
# Then read the business idea:
business_area = response.
# And repeat! In the next message, include the business area within the message