{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Welcome to the start of your adventure in Agentic AI" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Are you ready for action??

\n", " Have you completed all the setup steps in the setup folder?
\n", " Have you checked out the guides in the guides folder?
\n", " Well in that case, you're ready!!\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

This code is a live resource - keep an eye out for my updates

\n", " I 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.

\n", " 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!\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### And please do remember to contact me if I can help\n", "\n", "And I love to connect: https://www.linkedin.com/in/eddonner/\n", "\n", "\n", "### New to Notebooks like this one? Head over to the guides folder!\n", "\n", "Just to check you've already added the Python and Jupyter extensions to Cursor, if not already installed:\n", "- Open extensions (View >> extensions)\n", "- Search for python, and when the results show, click on the ms-python one, and Install it if not already installed\n", "- Search for jupyter, and when the results show, click on the Microsoft one, and Install it if not already installed \n", "Then View >> Explorer to bring back the File Explorer.\n", "\n", "And then:\n", "1. Click where it says \"Select Kernel\" near the top right, and select the option called `.venv (Python 3.12.9)` or similar, which should be the first choice or the most prominent choice. You may need to choose \"Python Environments\" first.\n", "2. Click in each \"cell\" below, starting with the cell immediately below this text, and press Shift+Enter to run\n", "3. Enjoy!\n", "\n", "After you click \"Select Kernel\", if there is no option like `.venv (Python 3.12.9)` then please do the following: \n", "1. On Mac: From the Cursor menu, choose Settings >> VS Code Settings (NOTE: be sure to select `VSCode Settings` not `Cursor Settings`); \n", "On Windows PC: From the File menu, choose Preferences >> VS Code Settings(NOTE: be sure to select `VSCode Settings` not `Cursor Settings`) \n", "2. In the Settings search bar, type \"venv\" \n", "3. 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). \n", "And then try again.\n", "\n", "Having problems with missing Python versions in that list? Have you ever used Anaconda before? It might be interferring. Quit Cursor, bring up a new command line, and make sure that your Anaconda environment is deactivated: \n", "`conda deactivate` \n", "And if you still have any problems with conda and python versions, it's possible that you will need to run this too: \n", "`conda config --set auto_activate_base false` \n", "and then from within the Agents directory, you should be able to run `uv python list` and see the Python 3.12 version." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# First let's do an import\n", "from dotenv import load_dotenv\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Next it's time to load the API keys into environment variables\n", "\n", "load_dotenv(override=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Wait, did that just output `False`??\n", "\n", "If so, the most common reason is that you didn't save your `.env` file after adding the key! Be sure to have saved.\n", "\n", "Also, make sure the `.env` file is named precisely `.env` and is in the project root directory (`agents`)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Google API Key exists and begins AIzaSyD0\n" ] } ], "source": [ "# Check the keys\n", "# Note - if you'd like to use an LLM other than OpenAI, please check out the Guide 9 on AI APIs and Ollama in the guides folder\n", "\n", "import os\n", "google_api_key = os.getenv('GOOGLE_API_KEY')\n", "\n", "if google_api_key:\n", " print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n", "else:\n", " print(\"Google API Key not set - please head to the troubleshooting guide in the setup folder\")\n", " \n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# And now - the all important import statement\n", "# If you get an import error - head over to troubleshooting guide\n", "import google.generativeai as genai\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "import google.generativeai as genai\n", "\n", "# Step 1: Configure the API key\n", "genai.configure(api_key=\"AIzaSyD0B217fP3yVIXgHCgYXrWVXNxDMYqC1BU\")\n", "\n", "# Step 2: Create a model instance (choose from: 'gemini-pro', 'gemini-1.5-pro', etc.)\n", "model = genai.GenerativeModel('gemini-2.0-flash')\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 + 2 = 4\n", "\n" ] } ], "source": [ "# Create a list of messages in the familiar OpenAI format\n", "\n", "messages = \"What is 2+2?\"\n", "\n", "response = model.generate_content(messages)\n", "print(response.text)\n" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 + 2 = 4\n", "\n" ] } ], "source": [ "response = model.generate_content(messages)\n", "print(response.text)\n", "\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You are given an unlimited supply of water and two unmarked buckets, one that holds exactly 5 liters and another that holds exactly 3 liters. Can you measure out exactly 4 liters of water? Explain your steps.\n", "\n" ] } ], "source": [ "# And# Extract the user message\n", "question = \"Please propose a hard, challenging question to assess someone's IQ. Respond only with the question.\"\n", "\n", "# Send to Gemini\n", "response = model.generate_content(question)\n", "print(response.text) \n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A farmer has 17 sheep, and all but 9 die. How many sheep are left?\n", "\n" ] } ], "source": [ "model = genai.GenerativeModel(\"gemini-1.5-flash\")\n", "\n", "prompt = \"Please propose a hard, challenging question to assess someone's IQ. Respond only with the question.\"\n", "\n", "response = model.generate_content(prompt)\n", "question = response.text\n", "\n", "print(question)\n", "\n" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "messages = [question]\n", "\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 9 sheep left.\n", "\n" ] } ], "source": [ "response = model.generate_content(messages)\n", "answer = response.text\n", "print(answer)\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "There are 9 sheep left.\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Markdown, display\n", "\n", "display(Markdown(answer))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Congratulations!\n", "\n", "That was a small, simple step in the direction of Agentic AI, with your new environment!\n", "\n", "Next time things get more interesting..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Exercise

\n", " Now try this commercial application:
\n", " First ask the LLM to pick a business area that might be worth exploring for an Agentic AI opportunity.
\n", " Then ask the LLM to present a pain-point in that industry - something challenging that might be ripe for an Agentic solution.
\n", " Finally have 3 third LLM call propose the Agentic AI solution.\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Business Area: A promising business area for an Agentic AI opportunity is **personalized preventative healthcare**.\n", "\n", "Here's why:\n", "\n", "* **High Demand & Untapped Potential:** Preventative healthcare is increasingly recognized as crucial, yet personalized approaches are still nascent. Many people struggle with adherence to preventative measures (diet, exercise, medication) and lack personalized guidance.\n", "\n", "* **Agentic AI's Strengths Align Perfectly:** Agentic AI, with its ability to autonomously plan, execute, and adapt, can excel here. It can:\n", " * **Gather data:** Integrate with wearables, health apps, and electronic health records to build a comprehensive picture of an individual's health.\n", " * **Personalize interventions:** Create tailored plans based on individual risk factors, preferences, and lifestyle. This could involve recommending specific exercises, dietary changes, medication reminders, or even scheduling check-ups.\n", " * **Adaptive learning:** Monitor progress, adjust strategies based on individual responses and evolving health data, and provide ongoing support and motivation.\n", " * **Proactive communication:** Alert users to potential problems, offer timely interventions, and facilitate communication with healthcare providers when necessary.\n", "\n", "* **Scalability and Efficiency:** An Agentic AI system could manage a large number of patients concurrently, improving accessibility and efficiency within the healthcare system.\n", "\n", "* **Data-driven improvement:** The system can continuously learn and improve its effectiveness through data analysis, leading to better health outcomes over time.\n", "\n", "\n", "Challenges would include data privacy, regulatory compliance, and the need for robust validation and safety protocols. However, the potential benefits in terms of improved health outcomes, reduced healthcare costs, and enhanced patient experience make this a compelling area for Agentic AI development.\n", "\n", "Pain Point: A major pain point that could benefit from an Agentic AI solution in personalized preventative healthcare is **patient adherence to preventative measures**. Many people struggle to maintain healthy diets, exercise regularly, or consistently take prescribed medications. Agentic AI's ability to personalize plans, provide ongoing support and motivation, and proactively communicate with patients directly addresses this critical challenge.\n", "\n", "Agentic AI Solution: ## Agentic AI Solution: \"ProactiveHealth\" for Personalized Preventative Healthcare\n", "\n", "**Problem:** Low patient adherence to preventative healthcare measures leading to poor health outcomes and increased healthcare costs.\n", "\n", "**Solution:** ProactiveHealth is an Agentic AI-powered platform designed to improve patient adherence through personalized preventative care plans and ongoing support.\n", "\n", "**Key Features:**\n", "\n", "* **Personalized Health Profile:** ProactiveHealth integrates data from wearables (Fitbit, Apple Watch), health apps (MyFitnessPal, Headspace), and electronic health records (EHRs) to create a comprehensive and continuously updated health profile for each patient. This includes physiological data, lifestyle choices, medical history, and personal preferences. Data privacy and security are paramount, utilizing robust encryption and adhering to all relevant regulations (HIPAA, GDPR, etc.).\n", "\n", "* **Autonomous Plan Generation & Adaptation:** Using the health profile, ProactiveHealth autonomously generates personalized preventative care plans. This includes:\n", " * **Customized Exercise Regimens:** Tailored workout plans based on fitness level, preferences, and available resources (home workouts, gym access).\n", " * **Dietary Recommendations:** Personalized nutrition plans considering dietary restrictions, allergies, and preferences, with integration with nutrition databases and recipe suggestions.\n", " * **Medication Management:** Automated medication reminders, refill notifications, and potential interaction checks.\n", " * **Preventive Check-up Scheduling:** Automated scheduling of necessary check-ups and screenings based on age, risk factors, and medical history.\n", " * **Mental Wellness Integration:** Integration with mindfulness apps and resources to address stress and mental health, crucial components of overall wellbeing.\n", "\n", "\n", "* **Proactive Engagement & Support:** ProactiveHealth employs several strategies for ongoing engagement and support:\n", " * **Personalized Communication:** Utilizes natural language processing (NLP) to communicate with patients in a conversational and engaging manner, providing encouragement, answering questions, and offering timely interventions.\n", " * **Gamification & Rewards:** Integrates gamified elements and reward systems to incentivize healthy behaviors and maintain motivation.\n", " * **Adaptive Learning:** Continuously monitors patient progress, adapts the plan based on feedback and adherence, and proactively adjusts strategies to optimize outcomes.\n", " * **Alerting System:** Proactively alerts patients and healthcare providers to potential problems (e.g., missed medications, concerning physiological data) to enable timely interventions.\n", "\n", "\n", "* **Healthcare Provider Integration:** ProactiveHealth offers a secure portal for healthcare providers to access patient data, review progress, and communicate directly with patients through the platform. This facilitates collaborative care and enables seamless transition between telehealth and in-person visits.\n", "\n", "\n", "* **Data-Driven Improvement:** ProactiveHealth continuously collects and analyzes data to improve its algorithms, personalize interventions further, and optimize its effectiveness over time. This data is anonymized and aggregated to maintain patient privacy while enabling valuable insights for improving the system.\n", "\n", "\n", "**Challenges & Mitigation Strategies:**\n", "\n", "* **Data Privacy:** Employ robust encryption, anonymization techniques, and strict adherence to relevant data privacy regulations. Obtain explicit informed consent from patients.\n", "* **Regulatory Compliance:** Work closely with regulatory bodies throughout the development and deployment process to ensure compliance with all relevant healthcare regulations.\n", "* **Validation & Safety Protocols:** Conduct rigorous testing and validation to ensure the safety and efficacy of the system. Implement robust error handling and monitoring mechanisms.\n", "\n", "\n", "**Business Model:** ProactiveHealth can be offered as a subscription service to individuals or integrated into existing healthcare systems. Revenue streams could include subscriptions, partnerships with insurance providers, and data licensing (with appropriate anonymization).\n", "\n", "\n", "ProactiveHealth aims to be more than just a health app; it strives to be a proactive, personalized healthcare companion, empowering individuals to take control of their health and improving overall population health outcomes.\n", "\n" ] } ], "source": [ "# Step 1: Ask Gemini to pick a business area worth exploring for Agentic AI\n", "messages = [\"Suggest a business area that might be worth exploring for an Agentic AI opportunity.\"]\n", "\n", "response = model.generate_content(messages)\n", "business_idea = response.text\n", "print(\"Business Area:\", business_idea)\n", "\n", "# Step 2: Ask Gemini for a pain-point in that industry\n", "messages = [f\"In the business area '{business_idea}', what is a major pain-point that could benefit from an Agentic AI solution?\"]\n", "\n", "response = model.generate_content(messages)\n", "pain_point = response.text\n", "print(\"Pain Point:\", pain_point)\n", "\n", "# Step 3: Ask Gemini to propose an Agentic AI solution\n", "messages = [f\"Given the pain-point '{pain_point}' in the business area '{business_idea}', propose an Agentic AI-based solution.\"]\n", "\n", "response = model.generate_content(messages)\n", "agentic_solution = response.text\n", "print(\"Agentic AI Solution:\", agentic_solution)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }