From ae3458217fd020edac6ba1fcfe35c273fc912ad7 Mon Sep 17 00:00:00 2001 From: denis-samatov Date: Sun, 30 Aug 2026 23:24:36 +0700 Subject: [PATCH] Remove unused nest_asyncio and use top-level await in Copy of 5_tool_calling.ipynb In modern notebook environments, asyncio.run() often fails because an event loop is already running. This removes the nest_asyncio import/apply() calls and updates all relevant cells to use await directly instead, which is the standard practice in that situation. Note: this diff also reformats the notebook's JSON (pretty-printed instead of minified), a side effect of editing it programmatically. --- notebooks/Copy of 5_tool_calling.ipynb | 1588 +++++++++++++++++++++++- 1 file changed, 1587 insertions(+), 1 deletion(-) diff --git a/notebooks/Copy of 5_tool_calling.ipynb b/notebooks/Copy of 5_tool_calling.ipynb index 9b52bc45..8011358c 100644 --- a/notebooks/Copy of 5_tool_calling.ipynb +++ b/notebooks/Copy of 5_tool_calling.ipynb @@ -1 +1,1587 @@ -{"cells":[{"cell_type":"markdown","id":"9496ebb1-25a6-40e8-bf4b-99884bc4cb2e","metadata":{"id":"9496ebb1-25a6-40e8-bf4b-99884bc4cb2e"},"source":["# 1. Install Dependencies"]},{"cell_type":"code","execution_count":null,"id":"t8nVkMERCbWP","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:28.010799Z","iopub.status.busy":"2025-07-25T06:23:28.010543Z","iopub.status.idle":"2025-07-25T06:23:28.350963Z","shell.execute_reply":"2025-07-25T06:23:28.350466Z"},"id":"t8nVkMERCbWP","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1753424899816,"user_tz":-330,"elapsed":59759,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}},"outputId":"d6eea687-4b44-43d1-c82a-ccfd8682037a"},"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m40.3/40.3 kB\u001b[0m \u001b[31m1.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m42.8/42.8 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m61.0/61.0 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.3/44.3 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n"," Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n"," Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m48.5/48.5 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m47.8/47.8 kB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m366.3/366.3 kB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m35.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m8.6/8.6 MB\u001b[0m \u001b[31m84.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.4/16.4 MB\u001b[0m \u001b[31m69.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m239.3/239.3 kB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m19.5/19.5 MB\u001b[0m \u001b[31m74.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.4/1.4 MB\u001b[0m \u001b[31m51.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m218.1/218.1 kB\u001b[0m \u001b[31m14.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m335.7/335.7 kB\u001b[0m \u001b[31m22.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m119.5/119.5 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m158.5/158.5 kB\u001b[0m \u001b[31m11.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m65.6/65.6 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m72.5/72.5 kB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m119.4/119.4 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m201.6/201.6 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m60.0/60.0 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.6/5.6 MB\u001b[0m \u001b[31m101.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m756.0/756.0 kB\u001b[0m \u001b[31m44.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m64.8/64.8 kB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m236.0/236.0 kB\u001b[0m \u001b[31m15.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m18.7/18.7 MB\u001b[0m \u001b[31m73.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.1/79.1 kB\u001b[0m \u001b[31m4.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m284.2/284.2 kB\u001b[0m \u001b[31m18.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.5/45.5 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m229.5/229.5 kB\u001b[0m \u001b[31m13.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m103.8/103.8 kB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m53.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.6/101.6 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m105.4/105.4 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.2/71.2 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.2/45.2 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m45.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m459.8/459.8 kB\u001b[0m \u001b[31m27.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m6.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m51.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.0/4.0 MB\u001b[0m \u001b[31m75.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m453.1/453.1 kB\u001b[0m \u001b[31m24.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n","\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","google-colab 1.0.0 requires requests==2.32.3, but you have requests 2.32.4 which is incompatible.\n","google-generativeai 0.8.5 requires google-ai-generativelanguage==0.6.15, but you have google-ai-generativelanguage 0.6.18 which is incompatible.\u001b[0m\u001b[31m\n","\u001b[0m"]}],"source":["!pip install -q -U \"dotenv==0.9.9\" \"langchain-google-genai==2.1.8\" \"crewai==0.150.0\" \"google-adk==1.8.0\""]},{"cell_type":"markdown","id":"mw5jyVEQHf-H","metadata":{"id":"mw5jyVEQHf-H"},"source":["# 2. Import Packages"]},{"cell_type":"code","execution_count":null,"id":"O4rGR_1FHgnP","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:28.353166Z","iopub.status.busy":"2025-07-25T06:23:28.353001Z","iopub.status.idle":"2025-07-25T06:23:32.724402Z","shell.execute_reply":"2025-07-25T06:23:32.724071Z"},"id":"O4rGR_1FHgnP"},"outputs":[],"source":["import os, getpass\n","import asyncio\n","import nest_asyncio\n","from typing import List\n","from dotenv import load_dotenv\n","import logging\n","\n","\n","from langchain_google_genai import ChatGoogleGenerativeAI\n","from langchain_core.prompts import ChatPromptTemplate\n","from langchain_core.tools import tool as langchain_tool\n","from langchain.agents import create_tool_calling_agent, AgentExecutor\n","\n","from crewai import Agent as CrewAgent, Task, Crew\n","from crewai.tools import tool as crew_tool\n","\n","from google.adk.agents import Agent as ADKAgent, LlmAgent\n","from google.adk.runners import Runner\n","from google.adk.sessions import InMemorySessionService\n","from google.adk.tools import google_search\n","from google.adk.code_executors import BuiltInCodeExecutor\n","from google.genai import types"]},{"cell_type":"code","execution_count":null,"id":"cXTBfGe8IppO","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:32.725713Z","iopub.status.busy":"2025-07-25T06:23:32.725584Z","iopub.status.idle":"2025-07-25T06:23:32.727230Z","shell.execute_reply":"2025-07-25T06:23:32.727023Z"},"id":"cXTBfGe8IppO"},"outputs":[],"source":["# Basic logging setup helps in debugging and tracking to execution.\n","logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n"]},{"cell_type":"markdown","id":"3nq-mQuMHaym","metadata":{"id":"3nq-mQuMHaym"},"source":["# 2. Setup API Keys"]},{"cell_type":"code","execution_count":null,"id":"2b4848df-095b-4ddd-81ac-5949ab25c30e","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"execution":{"iopub.execute_input":"2025-07-25T06:23:32.728261Z","iopub.status.busy":"2025-07-25T06:23:32.728200Z","iopub.status.idle":"2025-07-25T06:23:32.729503Z","shell.execute_reply":"2025-07-25T06:23:32.729287Z"},"id":"2b4848df-095b-4ddd-81ac-5949ab25c30e","outputId":"c9d5b34e-cdff-4501-eeaf-236d3ceb017c","executionInfo":{"status":"ok","timestamp":1753424956043,"user_tz":-330,"elapsed":15066,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}}},"outputs":[{"name":"stdout","output_type":"stream","text":["Enter your Google API key: ··········\n","Enter your OpenAI API key: ··········\n"]}],"source":["# UNCOMMENT\n","# Prompt the user securely and set API keys as an environment variables\n","os.environ[\"GOOGLE_API_KEY\"] = getpass.getpass(\"Enter your Google API key: \")\n","os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"Enter your OpenAI API key: \")"]},{"cell_type":"markdown","id":"cd624f3b-4e5d-4a76-896e-1d9076c64727","metadata":{"id":"cd624f3b-4e5d-4a76-896e-1d9076c64727"},"source":["# 3. LangChain"]},{"cell_type":"markdown","id":"DgVRXVDbHuZA","metadata":{"id":"DgVRXVDbHuZA"},"source":["## 3.1 Setup LLM"]},{"cell_type":"code","execution_count":null,"id":"d5VMXzAvHxiE","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"execution":{"iopub.execute_input":"2025-07-25T06:23:32.730500Z","iopub.status.busy":"2025-07-25T06:23:32.730444Z","iopub.status.idle":"2025-07-25T06:23:32.756682Z","shell.execute_reply":"2025-07-25T06:23:32.756489Z"},"id":"d5VMXzAvHxiE","outputId":"0279289e-49ac-47b2-aced-4fd6ae009e62","executionInfo":{"status":"ok","timestamp":1753424956075,"user_tz":-330,"elapsed":36,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["✅ Language model initialized: models/gemini-2.0-flash\n"]}],"source":["try:\n"," # A model with function/tool calling capabilities is required.\n"," llm = ChatGoogleGenerativeAI(model=\"gemini-2.0-flash\", temperature=0)\n"," print(f\"✅ Language model initialized: {llm.model}\")\n","except Exception as e:\n"," print(f\"🛑 Error initializing language model: {e}\")\n"," llm = None"]},{"cell_type":"markdown","id":"90EOPzFTH33S","metadata":{"id":"90EOPzFTH33S"},"source":["## 3.2 Define Search Tool"]},{"cell_type":"code","execution_count":null,"id":"jJacHepFH2-_","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:32.757701Z","iopub.status.busy":"2025-07-25T06:23:32.757639Z","iopub.status.idle":"2025-07-25T06:23:32.760591Z","shell.execute_reply":"2025-07-25T06:23:32.760378Z"},"id":"jJacHepFH2-_"},"outputs":[],"source":["# --- Define a Tool ---\n","@langchain_tool\n","def search_information(query: str) -> str:\n"," \"\"\"\n"," Provides factual information on a given topic. Use this tool to find answers to phrases\n"," like 'capital of France' or 'weather in London?'.\n"," \"\"\"\n"," print(f\"\\n--- 🛠️ Tool Called: search_information with query: '{query}' ---\")\n"," # Simulate a search tool with a dictionary of predefined results.\n"," simulated_results = {\n"," \"weather in london\": \"The weather in London is currently cloudy with a temperature of 15°C.\",\n"," \"capital of france\": \"The capital of France is Paris.\",\n"," \"population of earth\": \"The estimated population of Earth is around 8 billion people.\",\n"," \"tallest mountain\": \"Mount Everest is the tallest mountain above sea level.\",\n"," \"default\": f\"Simulated search result for '{query}': No specific information found, but the topic seems interesting.\"\n"," }\n"," result = simulated_results.get(query.lower(), simulated_results[\"default\"])\n"," print(f\"--- TOOL RESULT: {result} ---\")\n"," return result\n","\n","\n","tools = [search_information]"]},{"cell_type":"markdown","id":"_p91Mx8yH_w-","metadata":{"id":"_p91Mx8yH_w-"},"source":["## 3.3 Tool Calling Agent"]},{"cell_type":"code","execution_count":null,"id":"8rOcIPQ0ICZK","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:32.762254Z","iopub.status.busy":"2025-07-25T06:23:32.762195Z","iopub.status.idle":"2025-07-25T06:23:32.765863Z","shell.execute_reply":"2025-07-25T06:23:32.765680Z"},"id":"8rOcIPQ0ICZK"},"outputs":[],"source":["# --- Create a Tool-Calling Agent ---\n","if llm:\n"," # This prompt template requires an `agent_scratchpad` placeholder for the agent's internal steps.\n"," agent_prompt = ChatPromptTemplate.from_messages([\n"," (\"system\", \"You are a helpful assistant.\"),\n"," (\"human\", \"{input}\"),\n"," (\"placeholder\", \"{agent_scratchpad}\"),\n"," ])\n","\n","\n"," # Create the agent, binding the LLM, tools, and prompt together.\n"," agent = create_tool_calling_agent(llm, tools, agent_prompt)\n","\n","\n"," # AgentExecutor is the runtime that invokes the agent and executes the chosen tools.\n"," # The 'tools' argument is not needed here as they are already bound to the agent.\n"," agent_executor = AgentExecutor(agent=agent, verbose=True, tools=tools)"]},{"cell_type":"markdown","id":"gGZK5EWIIdwx","metadata":{"id":"gGZK5EWIIdwx"},"source":["## 3.4 Run Agent"]},{"cell_type":"code","execution_count":null,"id":"b862b9e3-61a8-4654-9ffd-4128fce28f4b","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"execution":{"iopub.execute_input":"2025-07-25T06:23:32.766832Z","iopub.status.busy":"2025-07-25T06:23:32.766770Z","iopub.status.idle":"2025-07-25T06:23:37.108919Z","shell.execute_reply":"2025-07-25T06:23:37.108214Z"},"id":"b862b9e3-61a8-4654-9ffd-4128fce28f4b","outputId":"c96038a1-cfd6-4531-8221-752c01bcbd70","scrolled":true,"executionInfo":{"status":"ok","timestamp":1753424957618,"user_tz":-330,"elapsed":1465,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["\n","--- 🏃 Running Agent with Query: 'What is the capital of France?' ---\n","\n","--- 🏃 Running Agent with Query: 'What's the weather like in London?' ---\n","\n","--- 🏃 Running Agent with Query: 'Tell me something about dogs.' ---\n","\n","\n","\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n","\n","\n","\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n","\n","\n","\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n","\u001b[32;1m\u001b[1;3m\n","Invoking: `search_information` with `{'query': 'weather in London'}`\n","\n","\n","\u001b[0m\n","--- 🛠️ Tool Called: search_information with query: 'weather in London' ---\n","--- TOOL RESULT: The weather in London is currently cloudy with a temperature of 15°C. ---\n","\u001b[36;1m\u001b[1;3mThe weather in London is currently cloudy with a temperature of 15°C.\u001b[0m\u001b[32;1m\u001b[1;3m\n","Invoking: `search_information` with `{'query': 'characteristics of dogs'}`\n","\n","\n","\u001b[0m\n","--- 🛠️ Tool Called: search_information with query: 'characteristics of dogs' ---\n","--- TOOL RESULT: Simulated search result for 'characteristics of dogs': No specific information found, but the topic seems interesting. ---\n","\u001b[36;1m\u001b[1;3mSimulated search result for 'characteristics of dogs': No specific information found, but the topic seems interesting.\u001b[0m\u001b[32;1m\u001b[1;3m\n","Invoking: `search_information` with `{'query': 'capital of France'}`\n","\n","\n","\u001b[0m\n","--- 🛠️ Tool Called: search_information with query: 'capital of France' ---\n","--- TOOL RESULT: The capital of France is Paris. ---\n","\u001b[36;1m\u001b[1;3mThe capital of France is Paris.\u001b[0m\u001b[32;1m\u001b[1;3mThe weather in London is currently cloudy with a temperature of 15°C.\n","\u001b[0m\n","\n","\u001b[1m> Finished chain.\u001b[0m\n","\n","--- ✅ Final Agent Response ---\n","The weather in London is currently cloudy with a temperature of 15°C.\n","\n","\u001b[32;1m\u001b[1;3mThe capital of France is Paris.\n","\u001b[0m\n","\n","\u001b[1m> Finished chain.\u001b[0m\n","\n","--- ✅ Final Agent Response ---\n","The capital of France is Paris.\n","\n","\u001b[32;1m\u001b[1;3mI'm sorry, I don't have enough information about dogs to fulfill your request. I can try a different query if you like. For example, I could search for different breeds of dogs, or the history of dogs.\u001b[0m\n","\n","\u001b[1m> Finished chain.\u001b[0m\n","\n","--- ✅ Final Agent Response ---\n","I'm sorry, I don't have enough information about dogs to fulfill your request. I can try a different query if you like. For example, I could search for different breeds of dogs, or the history of dogs.\n"]}],"source":["async def run_agent_with_tool(query: str):\n"," \"\"\"Invokes the agent executor with a query and prints the final response.\"\"\"\n"," print(f\"\\n--- 🏃 Running Agent with Query: '{query}' ---\")\n"," try:\n"," response = await agent_executor.ainvoke({\"input\": query})\n"," print(\"\\n--- ✅ Final Agent Response ---\")\n"," print(response[\"output\"])\n"," except Exception as e:\n"," print(f\"\\n🛑 An error occurred during agent execution: {e}\")\n","\n","\n","async def main():\n"," \"\"\"Runs all agent queries concurrently.\"\"\"\n"," tasks = [\n"," run_agent_with_tool(\"What is the capital of France?\"),\n"," run_agent_with_tool(\"What's the weather like in London?\"),\n"," run_agent_with_tool(\"Tell me something about dogs.\") # Should trigger the default tool response\n"," ]\n"," await asyncio.gather(*tasks)\n","\n","\n","\n","nest_asyncio.apply()\n","asyncio.run(main())"]},{"cell_type":"markdown","id":"8aa008f4-94a2-4a8b-8165-f6fd213c0d40","metadata":{"id":"8aa008f4-94a2-4a8b-8165-f6fd213c0d40"},"source":["# 4. Crew AI"]},{"cell_type":"markdown","id":"2uSUtzdbJRZQ","metadata":{"id":"2uSUtzdbJRZQ"},"source":["## 4.1 Define Stock Price Search Tool"]},{"cell_type":"code","execution_count":null,"id":"31df7900-9b2b-456c-b018-6a32db662bdc","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:37.112253Z","iopub.status.busy":"2025-07-25T06:23:37.111995Z","iopub.status.idle":"2025-07-25T06:23:37.119765Z","shell.execute_reply":"2025-07-25T06:23:37.119211Z"},"id":"31df7900-9b2b-456c-b018-6a32db662bdc"},"outputs":[],"source":["# --- 1. Refactored Tool: Returns Clean Data ---\n","# The tool now returns raw data (a float) or raises a standard Python error.\n","# This makes it more reusable and forces the agent to handle outcomes properly.\n","@crew_tool(\"Stock Price Lookup Tool\")\n","def get_stock_price(ticker: str) -> float:\n"," \"\"\"\n"," Fetches the latest simulated stock price for a given stock ticker symbol.\n"," Returns the price as a float. Raises a ValueError if the ticker is not found.\n"," \"\"\"\n"," logging.info(f\"Tool Call: get_stock_price for ticker '{ticker}'\")\n"," simulated_prices = {\n"," \"AAPL\": 178.15,\n"," \"GOOGL\": 1750.30,\n"," \"MSFT\": 425.50,\n"," }\n"," price = simulated_prices.get(ticker.upper())\n","\n","\n"," if price is not None:\n"," return price\n"," else:\n"," # Raising a specific error is better than returning a string.\n"," # The agent is equipped to handle exceptions and can decide on the next action.\n"," raise ValueError(f\"Simulated price for ticker '{ticker.upper()}' not found.\")\n","\n","\n","\n","\n"]},{"cell_type":"markdown","id":"WMqIW8n_JrkO","metadata":{"id":"WMqIW8n_JrkO"},"source":["## 4.2 Setup Crew Entities"]},{"cell_type":"code","execution_count":null,"id":"XFd2tKTRJh72","metadata":{"execution":{"iopub.execute_input":"2025-07-25T06:23:37.122182Z","iopub.status.busy":"2025-07-25T06:23:37.121984Z","iopub.status.idle":"2025-07-25T06:23:37.129796Z","shell.execute_reply":"2025-07-25T06:23:37.129431Z"},"id":"XFd2tKTRJh72"},"outputs":[],"source":["# --- 2. Define the Agent ---\n","# The agent definition remains the same, but it will now leverage the improved tool.\n","financial_analyst_agent = CrewAgent(\n"," role='Senior Financial Analyst',\n"," goal='Analyze stock data using provided tools and report key prices.',\n"," backstory=\"You are an experienced financial analyst adept at using data sources to find stock information. You provide clear, direct answers.\",\n"," verbose=True,\n"," tools=[get_stock_price],\n"," # Allowing delegation can be useful, but is not necessary for this simple task.\n"," allow_delegation=False,\n",")\n","\n","\n","# --- 3. Refined Task: Clearer Instructions and Error Handling ---\n","# The task description is more specific and guides the agent on how to react\n","# to both successful data retrieval and potential errors.\n","analyze_aapl_task = Task(\n"," description=(\n"," \"What is the current simulated stock price for Apple (ticker: AAPL)? \"\n"," \"Use the 'Stock Price Lookup Tool' to find it. \"\n"," \"If the ticker is not found, you must report that you were unable to retrieve the price.\"\n"," ),\n"," expected_output=(\n"," \"A single, clear sentence stating the simulated stock price for AAPL. \"\n"," \"For example: 'The simulated stock price for AAPL is $178.15.' \"\n"," \"If the price cannot be found, state that clearly.\"\n"," ),\n"," agent=financial_analyst_agent,\n",")\n","\n","\n","# --- 4. Formulate the Crew ---\n","# The crew orchestrates how the agent and task work together.\n","financial_crew = Crew(\n"," agents=[financial_analyst_agent],\n"," tasks=[analyze_aapl_task],\n"," verbose=True # Set to False for less detailed logs in production\n",")\n"]},{"cell_type":"markdown","id":"TBsi1L_oJmZi","metadata":{"id":"TBsi1L_oJmZi"},"source":["## 4.3 Run Crew Agent"]},{"cell_type":"code","execution_count":null,"id":"ISnpTbLBJmzk","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000,"referenced_widgets":["337f450966f840698abaeef5ffd42d9e","ae1548032c064897958efbe27ed668d1","e841c93064a441a4be2e5a303acd6b85","5cf2dd4cd95042b1bc3ef3a45ab161a8"]},"execution":{"iopub.execute_input":"2025-07-25T06:23:37.131761Z","iopub.status.busy":"2025-07-25T06:23:37.131605Z","iopub.status.idle":"2025-07-25T06:23:39.462993Z","shell.execute_reply":"2025-07-25T06:23:39.462634Z"},"id":"ISnpTbLBJmzk","outputId":"11b6e821-d14d-4e9b-b0e6-399ff96fd024","executionInfo":{"status":"ok","timestamp":1753424960514,"user_tz":-330,"elapsed":2821,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["\n","## Starting the Financial Crew...\n","---------------------------------\n"]},{"output_type":"display_data","data":{"text/plain":["\u001b[36m╭─\u001b[0m\u001b[36m───────────────────────────────────────────\u001b[0m\u001b[36m Crew Execution Started \u001b[0m\u001b[36m────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[1;36mCrew Execution Started\u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[37mName: \u001b[0m\u001b[36mcrew\u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[37mID: \u001b[0m\u001b[36m22e3da43-7199-40fd-8817-9aa4bc877eac\u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[37mTool Args: \u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m│\u001b[0m \u001b[36m│\u001b[0m\n","\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭──────────────────────────────────────────── Crew Execution Started ─────────────────────────────────────────────╮\n","                                                                                                                 \n","  Crew Execution Started                                                                                         \n","  Name: crew                                                                                                     \n","  ID: 22e3da43-7199-40fd-8817-9aa4bc877eac                                                                       \n","  Tool Args:                                                                                                     \n","                                                                                                                 \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\n"],"text/html":["
\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[],"text/html":["
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[35m╭─\u001b[0m\u001b[35m──────────────────────────────────────────────\u001b[0m\u001b[35m 🤖 Agent Started \u001b[0m\u001b[35m───────────────────────────────────────────────\u001b[0m\u001b[35m─╮\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[1;92mSenior Financial Analyst\u001b[0m                                                                                \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m  \u001b[37mTask: \u001b[0m\u001b[92mWhat is the current simulated stock price for Apple (ticker: AAPL)? Use the 'Stock Price Lookup Tool' \u001b[0m   \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m  \u001b[92mto find it. If the ticker is not found, you must report that you were unable to retrieve the price.\u001b[0m            \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭─────────────────────────────────────────────── 🤖 Agent Started ────────────────────────────────────────────────╮\n","                                                                                                                 \n","  Agent: Senior Financial Analyst                                                                                \n","                                                                                                                 \n","  Task: What is the current simulated stock price for Apple (ticker: AAPL)? Use the 'Stock Price Lookup Tool'    \n","  to find it. If the ticker is not found, you must report that you were unable to retrieve the price.            \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\n"],"text/html":["
\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["Output()"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"337f450966f840698abaeef5ffd42d9e"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[],"text/html":["
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[35m╭─\u001b[0m\u001b[35m───────────────────────────────────────────\u001b[0m\u001b[35m 🔧 Agent Tool Execution \u001b[0m\u001b[35m───────────────────────────────────────────\u001b[0m\u001b[35m─╮\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[1;92mSenior Financial Analyst\u001b[0m                                                                                \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m  \u001b[37mThought: \u001b[0m\u001b[92mThought: I need to find the current simulated stock price for Apple (ticker: AAPL).\u001b[0m                   \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m  \u001b[37mUsing Tool: \u001b[0m\u001b[1;92mStock Price Lookup Tool\u001b[0m                                                                            \u001b[35m│\u001b[0m\n","\u001b[35m│\u001b[0m                                                                                                                 \u001b[35m│\u001b[0m\n","\u001b[35m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭──────────────────────────────────────────── 🔧 Agent Tool Execution ────────────────────────────────────────────╮\n","                                                                                                                 \n","  Agent: Senior Financial Analyst                                                                                \n","                                                                                                                 \n","  Thought: Thought: I need to find the current simulated stock price for Apple (ticker: AAPL).                   \n","                                                                                                                 \n","  Using Tool: Stock Price Lookup Tool                                                                            \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[34m╭─\u001b[0m\u001b[34m─────────────────────────────────────────────────\u001b[0m\u001b[34m Tool Input \u001b[0m\u001b[34m──────────────────────────────────────────────────\u001b[0m\u001b[34m─╮\u001b[0m\n","\u001b[34m│\u001b[0m \u001b[34m│\u001b[0m\n","\u001b[34m│\u001b[0m \u001b[38;2;230;219;116;49m\"{\\\"ticker\\\": \\\"AAPL\\\"}\"\u001b[0m \u001b[34m│\u001b[0m\n","\u001b[34m│\u001b[0m \u001b[34m│\u001b[0m\n","\u001b[34m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭────────────────────────────────────────────────── Tool Input ───────────────────────────────────────────────────╮\n","                                                                                                                 \n","  \"{\\\"ticker\\\": \\\"AAPL\\\"}\"                                                                                       \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[32m╭─\u001b[0m\u001b[32m─────────────────────────────────────────────────\u001b[0m\u001b[32m Tool Output \u001b[0m\u001b[32m─────────────────────────────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[92m178.15\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭────────────────────────────────────────────────── Tool Output ──────────────────────────────────────────────────╮\n","                                                                                                                 \n","  178.15                                                                                                         \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\n"],"text/html":["
\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["Output()"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"e841c93064a441a4be2e5a303acd6b85"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[],"text/html":["
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[32m╭─\u001b[0m\u001b[32m────────────────────────────────────────────\u001b[0m\u001b[32m ✅ Agent Final Answer \u001b[0m\u001b[32m────────────────────────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n","\u001b[32m│\u001b[0m                                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[1;92mSenior Financial Analyst\u001b[0m                                                                                \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m                                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[37mFinal Answer:\u001b[0m                                                                                                  \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[92mThe simulated stock price for AAPL is $178.15.\u001b[0m                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m                                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭───────────────────────────────────────────── ✅ Agent Final Answer ─────────────────────────────────────────────╮\n","                                                                                                                 \n","  Agent: Senior Financial Analyst                                                                                \n","                                                                                                                 \n","  Final Answer:                                                                                                  \n","  The simulated stock price for AAPL is $178.15.                                                                 \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\n"],"text/html":["
\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":[],"text/html":["
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[32m╭─\u001b[0m\u001b[32m───────────────────────────────────────────────\u001b[0m\u001b[32m Task Completion \u001b[0m\u001b[32m───────────────────────────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n","\u001b[32m│\u001b[0m                                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[1;32mTask Completed\u001b[0m                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[37mName: \u001b[0m\u001b[32m3ae83180-2ac2-456f-aff6-2ff30a3e9f89\u001b[0m                                                                     \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[32mSenior Financial Analyst\u001b[0m                                                                                \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m  \u001b[37mTool Args: \u001b[0m                                                                                                    \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m                                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m                                                                                                                 \u001b[32m│\u001b[0m\n","\u001b[32m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭──────────────────────────────────────────────── Task Completion ────────────────────────────────────────────────╮\n","                                                                                                                 \n","  Task Completed                                                                                                 \n","  Name: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89                                                                     \n","  Agent: Senior Financial Analyst                                                                                \n","  Tool Args:                                                                                                     \n","                                                                                                                 \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\n"],"text/html":["
\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\u001b[32m╭─\u001b[0m\u001b[32m───────────────────────────────────────────────\u001b[0m\u001b[32m Crew Completion \u001b[0m\u001b[32m───────────────────────────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[1;32mCrew Execution Completed\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[37mName: \u001b[0m\u001b[32mcrew\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[37mID: \u001b[0m\u001b[32m22e3da43-7199-40fd-8817-9aa4bc877eac\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[37mTool Args: \u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[37mFinal Output: The simulated stock price for AAPL is $178.15.\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m│\u001b[0m \u001b[32m│\u001b[0m\n","\u001b[32m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"],"text/html":["
╭──────────────────────────────────────────────── Crew Completion ────────────────────────────────────────────────╮\n","                                                                                                                 \n","  Crew Execution Completed                                                                                       \n","  Name: crew                                                                                                     \n","  ID: 22e3da43-7199-40fd-8817-9aa4bc877eac                                                                       \n","  Tool Args:                                                                                                     \n","  Final Output: The simulated stock price for AAPL is $178.15.                                                   \n","                                                                                                                 \n","                                                                                                                 \n","╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n","
\n"]},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["\n"],"text/html":["
\n","
\n"]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["\n","---------------------------------\n","## Crew execution finished.\n","\n","Final Result:\n"," The simulated stock price for AAPL is $178.15.\n"]}],"source":["\n","\n","# --- 5. Run the Crew within a Main Execution Block ---\n","# Using a __name__ == \"__main__\": block is a standard Python best practice.\n","def main():\n"," \"\"\"Main function to run the crew.\"\"\"\n"," # Check for API key before starting to avoid runtime errors.\n"," if not os.environ.get(\"OPENAI_API_KEY\"):\n"," print(\"ERROR: The OPENAI_API_KEY environment variable is not set.\")\n"," print(\"Please set it before running the script.\")\n"," return\n","\n","\n"," print(\"\\n## Starting the Financial Crew...\")\n"," print(\"---------------------------------\")\n","\n"," # The kickoff method starts the execution.\n"," result = financial_crew.kickoff()\n","\n","\n"," print(\"\\n---------------------------------\")\n"," print(\"## Crew execution finished.\")\n"," print(\"\\nFinal Result:\\n\", result)\n","\n","\n","if __name__ == \"__main__\":\n"," main()\n"]},{"cell_type":"markdown","id":"01de8db8-25f9-420f-9698-8e93c8ab98fe","metadata":{"id":"01de8db8-25f9-420f-9698-8e93c8ab98fe"},"source":["# 5. Google Agent Development Kit (ADK)"]},{"cell_type":"markdown","id":"e04c9ab5-bbfe-4eb3-aa2d-64f8bfcd97b3","metadata":{"id":"e04c9ab5-bbfe-4eb3-aa2d-64f8bfcd97b3"},"source":["## 5.1 Agent with Search Tool"]},{"cell_type":"code","execution_count":null,"id":"350b5cb0-666f-46a6-b0b3-4d3c5df6c760","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"execution":{"iopub.execute_input":"2025-07-25T06:23:39.464863Z","iopub.status.busy":"2025-07-25T06:23:39.464725Z","iopub.status.idle":"2025-07-25T06:23:45.291775Z","shell.execute_reply":"2025-07-25T06:23:45.291253Z"},"id":"350b5cb0-666f-46a6-b0b3-4d3c5df6c760","outputId":"59ddea39-5066-4858-f458-5765f4d87a09","scrolled":true,"executionInfo":{"status":"ok","timestamp":1753424964011,"user_tz":-330,"elapsed":3496,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["Agent Response: Here's a summary of recent AI news:\n","\n","* **AI and Job Markets**: Sam Altman (OpenAI CEO) has warned of potential job losses and national security threats due to AI. Research indicates AI is changing the job landscape, prompting nations to prepare their workforces.\n","* **AI Models and Advancements**: Google made AI models faster and cheaper. Google's Gemini 2.5 model aims for 'intelligence per dollar'. Google also introduced AlphaGenome for understanding the human genome and launched Weather Lab to support better tropical cyclone prediction with AI.\n","* **AI in Different Sectors**: AI is rewriting the rules of the insurance industry. AI is helping students learn and scientists understand the human body better.\n","* **AI Ethics and Safety**: There are growing concerns about AI safety. A study revealed that even the most powerful AI models can make basic errors in navigating ethical medical decisions.\n","* **Talent Acquisition**: Meta is actively hiring AI researchers, including those from Apple.\n","* **Quantum Computing**: There have been breakthroughs in quantum computing, including achieving an exponential speedup and making \"magic states\" easier to create.\n","\n"]}],"source":["# Define variables required for Session setup and Agent execution\n","APP_NAME=\"Google Search_agent\"\n","USER_ID=\"user1234\"\n","SESSION_ID=\"1234\"\n","\n","\n","\n","# Define Agent with access to search tool\n","root_agent = ADKAgent(\n"," name=\"basic_search_agent\",\n"," model=\"gemini-2.0-flash-exp\",\n"," description=\"Agent to answer questions using Google Search.\",\n"," instruction=\"I can answer your questions by searching the internet. Just ask me anything!\",\n"," tools=[google_search] # Google Search is a pre-built tool to perform Google searches.\n",")\n","\n","\n","\n","\n","# Agent Interaction\n","async def call_agent(query):\n"," \"\"\"\n"," Helper function to call the agent with a query.\n"," \"\"\"\n","\n"," # Session and Runner\n"," session_service = InMemorySessionService()\n"," session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)\n"," runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)\n","\n"," content = types.Content(role='user', parts=[types.Part(text=query)])\n"," events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content)\n","\n","\n"," for event in events:\n"," if event.is_final_response():\n"," final_response = event.content.parts[0].text\n"," print(\"Agent Response: \", final_response)\n","\n","nest_asyncio.apply()\n","\n","asyncio.run(call_agent(\"what's the latest ai news?\"))"]},{"cell_type":"markdown","id":"6dde5f6e-4d28-4015-842d-5b53beb5b638","metadata":{"id":"6dde5f6e-4d28-4015-842d-5b53beb5b638"},"source":["## 5.2 Agent with Code Tool"]},{"cell_type":"code","execution_count":null,"id":"d0e485c0-98a8-49a8-a373-7832c500b955","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"execution":{"iopub.execute_input":"2025-07-25T06:23:45.294602Z","iopub.status.busy":"2025-07-25T06:23:45.294355Z","iopub.status.idle":"2025-07-25T06:24:04.644288Z","shell.execute_reply":"2025-07-25T06:24:04.642573Z"},"id":"d0e485c0-98a8-49a8-a373-7832c500b955","outputId":"08de17eb-3506-4319-baaa-3639a41b1238","scrolled":true,"executionInfo":{"status":"ok","timestamp":1753424981662,"user_tz":-330,"elapsed":17645,"user":{"displayName":"Shishir Suman","userId":"15686497179682448712"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["\n","--- Running Query: Calculate the value of (5 + 7) * 3 ---\n"]},{"output_type":"stream","name":"stderr","text":["WARNING:google_genai.types:Warning: there are non-text parts in the response: ['executable_code', 'code_execution_result'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.\n"]},{"output_type":"stream","name":"stdout","text":["Event ID: 23696e40-5e9d-4da3-89f5-032971769c2b, Author: calculator_agent\n"," Debug: Agent generated code:\n","```python\n","print((5 + 7) * 3)\n","\n","```\n"," Debug: Code Execution Result: Outcome.OUTCOME_OK - Output:\n","36\n","\n"," Text: '36'\n","==> Final Agent Response: 36\n","\n","------------------------------\n","\n","--- Running Query: What is 10 factorial? ---\n"]},{"output_type":"stream","name":"stderr","text":["WARNING:google_genai.types:Warning: there are non-text parts in the response: ['executable_code', 'code_execution_result'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.\n"]},{"output_type":"stream","name":"stdout","text":["Event ID: 11d25af6-8864-497f-8846-7c054503a100, Author: calculator_agent\n"," Debug: Agent generated code:\n","```python\n","import math\n","print(math.factorial(10))\n","\n","```\n"," Debug: Code Execution Result: Outcome.OUTCOME_OK - Output:\n","3628800\n","\n"," Text: '3628800'\n","==> Final Agent Response: 3628800\n","\n","------------------------------\n"]}],"source":["# Define variables required for Session setup and Agent execution\n","APP_NAME=\"calculator\"\n","USER_ID=\"user1234\"\n","SESSION_ID=\"session_code_exec_async\"\n","\n","\n","# Agent Definition\n","code_agent = LlmAgent(\n"," name=\"calculator_agent\",\n"," model=\"gemini-2.0-flash\",\n"," code_executor=BuiltInCodeExecutor(),\n"," instruction=\"\"\"You are a calculator agent.\n"," When given a mathematical expression, write and execute Python code to calculate the result.\n"," Return only the final numerical result as plain text, without markdown or code blocks.\n"," \"\"\",\n"," description=\"Executes Python code to perform calculations.\",\n",")\n","\n","# Agent Interaction (Async)\n","async def call_agent_async(query):\n","\n"," # Session and Runner\n"," session_service = InMemorySessionService()\n"," session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)\n"," runner = Runner(agent=code_agent, app_name=APP_NAME, session_service=session_service)\n","\n"," content = types.Content(role='user', parts=[types.Part(text=query)])\n"," print(f\"\\n--- Running Query: {query} ---\")\n"," final_response_text = \"No final text response captured.\"\n"," try:\n"," # Use run_async\n"," async for event in runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=content):\n"," print(f\"Event ID: {event.id}, Author: {event.author}\")\n","\n"," # --- Check for specific parts FIRST ---\n"," # has_specific_part = False\n"," if event.content and event.content.parts and event.is_final_response():\n"," for part in event.content.parts: # Iterate through all parts\n"," if part.executable_code:\n"," # Access the actual code string via .code\n"," print(f\" Debug: Agent generated code:\\n```python\\n{part.executable_code.code}\\n```\")\n"," has_specific_part = True\n"," elif part.code_execution_result:\n"," # Access outcome and output correctly\n"," print(f\" Debug: Code Execution Result: {part.code_execution_result.outcome} - Output:\\n{part.code_execution_result.output}\")\n"," has_specific_part = True\n"," # Also print any text parts found in any event for debugging\n"," elif part.text and not part.text.isspace():\n"," print(f\" Text: '{part.text.strip()}'\")\n"," # Do not set has_specific_part=True here, as we want the final response logic below\n","\n"," # --- Check for final response AFTER specific parts ---\n"," text_parts = [part.text for part in event.content.parts if part.text]\n"," final_result = \"\".join(text_parts)\n"," print(f\"==> Final Agent Response: {final_result}\")\n","\n"," except Exception as e:\n"," print(f\"ERROR during agent run: {e}\")\n"," print(\"-\" * 30)\n","\n","# Main async function to run the examples\n","async def main():\n"," await call_agent_async(\"Calculate the value of (5 + 7) * 3\")\n"," await call_agent_async(\"What is 10 factorial?\")\n","\n","\n","# Execute the main async function\n","try:\n"," nest_asyncio.apply()\n"," asyncio.run(main())\n","except RuntimeError as e:\n"," # Handle specific error when running asyncio.run in an already running loop (like Jupyter/Colab)\n"," if \"cannot be called from a running event loop\" in str(e):\n"," print(\"\\nRunning in an existing event loop (like Colab/Jupyter).\")\n"," print(\"Please run `await main()` in a notebook cell instead.\")\n"," # If in an interactive environment like a notebook, you might need to run:\n"," # await main()\n"," else:\n"," raise e # Re-raise other runtime errors"]},{"cell_type":"markdown","id":"wJEScHHvGfub","metadata":{"id":"wJEScHHvGfub"},"source":["End of notebook!"]}],"metadata":{"colab":{"provenance":[{"file_id":"10YuefXzs0yPPmx0YriMQwb5EFy7EAGcF","timestamp":1753783205496}]},"kernelspec":{"display_name":"Python 3 (ipykernel)","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.11.11"},"widgets":{"application/vnd.jupyter.widget-state+json":{"337f450966f840698abaeef5ffd42d9e":{"model_module":"@jupyter-widgets/output","model_name":"OutputModel","model_module_version":"1.0.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/output","_model_module_version":"1.0.0","_model_name":"OutputModel","_view_count":null,"_view_module":"@jupyter-widgets/output","_view_module_version":"1.0.0","_view_name":"OutputView","layout":"IPY_MODEL_ae1548032c064897958efbe27ed668d1","msg_id":"","outputs":[{"output_type":"display_data","data":{"text/plain":"\u001b[1;36m🚀 Crew: \u001b[0m\u001b[1;36mcrew\u001b[0m\n└── \u001b[1;33m📋 Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\u001b[0m\n \u001b[37mStatus: \u001b[0m\u001b[2;33mExecuting Task...\u001b[0m\n └── \u001b[1;33m🔧 \u001b[0m\u001b[33mUsing Stock Price Lookup Tool (1)\u001b[0m\n","text/html":"
🚀 Crew: crew\n└── 📋 Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\n    Status: Executing Task...\n    └── 🔧 Using Stock Price Lookup Tool (1)\n
\n"},"metadata":{}}]}},"ae1548032c064897958efbe27ed668d1":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e841c93064a441a4be2e5a303acd6b85":{"model_module":"@jupyter-widgets/output","model_name":"OutputModel","model_module_version":"1.0.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/output","_model_module_version":"1.0.0","_model_name":"OutputModel","_view_count":null,"_view_module":"@jupyter-widgets/output","_view_module_version":"1.0.0","_view_name":"OutputView","layout":"IPY_MODEL_5cf2dd4cd95042b1bc3ef3a45ab161a8","msg_id":"","outputs":[{"output_type":"display_data","data":{"text/plain":"\u001b[1;36m🚀 Crew: \u001b[0m\u001b[1;36mcrew\u001b[0m\n└── \u001b[1;33m📋 Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\u001b[0m\n \u001b[37mStatus: \u001b[0m\u001b[2;33mExecuting Task...\u001b[0m\n └── \u001b[1;32m🔧 \u001b[0m\u001b[32mUsed Stock Price Lookup Tool (1)\u001b[0m\n","text/html":"
🚀 Crew: crew\n└── 📋 Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\n    Status: Executing Task...\n    └── 🔧 Used Stock Price Lookup Tool (1)\n
\n"},"metadata":{}}]}},"5cf2dd4cd95042b1bc3ef3a45ab161a8":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}}}}},"nbformat":4,"nbformat_minor":5} \ No newline at end of file +{ + "cells": [ + { + "cell_type": "markdown", + "id": "9496ebb1-25a6-40e8-bf4b-99884bc4cb2e", + "metadata": { + "id": "9496ebb1-25a6-40e8-bf4b-99884bc4cb2e" + }, + "source": [ + "# 1. Install Dependencies" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "t8nVkMERCbWP", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:28.010799Z", + "iopub.status.busy": "2025-07-25T06:23:28.010543Z", + "iopub.status.idle": "2025-07-25T06:23:28.350963Z", + "shell.execute_reply": "2025-07-25T06:23:28.350466Z" + }, + "id": "t8nVkMERCbWP", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "status": "ok", + "timestamp": 1753424899816, + "user_tz": -330, + "elapsed": 59759, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + }, + "outputId": "d6eea687-4b44-43d1-c82a-ccfd8682037a" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m40.3/40.3 kB\u001b[0m \u001b[31m1.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m42.8/42.8 kB\u001b[0m \u001b[31m2.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m61.0/61.0 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m44.3/44.3 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", + " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", + " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m48.5/48.5 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m47.8/47.8 kB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m366.3/366.3 kB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m35.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m8.6/8.6 MB\u001b[0m \u001b[31m84.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m16.4/16.4 MB\u001b[0m \u001b[31m69.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m239.3/239.3 kB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m19.5/19.5 MB\u001b[0m \u001b[31m74.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m1.4/1.4 MB\u001b[0m \u001b[31m51.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m218.1/218.1 kB\u001b[0m \u001b[31m14.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m335.7/335.7 kB\u001b[0m \u001b[31m22.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m119.5/119.5 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m158.5/158.5 kB\u001b[0m \u001b[31m11.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m65.6/65.6 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m72.5/72.5 kB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m119.4/119.4 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m201.6/201.6 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m60.0/60.0 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m5.6/5.6 MB\u001b[0m \u001b[31m101.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m756.0/756.0 kB\u001b[0m \u001b[31m44.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m64.8/64.8 kB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m236.0/236.0 kB\u001b[0m \u001b[31m15.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m18.7/18.7 MB\u001b[0m \u001b[31m73.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m79.1/79.1 kB\u001b[0m \u001b[31m4.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m284.2/284.2 kB\u001b[0m \u001b[31m18.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m45.5/45.5 kB\u001b[0m \u001b[31m2.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m229.5/229.5 kB\u001b[0m \u001b[31m13.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m103.8/103.8 kB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m53.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m101.6/101.6 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m105.4/105.4 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m71.2/71.2 kB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m45.2/45.2 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m45.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m459.8/459.8 kB\u001b[0m \u001b[31m27.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m6.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m51.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m4.0/4.0 MB\u001b[0m \u001b[31m75.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m453.1/453.1 kB\u001b[0m \u001b[31m24.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "google-colab 1.0.0 requires requests==2.32.3, but you have requests 2.32.4 which is incompatible.\n", + "google-generativeai 0.8.5 requires google-ai-generativelanguage==0.6.15, but you have google-ai-generativelanguage 0.6.18 which is incompatible.\u001b[0m\u001b[31m\n", + "\u001b[0m" + ] + } + ], + "source": [ + "!pip install -q -U \"dotenv==0.9.9\" \"langchain-google-genai==2.1.8\" \"crewai==0.150.0\" \"google-adk==1.8.0\"" + ] + }, + { + "cell_type": "markdown", + "id": "mw5jyVEQHf-H", + "metadata": { + "id": "mw5jyVEQHf-H" + }, + "source": [ + "# 2. Import Packages" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "O4rGR_1FHgnP", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:28.353166Z", + "iopub.status.busy": "2025-07-25T06:23:28.353001Z", + "iopub.status.idle": "2025-07-25T06:23:32.724402Z", + "shell.execute_reply": "2025-07-25T06:23:32.724071Z" + }, + "id": "O4rGR_1FHgnP" + }, + "outputs": [], + "source": [ + "import os, getpass\n", + "import asyncio\n", + "from typing import List\n", + "from dotenv import load_dotenv\n", + "import logging\n", + "\n", + "\n", + "from langchain_google_genai import ChatGoogleGenerativeAI\n", + "from langchain_core.prompts import ChatPromptTemplate\n", + "from langchain_core.tools import tool as langchain_tool\n", + "from langchain.agents import create_tool_calling_agent, AgentExecutor\n", + "\n", + "from crewai import Agent as CrewAgent, Task, Crew\n", + "from crewai.tools import tool as crew_tool\n", + "\n", + "from google.adk.agents import Agent as ADKAgent, LlmAgent\n", + "from google.adk.runners import Runner\n", + "from google.adk.sessions import InMemorySessionService\n", + "from google.adk.tools import google_search\n", + "from google.adk.code_executors import BuiltInCodeExecutor\n", + "from google.genai import types" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cXTBfGe8IppO", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:32.725713Z", + "iopub.status.busy": "2025-07-25T06:23:32.725584Z", + "iopub.status.idle": "2025-07-25T06:23:32.727230Z", + "shell.execute_reply": "2025-07-25T06:23:32.727023Z" + }, + "id": "cXTBfGe8IppO" + }, + "outputs": [], + "source": [ + "# Basic logging setup helps in debugging and tracking to execution.\n", + "logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n" + ] + }, + { + "cell_type": "markdown", + "id": "3nq-mQuMHaym", + "metadata": { + "id": "3nq-mQuMHaym" + }, + "source": [ + "# 2. Setup API Keys" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2b4848df-095b-4ddd-81ac-5949ab25c30e", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "execution": { + "iopub.execute_input": "2025-07-25T06:23:32.728261Z", + "iopub.status.busy": "2025-07-25T06:23:32.728200Z", + "iopub.status.idle": "2025-07-25T06:23:32.729503Z", + "shell.execute_reply": "2025-07-25T06:23:32.729287Z" + }, + "id": "2b4848df-095b-4ddd-81ac-5949ab25c30e", + "outputId": "c9d5b34e-cdff-4501-eeaf-236d3ceb017c", + "executionInfo": { + "status": "ok", + "timestamp": 1753424956043, + "user_tz": -330, + "elapsed": 15066, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter your Google API key: \u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\n", + "Enter your OpenAI API key: \u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\u00b7\n" + ] + } + ], + "source": [ + "# UNCOMMENT\n", + "# Prompt the user securely and set API keys as an environment variables\n", + "os.environ[\"GOOGLE_API_KEY\"] = getpass.getpass(\"Enter your Google API key: \")\n", + "os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"Enter your OpenAI API key: \")" + ] + }, + { + "cell_type": "markdown", + "id": "cd624f3b-4e5d-4a76-896e-1d9076c64727", + "metadata": { + "id": "cd624f3b-4e5d-4a76-896e-1d9076c64727" + }, + "source": [ + "# 3. LangChain" + ] + }, + { + "cell_type": "markdown", + "id": "DgVRXVDbHuZA", + "metadata": { + "id": "DgVRXVDbHuZA" + }, + "source": [ + "## 3.1 Setup LLM" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5VMXzAvHxiE", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "execution": { + "iopub.execute_input": "2025-07-25T06:23:32.730500Z", + "iopub.status.busy": "2025-07-25T06:23:32.730444Z", + "iopub.status.idle": "2025-07-25T06:23:32.756682Z", + "shell.execute_reply": "2025-07-25T06:23:32.756489Z" + }, + "id": "d5VMXzAvHxiE", + "outputId": "0279289e-49ac-47b2-aced-4fd6ae009e62", + "executionInfo": { + "status": "ok", + "timestamp": 1753424956075, + "user_tz": -330, + "elapsed": 36, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u2705 Language model initialized: models/gemini-2.0-flash\n" + ] + } + ], + "source": [ + "try:\n", + " # A model with function/tool calling capabilities is required.\n", + " llm = ChatGoogleGenerativeAI(model=\"gemini-2.0-flash\", temperature=0)\n", + " print(f\"\u2705 Language model initialized: {llm.model}\")\n", + "except Exception as e:\n", + " print(f\"\ud83d\uded1 Error initializing language model: {e}\")\n", + " llm = None" + ] + }, + { + "cell_type": "markdown", + "id": "90EOPzFTH33S", + "metadata": { + "id": "90EOPzFTH33S" + }, + "source": [ + "## 3.2 Define Search Tool" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "jJacHepFH2-_", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:32.757701Z", + "iopub.status.busy": "2025-07-25T06:23:32.757639Z", + "iopub.status.idle": "2025-07-25T06:23:32.760591Z", + "shell.execute_reply": "2025-07-25T06:23:32.760378Z" + }, + "id": "jJacHepFH2-_" + }, + "outputs": [], + "source": [ + "# --- Define a Tool ---\n", + "@langchain_tool\n", + "def search_information(query: str) -> str:\n", + " \"\"\"\n", + " Provides factual information on a given topic. Use this tool to find answers to phrases\n", + " like 'capital of France' or 'weather in London?'.\n", + " \"\"\"\n", + " print(f\"\\n--- \ud83d\udee0\ufe0f Tool Called: search_information with query: '{query}' ---\")\n", + " # Simulate a search tool with a dictionary of predefined results.\n", + " simulated_results = {\n", + " \"weather in london\": \"The weather in London is currently cloudy with a temperature of 15\u00b0C.\",\n", + " \"capital of france\": \"The capital of France is Paris.\",\n", + " \"population of earth\": \"The estimated population of Earth is around 8 billion people.\",\n", + " \"tallest mountain\": \"Mount Everest is the tallest mountain above sea level.\",\n", + " \"default\": f\"Simulated search result for '{query}': No specific information found, but the topic seems interesting.\"\n", + " }\n", + " result = simulated_results.get(query.lower(), simulated_results[\"default\"])\n", + " print(f\"--- TOOL RESULT: {result} ---\")\n", + " return result\n", + "\n", + "\n", + "tools = [search_information]" + ] + }, + { + "cell_type": "markdown", + "id": "_p91Mx8yH_w-", + "metadata": { + "id": "_p91Mx8yH_w-" + }, + "source": [ + "## 3.3 Tool Calling Agent" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8rOcIPQ0ICZK", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:32.762254Z", + "iopub.status.busy": "2025-07-25T06:23:32.762195Z", + "iopub.status.idle": "2025-07-25T06:23:32.765863Z", + "shell.execute_reply": "2025-07-25T06:23:32.765680Z" + }, + "id": "8rOcIPQ0ICZK" + }, + "outputs": [], + "source": [ + "# --- Create a Tool-Calling Agent ---\n", + "if llm:\n", + " # This prompt template requires an `agent_scratchpad` placeholder for the agent's internal steps.\n", + " agent_prompt = ChatPromptTemplate.from_messages([\n", + " (\"system\", \"You are a helpful assistant.\"),\n", + " (\"human\", \"{input}\"),\n", + " (\"placeholder\", \"{agent_scratchpad}\"),\n", + " ])\n", + "\n", + "\n", + " # Create the agent, binding the LLM, tools, and prompt together.\n", + " agent = create_tool_calling_agent(llm, tools, agent_prompt)\n", + "\n", + "\n", + " # AgentExecutor is the runtime that invokes the agent and executes the chosen tools.\n", + " # The 'tools' argument is not needed here as they are already bound to the agent.\n", + " agent_executor = AgentExecutor(agent=agent, verbose=True, tools=tools)" + ] + }, + { + "cell_type": "markdown", + "id": "gGZK5EWIIdwx", + "metadata": { + "id": "gGZK5EWIIdwx" + }, + "source": [ + "## 3.4 Run Agent" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b862b9e3-61a8-4654-9ffd-4128fce28f4b", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "execution": { + "iopub.execute_input": "2025-07-25T06:23:32.766832Z", + "iopub.status.busy": "2025-07-25T06:23:32.766770Z", + "iopub.status.idle": "2025-07-25T06:23:37.108919Z", + "shell.execute_reply": "2025-07-25T06:23:37.108214Z" + }, + "id": "b862b9e3-61a8-4654-9ffd-4128fce28f4b", + "outputId": "c96038a1-cfd6-4531-8221-752c01bcbd70", + "scrolled": true, + "executionInfo": { + "status": "ok", + "timestamp": 1753424957618, + "user_tz": -330, + "elapsed": 1465, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "--- \ud83c\udfc3 Running Agent with Query: 'What is the capital of France?' ---\n", + "\n", + "--- \ud83c\udfc3 Running Agent with Query: 'What's the weather like in London?' ---\n", + "\n", + "--- \ud83c\udfc3 Running Agent with Query: 'Tell me something about dogs.' ---\n", + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "\u001b[32;1m\u001b[1;3m\n", + "Invoking: `search_information` with `{'query': 'weather in London'}`\n", + "\n", + "\n", + "\u001b[0m\n", + "--- \ud83d\udee0\ufe0f Tool Called: search_information with query: 'weather in London' ---\n", + "--- TOOL RESULT: The weather in London is currently cloudy with a temperature of 15\u00b0C. ---\n", + "\u001b[36;1m\u001b[1;3mThe weather in London is currently cloudy with a temperature of 15\u00b0C.\u001b[0m\u001b[32;1m\u001b[1;3m\n", + "Invoking: `search_information` with `{'query': 'characteristics of dogs'}`\n", + "\n", + "\n", + "\u001b[0m\n", + "--- \ud83d\udee0\ufe0f Tool Called: search_information with query: 'characteristics of dogs' ---\n", + "--- TOOL RESULT: Simulated search result for 'characteristics of dogs': No specific information found, but the topic seems interesting. ---\n", + "\u001b[36;1m\u001b[1;3mSimulated search result for 'characteristics of dogs': No specific information found, but the topic seems interesting.\u001b[0m\u001b[32;1m\u001b[1;3m\n", + "Invoking: `search_information` with `{'query': 'capital of France'}`\n", + "\n", + "\n", + "\u001b[0m\n", + "--- \ud83d\udee0\ufe0f Tool Called: search_information with query: 'capital of France' ---\n", + "--- TOOL RESULT: The capital of France is Paris. ---\n", + "\u001b[36;1m\u001b[1;3mThe capital of France is Paris.\u001b[0m\u001b[32;1m\u001b[1;3mThe weather in London is currently cloudy with a temperature of 15\u00b0C.\n", + "\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "--- \u2705 Final Agent Response ---\n", + "The weather in London is currently cloudy with a temperature of 15\u00b0C.\n", + "\n", + "\u001b[32;1m\u001b[1;3mThe capital of France is Paris.\n", + "\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "--- \u2705 Final Agent Response ---\n", + "The capital of France is Paris.\n", + "\n", + "\u001b[32;1m\u001b[1;3mI'm sorry, I don't have enough information about dogs to fulfill your request. I can try a different query if you like. For example, I could search for different breeds of dogs, or the history of dogs.\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n", + "\n", + "--- \u2705 Final Agent Response ---\n", + "I'm sorry, I don't have enough information about dogs to fulfill your request. I can try a different query if you like. For example, I could search for different breeds of dogs, or the history of dogs.\n" + ] + } + ], + "source": [ + "async def run_agent_with_tool(query: str):\n", + " \"\"\"Invokes the agent executor with a query and prints the final response.\"\"\"\n", + " print(f\"\\n--- \ud83c\udfc3 Running Agent with Query: '{query}' ---\")\n", + " try:\n", + " response = await agent_executor.ainvoke({\"input\": query})\n", + " print(\"\\n--- \u2705 Final Agent Response ---\")\n", + " print(response[\"output\"])\n", + " except Exception as e:\n", + " print(f\"\\n\ud83d\uded1 An error occurred during agent execution: {e}\")\n", + "\n", + "\n", + "async def main():\n", + " \"\"\"Runs all agent queries concurrently.\"\"\"\n", + " tasks = [\n", + " run_agent_with_tool(\"What is the capital of France?\"),\n", + " run_agent_with_tool(\"What's the weather like in London?\"),\n", + " run_agent_with_tool(\"Tell me something about dogs.\") # Should trigger the default tool response\n", + " ]\n", + " await asyncio.gather(*tasks)\n", + "\n", + "\n", + "\n", + "await main()" + ] + }, + { + "cell_type": "markdown", + "id": "8aa008f4-94a2-4a8b-8165-f6fd213c0d40", + "metadata": { + "id": "8aa008f4-94a2-4a8b-8165-f6fd213c0d40" + }, + "source": [ + "# 4. Crew AI" + ] + }, + { + "cell_type": "markdown", + "id": "2uSUtzdbJRZQ", + "metadata": { + "id": "2uSUtzdbJRZQ" + }, + "source": [ + "## 4.1 Define Stock Price Search Tool" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31df7900-9b2b-456c-b018-6a32db662bdc", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:37.112253Z", + "iopub.status.busy": "2025-07-25T06:23:37.111995Z", + "iopub.status.idle": "2025-07-25T06:23:37.119765Z", + "shell.execute_reply": "2025-07-25T06:23:37.119211Z" + }, + "id": "31df7900-9b2b-456c-b018-6a32db662bdc" + }, + "outputs": [], + "source": [ + "# --- 1. Refactored Tool: Returns Clean Data ---\n", + "# The tool now returns raw data (a float) or raises a standard Python error.\n", + "# This makes it more reusable and forces the agent to handle outcomes properly.\n", + "@crew_tool(\"Stock Price Lookup Tool\")\n", + "def get_stock_price(ticker: str) -> float:\n", + " \"\"\"\n", + " Fetches the latest simulated stock price for a given stock ticker symbol.\n", + " Returns the price as a float. Raises a ValueError if the ticker is not found.\n", + " \"\"\"\n", + " logging.info(f\"Tool Call: get_stock_price for ticker '{ticker}'\")\n", + " simulated_prices = {\n", + " \"AAPL\": 178.15,\n", + " \"GOOGL\": 1750.30,\n", + " \"MSFT\": 425.50,\n", + " }\n", + " price = simulated_prices.get(ticker.upper())\n", + "\n", + "\n", + " if price is not None:\n", + " return price\n", + " else:\n", + " # Raising a specific error is better than returning a string.\n", + " # The agent is equipped to handle exceptions and can decide on the next action.\n", + " raise ValueError(f\"Simulated price for ticker '{ticker.upper()}' not found.\")\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "WMqIW8n_JrkO", + "metadata": { + "id": "WMqIW8n_JrkO" + }, + "source": [ + "## 4.2 Setup Crew Entities" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "XFd2tKTRJh72", + "metadata": { + "execution": { + "iopub.execute_input": "2025-07-25T06:23:37.122182Z", + "iopub.status.busy": "2025-07-25T06:23:37.121984Z", + "iopub.status.idle": "2025-07-25T06:23:37.129796Z", + "shell.execute_reply": "2025-07-25T06:23:37.129431Z" + }, + "id": "XFd2tKTRJh72" + }, + "outputs": [], + "source": [ + "# --- 2. Define the Agent ---\n", + "# The agent definition remains the same, but it will now leverage the improved tool.\n", + "financial_analyst_agent = CrewAgent(\n", + " role='Senior Financial Analyst',\n", + " goal='Analyze stock data using provided tools and report key prices.',\n", + " backstory=\"You are an experienced financial analyst adept at using data sources to find stock information. You provide clear, direct answers.\",\n", + " verbose=True,\n", + " tools=[get_stock_price],\n", + " # Allowing delegation can be useful, but is not necessary for this simple task.\n", + " allow_delegation=False,\n", + ")\n", + "\n", + "\n", + "# --- 3. Refined Task: Clearer Instructions and Error Handling ---\n", + "# The task description is more specific and guides the agent on how to react\n", + "# to both successful data retrieval and potential errors.\n", + "analyze_aapl_task = Task(\n", + " description=(\n", + " \"What is the current simulated stock price for Apple (ticker: AAPL)? \"\n", + " \"Use the 'Stock Price Lookup Tool' to find it. \"\n", + " \"If the ticker is not found, you must report that you were unable to retrieve the price.\"\n", + " ),\n", + " expected_output=(\n", + " \"A single, clear sentence stating the simulated stock price for AAPL. \"\n", + " \"For example: 'The simulated stock price for AAPL is $178.15.' \"\n", + " \"If the price cannot be found, state that clearly.\"\n", + " ),\n", + " agent=financial_analyst_agent,\n", + ")\n", + "\n", + "\n", + "# --- 4. Formulate the Crew ---\n", + "# The crew orchestrates how the agent and task work together.\n", + "financial_crew = Crew(\n", + " agents=[financial_analyst_agent],\n", + " tasks=[analyze_aapl_task],\n", + " verbose=True # Set to False for less detailed logs in production\n", + ")\n" + ] + }, + { + "cell_type": "markdown", + "id": "TBsi1L_oJmZi", + "metadata": { + "id": "TBsi1L_oJmZi" + }, + "source": [ + "## 4.3 Run Crew Agent" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ISnpTbLBJmzk", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000, + "referenced_widgets": [ + "337f450966f840698abaeef5ffd42d9e", + "ae1548032c064897958efbe27ed668d1", + "e841c93064a441a4be2e5a303acd6b85", + "5cf2dd4cd95042b1bc3ef3a45ab161a8" + ] + }, + "execution": { + "iopub.execute_input": "2025-07-25T06:23:37.131761Z", + "iopub.status.busy": "2025-07-25T06:23:37.131605Z", + "iopub.status.idle": "2025-07-25T06:23:39.462993Z", + "shell.execute_reply": "2025-07-25T06:23:39.462634Z" + }, + "id": "ISnpTbLBJmzk", + "outputId": "11b6e821-d14d-4e9b-b0e6-399ff96fd024", + "executionInfo": { + "status": "ok", + "timestamp": 1753424960514, + "user_tz": -330, + "elapsed": 2821, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "## Starting the Financial Crew...\n", + "---------------------------------\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[36m\u256d\u2500\u001b[0m\u001b[36m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[36m Crew Execution Started \u001b[0m\u001b[36m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[36m\u2500\u256e\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[1;36mCrew Execution Started\u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[37mName: \u001b[0m\u001b[36mcrew\u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[37mID: \u001b[0m\u001b[36m22e3da43-7199-40fd-8817-9aa4bc877eac\u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[37mTool Args: \u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2502\u001b[0m \u001b[36m\u2502\u001b[0m\n", + "\u001b[36m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n" + ], + "text/html": [ + "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Crew Execution Started \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Crew Execution Started                                                                                         \u2502\n",
+       "\u2502  Name: crew                                                                                                     \u2502\n",
+       "\u2502  ID: 22e3da43-7199-40fd-8817-9aa4bc877eac                                                                       \u2502\n",
+       "\u2502  Tool Args:                                                                                                     \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\n" + ], + "text/html": [ + "
\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [], + "text/html": [ + "
\n"
+      ]
+     },
+     "metadata": {}
+    },
+    {
+     "output_type": "display_data",
+     "data": {
+      "text/plain": [
+       "\u001b[35m\u256d\u2500\u001b[0m\u001b[35m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[35m \ud83e\udd16 Agent Started \u001b[0m\u001b[35m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[35m\u2500\u256e\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[1;92mSenior Financial Analyst\u001b[0m                                                                                \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m  \u001b[37mTask: \u001b[0m\u001b[92mWhat is the current simulated stock price for Apple (ticker: AAPL)? Use the 'Stock Price Lookup Tool' \u001b[0m   \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m  \u001b[92mto find it. If the ticker is not found, you must report that you were unable to retrieve the price.\u001b[0m            \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n"
+      ],
+      "text/html": [
+       "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \ud83e\udd16 Agent Started \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Agent: Senior Financial Analyst                                                                                \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Task: What is the current simulated stock price for Apple (ticker: AAPL)? Use the 'Stock Price Lookup Tool'    \u2502\n",
+       "\u2502  to find it. If the ticker is not found, you must report that you were unable to retrieve the price.            \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\n" + ], + "text/html": [ + "
\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "337f450966f840698abaeef5ffd42d9e" + } + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [], + "text/html": [ + "
\n"
+      ]
+     },
+     "metadata": {}
+    },
+    {
+     "output_type": "display_data",
+     "data": {
+      "text/plain": [
+       "\u001b[35m\u256d\u2500\u001b[0m\u001b[35m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[35m \ud83d\udd27 Agent Tool Execution \u001b[0m\u001b[35m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[35m\u2500\u256e\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[1;92mSenior Financial Analyst\u001b[0m                                                                                \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m  \u001b[37mThought: \u001b[0m\u001b[92mThought: I need to find the current simulated stock price for Apple (ticker: AAPL).\u001b[0m                   \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m  \u001b[37mUsing Tool: \u001b[0m\u001b[1;92mStock Price Lookup Tool\u001b[0m                                                                            \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2502\u001b[0m                                                                                                                 \u001b[35m\u2502\u001b[0m\n",
+       "\u001b[35m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n"
+      ],
+      "text/html": [
+       "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \ud83d\udd27 Agent Tool Execution \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Agent: Senior Financial Analyst                                                                                \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Thought: Thought: I need to find the current simulated stock price for Apple (ticker: AAPL).                   \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Using Tool: Stock Price Lookup Tool                                                                            \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[34m\u256d\u2500\u001b[0m\u001b[34m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[34m Tool Input \u001b[0m\u001b[34m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[34m\u2500\u256e\u001b[0m\n", + "\u001b[34m\u2502\u001b[0m \u001b[34m\u2502\u001b[0m\n", + "\u001b[34m\u2502\u001b[0m \u001b[38;2;230;219;116;49m\"{\\\"ticker\\\": \\\"AAPL\\\"}\"\u001b[0m \u001b[34m\u2502\u001b[0m\n", + "\u001b[34m\u2502\u001b[0m \u001b[34m\u2502\u001b[0m\n", + "\u001b[34m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n" + ], + "text/html": [ + "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Tool Input \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  \"{\\\"ticker\\\": \\\"AAPL\\\"}\"                                                                                       \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[32m\u256d\u2500\u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m Tool Output \u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m\u2500\u256e\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[92m178.15\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n" + ], + "text/html": [ + "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Tool Output \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  178.15                                                                                                         \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\n" + ], + "text/html": [ + "
\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Output()" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "e841c93064a441a4be2e5a303acd6b85" + } + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [], + "text/html": [ + "
\n"
+      ]
+     },
+     "metadata": {}
+    },
+    {
+     "output_type": "display_data",
+     "data": {
+      "text/plain": [
+       "\u001b[32m\u256d\u2500\u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m \u2705 Agent Final Answer \u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m\u2500\u256e\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m                                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[1;92mSenior Financial Analyst\u001b[0m                                                                                \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m                                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[37mFinal Answer:\u001b[0m                                                                                                  \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[92mThe simulated stock price for AAPL is $178.15.\u001b[0m                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m                                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n"
+      ],
+      "text/html": [
+       "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2705 Agent Final Answer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Agent: Senior Financial Analyst                                                                                \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Final Answer:                                                                                                  \u2502\n",
+       "\u2502  The simulated stock price for AAPL is $178.15.                                                                 \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\n" + ], + "text/html": [ + "
\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [], + "text/html": [ + "
\n"
+      ]
+     },
+     "metadata": {}
+    },
+    {
+     "output_type": "display_data",
+     "data": {
+      "text/plain": [
+       "\u001b[32m\u256d\u2500\u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m Task Completion \u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m\u2500\u256e\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m                                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[1;32mTask Completed\u001b[0m                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[37mName: \u001b[0m\u001b[32m3ae83180-2ac2-456f-aff6-2ff30a3e9f89\u001b[0m                                                                     \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[37mAgent: \u001b[0m\u001b[32mSenior Financial Analyst\u001b[0m                                                                                \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m  \u001b[37mTool Args: \u001b[0m                                                                                                    \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m                                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2502\u001b[0m                                                                                                                 \u001b[32m\u2502\u001b[0m\n",
+       "\u001b[32m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n"
+      ],
+      "text/html": [
+       "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Task Completion \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Task Completed                                                                                                 \u2502\n",
+       "\u2502  Name: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89                                                                     \u2502\n",
+       "\u2502  Agent: Senior Financial Analyst                                                                                \u2502\n",
+       "\u2502  Tool Args:                                                                                                     \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\n" + ], + "text/html": [ + "
\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[32m\u256d\u2500\u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m Crew Completion \u001b[0m\u001b[32m\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u001b[0m\u001b[32m\u2500\u256e\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[1;32mCrew Execution Completed\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[37mName: \u001b[0m\u001b[32mcrew\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[37mID: \u001b[0m\u001b[32m22e3da43-7199-40fd-8817-9aa4bc877eac\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[37mTool Args: \u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[37mFinal Output: The simulated stock price for AAPL is $178.15.\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2502\u001b[0m \u001b[32m\u2502\u001b[0m\n", + "\u001b[32m\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\u001b[0m\n" + ], + "text/html": [ + "
\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Crew Completion \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502  Crew Execution Completed                                                                                       \u2502\n",
+       "\u2502  Name: crew                                                                                                     \u2502\n",
+       "\u2502  ID: 22e3da43-7199-40fd-8817-9aa4bc877eac                                                                       \u2502\n",
+       "\u2502  Tool Args:                                                                                                     \u2502\n",
+       "\u2502  Final Output: The simulated stock price for AAPL is $178.15.                                                   \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2502                                                                                                                 \u2502\n",
+       "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\n" + ], + "text/html": [ + "
\n",
+       "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "---------------------------------\n", + "## Crew execution finished.\n", + "\n", + "Final Result:\n", + " The simulated stock price for AAPL is $178.15.\n" + ] + } + ], + "source": [ + "\n", + "\n", + "# --- 5. Run the Crew within a Main Execution Block ---\n", + "# Using a __name__ == \"__main__\": block is a standard Python best practice.\n", + "def main():\n", + " \"\"\"Main function to run the crew.\"\"\"\n", + " # Check for API key before starting to avoid runtime errors.\n", + " if not os.environ.get(\"OPENAI_API_KEY\"):\n", + " print(\"ERROR: The OPENAI_API_KEY environment variable is not set.\")\n", + " print(\"Please set it before running the script.\")\n", + " return\n", + "\n", + "\n", + " print(\"\\n## Starting the Financial Crew...\")\n", + " print(\"---------------------------------\")\n", + "\n", + " # The kickoff method starts the execution.\n", + " result = financial_crew.kickoff()\n", + "\n", + "\n", + " print(\"\\n---------------------------------\")\n", + " print(\"## Crew execution finished.\")\n", + " print(\"\\nFinal Result:\\n\", result)\n", + "\n", + "\n", + "if __name__ == \"__main__\":\n", + " main()\n" + ] + }, + { + "cell_type": "markdown", + "id": "01de8db8-25f9-420f-9698-8e93c8ab98fe", + "metadata": { + "id": "01de8db8-25f9-420f-9698-8e93c8ab98fe" + }, + "source": [ + "# 5. Google Agent Development Kit (ADK)" + ] + }, + { + "cell_type": "markdown", + "id": "e04c9ab5-bbfe-4eb3-aa2d-64f8bfcd97b3", + "metadata": { + "id": "e04c9ab5-bbfe-4eb3-aa2d-64f8bfcd97b3" + }, + "source": [ + "## 5.1 Agent with Search Tool" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "350b5cb0-666f-46a6-b0b3-4d3c5df6c760", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "execution": { + "iopub.execute_input": "2025-07-25T06:23:39.464863Z", + "iopub.status.busy": "2025-07-25T06:23:39.464725Z", + "iopub.status.idle": "2025-07-25T06:23:45.291775Z", + "shell.execute_reply": "2025-07-25T06:23:45.291253Z" + }, + "id": "350b5cb0-666f-46a6-b0b3-4d3c5df6c760", + "outputId": "59ddea39-5066-4858-f458-5765f4d87a09", + "scrolled": true, + "executionInfo": { + "status": "ok", + "timestamp": 1753424964011, + "user_tz": -330, + "elapsed": 3496, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Agent Response: Here's a summary of recent AI news:\n", + "\n", + "* **AI and Job Markets**: Sam Altman (OpenAI CEO) has warned of potential job losses and national security threats due to AI. Research indicates AI is changing the job landscape, prompting nations to prepare their workforces.\n", + "* **AI Models and Advancements**: Google made AI models faster and cheaper. Google's Gemini 2.5 model aims for 'intelligence per dollar'. Google also introduced AlphaGenome for understanding the human genome and launched Weather Lab to support better tropical cyclone prediction with AI.\n", + "* **AI in Different Sectors**: AI is rewriting the rules of the insurance industry. AI is helping students learn and scientists understand the human body better.\n", + "* **AI Ethics and Safety**: There are growing concerns about AI safety. A study revealed that even the most powerful AI models can make basic errors in navigating ethical medical decisions.\n", + "* **Talent Acquisition**: Meta is actively hiring AI researchers, including those from Apple.\n", + "* **Quantum Computing**: There have been breakthroughs in quantum computing, including achieving an exponential speedup and making \"magic states\" easier to create.\n", + "\n" + ] + } + ], + "source": [ + "# Define variables required for Session setup and Agent execution\n", + "APP_NAME=\"Google Search_agent\"\n", + "USER_ID=\"user1234\"\n", + "SESSION_ID=\"1234\"\n", + "\n", + "\n", + "\n", + "# Define Agent with access to search tool\n", + "root_agent = ADKAgent(\n", + " name=\"basic_search_agent\",\n", + " model=\"gemini-2.0-flash-exp\",\n", + " description=\"Agent to answer questions using Google Search.\",\n", + " instruction=\"I can answer your questions by searching the internet. Just ask me anything!\",\n", + " tools=[google_search] # Google Search is a pre-built tool to perform Google searches.\n", + ")\n", + "\n", + "\n", + "\n", + "\n", + "# Agent Interaction\n", + "async def call_agent(query):\n", + " \"\"\"\n", + " Helper function to call the agent with a query.\n", + " \"\"\"\n", + "\n", + " # Session and Runner\n", + " session_service = InMemorySessionService()\n", + " session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)\n", + " runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)\n", + "\n", + " content = types.Content(role='user', parts=[types.Part(text=query)])\n", + " events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content)\n", + "\n", + "\n", + " for event in events:\n", + " if event.is_final_response():\n", + " final_response = event.content.parts[0].text\n", + " print(\"Agent Response: \", final_response)\n", + "\n", + "\n", + "await call_agent(\"what's the latest ai news?\")" + ] + }, + { + "cell_type": "markdown", + "id": "6dde5f6e-4d28-4015-842d-5b53beb5b638", + "metadata": { + "id": "6dde5f6e-4d28-4015-842d-5b53beb5b638" + }, + "source": [ + "## 5.2 Agent with Code Tool" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d0e485c0-98a8-49a8-a373-7832c500b955", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "execution": { + "iopub.execute_input": "2025-07-25T06:23:45.294602Z", + "iopub.status.busy": "2025-07-25T06:23:45.294355Z", + "iopub.status.idle": "2025-07-25T06:24:04.644288Z", + "shell.execute_reply": "2025-07-25T06:24:04.642573Z" + }, + "id": "d0e485c0-98a8-49a8-a373-7832c500b955", + "outputId": "08de17eb-3506-4319-baaa-3639a41b1238", + "scrolled": true, + "executionInfo": { + "status": "ok", + "timestamp": 1753424981662, + "user_tz": -330, + "elapsed": 17645, + "user": { + "displayName": "Shishir Suman", + "userId": "15686497179682448712" + } + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "--- Running Query: Calculate the value of (5 + 7) * 3 ---\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "WARNING:google_genai.types:Warning: there are non-text parts in the response: ['executable_code', 'code_execution_result'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Event ID: 23696e40-5e9d-4da3-89f5-032971769c2b, Author: calculator_agent\n", + " Debug: Agent generated code:\n", + "```python\n", + "print((5 + 7) * 3)\n", + "\n", + "```\n", + " Debug: Code Execution Result: Outcome.OUTCOME_OK - Output:\n", + "36\n", + "\n", + " Text: '36'\n", + "==> Final Agent Response: 36\n", + "\n", + "------------------------------\n", + "\n", + "--- Running Query: What is 10 factorial? ---\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "WARNING:google_genai.types:Warning: there are non-text parts in the response: ['executable_code', 'code_execution_result'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Event ID: 11d25af6-8864-497f-8846-7c054503a100, Author: calculator_agent\n", + " Debug: Agent generated code:\n", + "```python\n", + "import math\n", + "print(math.factorial(10))\n", + "\n", + "```\n", + " Debug: Code Execution Result: Outcome.OUTCOME_OK - Output:\n", + "3628800\n", + "\n", + " Text: '3628800'\n", + "==> Final Agent Response: 3628800\n", + "\n", + "------------------------------\n" + ] + } + ], + "source": [ + "# Define variables required for Session setup and Agent execution\n", + "APP_NAME=\"calculator\"\n", + "USER_ID=\"user1234\"\n", + "SESSION_ID=\"session_code_exec_async\"\n", + "\n", + "\n", + "# Agent Definition\n", + "code_agent = LlmAgent(\n", + " name=\"calculator_agent\",\n", + " model=\"gemini-2.0-flash\",\n", + " code_executor=BuiltInCodeExecutor(),\n", + " instruction=\"\"\"You are a calculator agent.\n", + " When given a mathematical expression, write and execute Python code to calculate the result.\n", + " Return only the final numerical result as plain text, without markdown or code blocks.\n", + " \"\"\",\n", + " description=\"Executes Python code to perform calculations.\",\n", + ")\n", + "\n", + "# Agent Interaction (Async)\n", + "async def call_agent_async(query):\n", + "\n", + " # Session and Runner\n", + " session_service = InMemorySessionService()\n", + " session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)\n", + " runner = Runner(agent=code_agent, app_name=APP_NAME, session_service=session_service)\n", + "\n", + " content = types.Content(role='user', parts=[types.Part(text=query)])\n", + " print(f\"\\n--- Running Query: {query} ---\")\n", + " final_response_text = \"No final text response captured.\"\n", + " try:\n", + " # Use run_async\n", + " async for event in runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=content):\n", + " print(f\"Event ID: {event.id}, Author: {event.author}\")\n", + "\n", + " # --- Check for specific parts FIRST ---\n", + " # has_specific_part = False\n", + " if event.content and event.content.parts and event.is_final_response():\n", + " for part in event.content.parts: # Iterate through all parts\n", + " if part.executable_code:\n", + " # Access the actual code string via .code\n", + " print(f\" Debug: Agent generated code:\\n```python\\n{part.executable_code.code}\\n```\")\n", + " has_specific_part = True\n", + " elif part.code_execution_result:\n", + " # Access outcome and output correctly\n", + " print(f\" Debug: Code Execution Result: {part.code_execution_result.outcome} - Output:\\n{part.code_execution_result.output}\")\n", + " has_specific_part = True\n", + " # Also print any text parts found in any event for debugging\n", + " elif part.text and not part.text.isspace():\n", + " print(f\" Text: '{part.text.strip()}'\")\n", + " # Do not set has_specific_part=True here, as we want the final response logic below\n", + "\n", + " # --- Check for final response AFTER specific parts ---\n", + " text_parts = [part.text for part in event.content.parts if part.text]\n", + " final_result = \"\".join(text_parts)\n", + " print(f\"==> Final Agent Response: {final_result}\")\n", + "\n", + " except Exception as e:\n", + " print(f\"ERROR during agent run: {e}\")\n", + " print(\"-\" * 30)\n", + "\n", + "# Main async function to run the examples\n", + "async def main():\n", + " await call_agent_async(\"Calculate the value of (5 + 7) * 3\")\n", + " await call_agent_async(\"What is 10 factorial?\")\n", + "\n", + "\n", + "# Execute the main async function\n", + "await main()" + ] + }, + { + "cell_type": "markdown", + "id": "wJEScHHvGfub", + "metadata": { + "id": "wJEScHHvGfub" + }, + "source": [ + "End of notebook!" + ] + } + ], + "metadata": { + "colab": { + "provenance": [ + { + "file_id": "10YuefXzs0yPPmx0YriMQwb5EFy7EAGcF", + "timestamp": 1753783205496 + } + ] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.11.11" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "337f450966f840698abaeef5ffd42d9e": { + "model_module": "@jupyter-widgets/output", + "model_name": "OutputModel", + "model_module_version": "1.0.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/output", + "_model_module_version": "1.0.0", + "_model_name": "OutputModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/output", + "_view_module_version": "1.0.0", + "_view_name": "OutputView", + "layout": "IPY_MODEL_ae1548032c064897958efbe27ed668d1", + "msg_id": "", + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": "\u001b[1;36m\ud83d\ude80 Crew: \u001b[0m\u001b[1;36mcrew\u001b[0m\n\u2514\u2500\u2500 \u001b[1;33m\ud83d\udccb Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\u001b[0m\n \u001b[37mStatus: \u001b[0m\u001b[2;33mExecuting Task...\u001b[0m\n \u2514\u2500\u2500 \u001b[1;33m\ud83d\udd27 \u001b[0m\u001b[33mUsing Stock Price Lookup Tool (1)\u001b[0m\n", + "text/html": "
\ud83d\ude80 Crew: crew\n\u2514\u2500\u2500 \ud83d\udccb Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\n    Status: Executing Task...\n    \u2514\u2500\u2500 \ud83d\udd27 Using Stock Price Lookup Tool (1)\n
\n" + }, + "metadata": {} + } + ] + } + }, + "ae1548032c064897958efbe27ed668d1": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "e841c93064a441a4be2e5a303acd6b85": { + "model_module": "@jupyter-widgets/output", + "model_name": "OutputModel", + "model_module_version": "1.0.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/output", + "_model_module_version": "1.0.0", + "_model_name": "OutputModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/output", + "_view_module_version": "1.0.0", + "_view_name": "OutputView", + "layout": "IPY_MODEL_5cf2dd4cd95042b1bc3ef3a45ab161a8", + "msg_id": "", + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": "\u001b[1;36m\ud83d\ude80 Crew: \u001b[0m\u001b[1;36mcrew\u001b[0m\n\u2514\u2500\u2500 \u001b[1;33m\ud83d\udccb Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\u001b[0m\n \u001b[37mStatus: \u001b[0m\u001b[2;33mExecuting Task...\u001b[0m\n \u2514\u2500\u2500 \u001b[1;32m\ud83d\udd27 \u001b[0m\u001b[32mUsed Stock Price Lookup Tool (1)\u001b[0m\n", + "text/html": "
\ud83d\ude80 Crew: crew\n\u2514\u2500\u2500 \ud83d\udccb Task: 3ae83180-2ac2-456f-aff6-2ff30a3e9f89\n    Status: Executing Task...\n    \u2514\u2500\u2500 \ud83d\udd27 Used Stock Price Lookup Tool (1)\n
\n" + }, + "metadata": {} + } + ] + } + }, + "5cf2dd4cd95042b1bc3ef3a45ab161a8": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + } + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file