{ "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": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OpenAI API Key exists and begins sk-proj-\n" ] } ], "source": [ "# Check the keys\n", "\n", "import os\n", "openai_api_key = os.getenv('OPENAI_API_KEY')\n", "\n", "if openai_api_key:\n", " print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n", "else:\n", " print(\"OpenAI API Key not set - please head to the troubleshooting guide in the setup folder\")\n", " \n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# And now - the all important import statement\n", "# If you get an import error - head over to troubleshooting guide\n", "\n", "from openai import OpenAI" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# And now we'll create an instance of the OpenAI class\n", "# If you're not sure what it means to create an instance of a class - head over to the guides folder!\n", "# If you get a NameError - head over to the guides folder to learn about NameErrors\n", "\n", "openai = OpenAI()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Create a list of messages in the familiar OpenAI format\n", "\n", "messages = [{\"role\": \"user\", \"content\": \"What is 2+2?\"}]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 + 2 equals 4.\n" ] } ], "source": [ "# And now call it! Any problems, head to the troubleshooting guide\n", "# This uses GPT 4.1 nano, the incredibly cheap model\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-4.1-nano\",\n", " messages=messages\n", ")\n", "\n", "print(response.choices[0].message.content)\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# And now - let's ask for a question:\n", "\n", "question = \"Please propose a hard, challenging question to assess someone's IQ. Respond only with the question.\"\n", "messages = [{\"role\": \"user\", \"content\": question}]\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost?\n" ] } ], "source": [ "# ask it - this uses GPT 4.1 mini, still cheap but more powerful than nano\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-4.1-mini\",\n", " messages=messages\n", ")\n", "\n", "question = response.choices[0].message.content\n", "\n", "print(question)\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# form a new messages list\n", "messages = [{\"role\": \"user\", \"content\": question}]\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Let's denote the cost of the ball as \\(x\\).\n", "\n", "Given:\n", "- The bat costs $1.00 more than the ball, so the bat costs \\(x + 1.00\\).\n", "- Together, the ball and bat cost $1.10.\n", "\n", "We set up the equation:\n", "\\[\n", "x + (x + 1.00) = 1.10\n", "\\]\n", "\\[\n", "2x + 1.00 = 1.10\n", "\\]\n", "\\[\n", "2x = 1.10 - 1.00 = 0.10\n", "\\]\n", "\\[\n", "x = \\frac{0.10}{2} = 0.05\n", "\\]\n", "\n", "**Answer:** The ball costs **5 cents**.\n" ] } ], "source": [ "# Ask it again\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-4.1-mini\",\n", " messages=messages\n", ")\n", "\n", "answer = response.choices[0].message.content\n", "print(answer)\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "Let's denote the cost of the ball as \\(x\\).\n", "\n", "Given:\n", "- The bat costs $1.00 more than the ball, so the bat costs \\(x + 1.00\\).\n", "- Together, the ball and bat cost $1.10.\n", "\n", "We set up the equation:\n", "\\[\n", "x + (x + 1.00) = 1.10\n", "\\]\n", "\\[\n", "2x + 1.00 = 1.10\n", "\\]\n", "\\[\n", "2x = 1.10 - 1.00 = 0.10\n", "\\]\n", "\\[\n", "x = \\frac{0.10}{2} = 0.05\n", "\\]\n", "\n", "**Answer:** The ball costs **5 cents**." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Markdown, display\n", "\n", "display(Markdown(answer))\n", "\n" ] }, { "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": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Let's consider the healthcare industry as a business area that might be worth exploring for an Agentic AI opportunity. Healthcare involves complex decision-making, large amounts of data, and a critical need for timely and accurate interventions—areas where an autonomous AI agent could add significant value. Would you like to dive deeper into specific use cases within healthcare, or explore a different business area?\n" ] } ], "source": [ "# First create the messages:\n", "\n", "messages = [{\"role\": \"user\", \"content\": \"First ask the LLM to pick a business area that might be worth exploring for an Agentic AI opportunity.\"}]\n", "\n", "# Then make the first call:\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-4.1-mini\",\n", " messages=messages\n", ")\n", "\n", "# Then read the business idea:\n", "\n", "business_idea = response.choices[0].message.content\n", "\n", "print(business_idea)\n", "\n", "# And repeat!" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Certainly! Exploring the healthcare industry for an Agentic AI opportunity is promising, but it's important to be aware of the pain points or challenges that such a business idea may face. Here are some key pain points related to deploying Agentic AI in healthcare:\n", "\n", "1. **Data Privacy and Security** \n", " - Healthcare data is highly sensitive and protected by regulations such as HIPAA (USA), GDPR (EU), etc. Ensuring that AI agents handle patient data securely and comply with all legal requirements is complex and critical.\n", "\n", "2. **Data Quality and Integration** \n", " - Healthcare data is often fragmented across multiple systems (EMRs, lab systems, imaging, wearable devices) and can be unstructured or inconsistent, making it difficult for AI agents to access clean, integrated data sets.\n", "\n", "3. **Regulatory Compliance and Approval** \n", " - AI-driven healthcare solutions must undergo rigorous regulatory scrutiny before deployment (e.g., FDA approval), which can be time-consuming and expensive.\n", "\n", "4. **Trust and Explainability** \n", " - Clinicians and patients need to trust AI recommendations. Lack of transparency or explainability in how autonomous agents make decisions can reduce adoption.\n", "\n", "5. **Clinical Validation and Accuracy** \n", " - Autonomous AI agents must achieve very high accuracy and robustness since errors can have serious health consequences. Validating AI models on diverse patient populations and real-world settings is challenging.\n", "\n", "6. **Ethical and Liability Concerns** \n", " - Determining accountability when an AI-driven intervention leads to errors or adverse outcomes raises ethical and legal questions.\n", "\n", "7. **Workflow Integration and Resistance to Change** \n", " - Healthcare providers often have established workflows and may resist adopting autonomous AI agents if integration is burdensome or disrupts patient care.\n", "\n", "8. **Interdisciplinary Collaboration Complexity** \n", " - Successful AI in healthcare requires collaboration across clinicians, data scientists, IT specialists, and administrators, which can be difficult to coordinate.\n", "\n", "9. **High Costs of Development and Maintenance** \n", " - Developing, training, validating, deploying, and continuously updating AI agents in healthcare requires significant investment.\n", "\n", "10. **Handling Rare and Complex Cases** \n", " - AI models can struggle with rare diseases or complex clinical scenarios due to limited training data or nuanced decision-making requirements.\n", "\n", "11. **Bias and Fairness Issues** \n", " - If training data is biased or unrepresentative, AI agents may perform poorly on certain demographic groups, leading to disparities in care.\n", "\n", "12. **User Experience and Accessibility** \n", " - Designing AI interfaces that are intuitive for diverse users (doctors, nurses, patients) is essential but challenging.\n", "\n", "---\n", "\n", "Would you like to explore pain points for specific healthcare use cases (e.g., diagnostics, treatment planning, patient monitoring) or compare with another industry?\n" ] } ], "source": [ "messages = [{\"role\": \"user\", \"content\": f\"Please list the pain points of the business idea: { business_idea}\"}]\n", "\n", "# Then make the first call:\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-4.1-mini\",\n", " messages=messages\n", ")\n", "\n", "pain_points = response.choices[0].message.content\n", "\n", "print(pain_points)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Certainly! Healthcare is an excellent domain for Agentic AI solutions given its complexity and critical impact on human lives. Here’s a proposed Agentic AI solution tailored for healthcare, followed by a few specific high-potential use cases. If you'd like, we can then deep-dive into a particular use case.\n", "\n", "---\n", "\n", "### Proposed Agentic AI Solution: **Autonomous Clinical Decision Support Agent (ACDSA)**\n", "\n", "**Overview:**\n", "An Autonomous Clinical Decision Support Agent (ACDSA) is an AI-driven agent capable of ingesting and interpreting large volumes of heterogeneous healthcare data (EHRs, lab results, imaging, patient history, real-time vitals), autonomously generating diagnostic hypotheses, recommending personalized treatment plans, and dynamically adjusting care protocols based on patient response and new data. It communicates and collaborates with healthcare providers to optimize clinical workflows and patient outcomes.\n", "\n", "**Key Features:**\n", "\n", "- **Multimodal Data Integration:** Combines text, images, signals, and structured data for comprehensive patient assessment.\n", "- **Real-Time Monitoring & Alerts:** Continuously monitors patient vitals and lab results for early detection of deterioration.\n", "- **Personalized Treatment Optimization:** Suggests and updates treatment plans based on patient genotypes, comorbidities, and preferences.\n", "- **Explainable Recommendations:** Provides reasoning behind suggestions to aid physician trust and decision-making.\n", "- **Autonomous Workflow Management:** Interfaces with hospital systems to schedule tests, prescribe medications, and coordinate specialists.\n", "- **Regulatory & Ethical Compliance:** Monitors decision processes to ensure adherence to guidelines and patient safety.\n", "\n", "---\n", "\n", "### Specific Use Cases Within Healthcare for Agentic AI:\n", "\n", "1. **Critical Care & ICU Monitoring:**\n", " - Autonomously monitors patient vitals in Intensive Care Units.\n", " - Predicts sepsis, organ failure, or adverse events hours before clinical manifestation.\n", " - Initiates alerts and suggests intervention strategies to care teams.\n", "\n", "2. **Personalized Cancer Treatment Planning:**\n", " - Analyzes genomic data to predict tumor response to therapies.\n", " - Optimizes chemotherapy protocols considering side effects, drug interactions.\n", " - Coordinates multi-disciplinary input and dynamically adjusts plans over time.\n", "\n", "3. **Chronic Disease Management:**\n", " - Manages complex diabetic or cardiovascular patients by recommending medication adjustments based on glucose monitors or blood pressure readings.\n", " - Provides autonomous lifestyle coaching via chatbot interfaces.\n", "\n", "4. **Automated Radiology Interpretation:**\n", " - Reviews imaging scans and flags abnormalities with confidence scores.\n", " - Prioritizes urgent findings.\n", " - Generates preliminary reports to accelerate workflow.\n", "\n", "5. **Telemedicine & Virtual Health Assistants:**\n", " - Conducts autonomous symptom checking and patient triage.\n", " - Integrates with home health devices (wearables) for continuous remote monitoring.\n", " - Provides medication reminders and adherence tracking.\n", "\n", "---\n", "\n", "### Next Steps:\n", "\n", "- Would you like to explore any of these specific use cases further, focusing on system architecture, technology components, and integration strategies?\n", "- Or would you like to pivot and evaluate Agentic AI opportunities in a different industry?\n", "\n", "I’m happy to assist in drilling down or broadening the scope as you prefer!\n" ] } ], "source": [ "messages = [{\"role\": \"user\", \"content\": f\"Please propose the Agentic AI solution for the following business idea: {business_idea} \"}]\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-4.1-mini\",\n", " messages=messages\n", ")\n", "\n", "solution = response.choices[0].message.content\n", "\n", "print(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.2" } }, "nbformat": 4, "nbformat_minor": 2 }