{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c57cb5f3",
"metadata": {},
"outputs": [],
"source": [
"# !pip install -r requirements.txt\n",
"# Load metadata.jsonl\n",
"import json\n",
"# Load the metadata.jsonl file\n",
"with open('metadata.jsonl', 'r') as jsonl_file:\n",
" json_list = list(jsonl_file)\n",
"\n",
"json_QA = []\n",
"for json_str in json_list:\n",
" json_data = json.loads(json_str)\n",
" json_QA.append(json_data)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ec0f78a4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"==================================================\n",
"Task ID: a26649c6-1cb2-470a-871e-6910c64c3e53\n",
"Question: What is the absolute difference in tens of thousands between the population of chinstrap penguins on the Wikipedia page for penguin species populations as of the end of 2018 and the population recorded in the Nature.com \"global population assessment of the Chinstrap penguin\" article from 2020, assuming two penguins per breeding pair?\n",
"Level: 2\n",
"Final Answer: 116\n",
"Annotator Metadata: \n",
" ├── Steps: \n",
" │ ├── 1. Searched \"penguin species populations wikipedia\" on Google search.\n",
" │ ├── 2. Opened the \"List of Sphenisciformes by population\" Wikipedia article.\n",
" │ ├── 3. Clicked \"View history\".\n",
" │ ├── 4. Scrolled to the end of 2018 and opened the page.\n",
" │ ├── 5. Scrolled to the encoding for the population table.\n",
" │ ├── 6. Recorded the number of chinstrap penguins (8 million).\n",
" │ ├── 7. Searched \"Nature.com global population assessment of the Chinstrap penguin 2020\" in Google search.\n",
" │ ├── 8. Opened the top link to the article with the corresponding name and date.\n",
" │ ├── 9. Read the abstract and noted the number of breeding pairs (3.42 million).\n",
" │ ├── 10. Multiplied the breeding pairs by 2 to get the number of penguins (6.84 million).\n",
" │ ├── 11. Subtracted the Wikipedia population from the Nature.com population (1.16 million).\n",
" │ ├── 12. Multiplied 1.16 by 100 to get tens of thousands (116).\n",
" ├── Number of steps: 12\n",
" ├── How long did this take?: 20 minutes\n",
" ├── Tools:\n",
" │ ├── 1. Search engine\n",
" │ ├── 2. Web browser\n",
" │ ├── 3. Calculator\n",
" └── Number of tools: 3\n",
"==================================================\n"
]
}
],
"source": [
"# randomly select 3 samples\n",
"# {\"task_id\": \"c61d22de-5f6c-4958-a7f6-5e9707bd3466\", \"Question\": \"A paper about AI regulation that was originally submitted to arXiv.org in June 2022 shows a figure with three axes, where each axis has a label word at both ends. Which of these words is used to describe a type of society in a Physics and Society article submitted to arXiv.org on August 11, 2016?\", \"Level\": 2, \"Final answer\": \"egalitarian\", \"file_name\": \"\", \"Annotator Metadata\": {\"Steps\": \"1. Go to arxiv.org and navigate to the Advanced Search page.\\n2. Enter \\\"AI regulation\\\" in the search box and select \\\"All fields\\\" from the dropdown.\\n3. Enter 2022-06-01 and 2022-07-01 into the date inputs, select \\\"Submission date (original)\\\", and submit the search.\\n4. Go through the search results to find the article that has a figure with three axes and labels on each end of the axes, titled \\\"Fairness in Agreement With European Values: An Interdisciplinary Perspective on AI Regulation\\\".\\n5. Note the six words used as labels: deontological, egalitarian, localized, standardized, utilitarian, and consequential.\\n6. Go back to arxiv.org\\n7. Find \\\"Physics and Society\\\" and go to the page for the \\\"Physics and Society\\\" category.\\n8. Note that the tag for this category is \\\"physics.soc-ph\\\".\\n9. Go to the Advanced Search page.\\n10. Enter \\\"physics.soc-ph\\\" in the search box and select \\\"All fields\\\" from the dropdown.\\n11. Enter 2016-08-11 and 2016-08-12 into the date inputs, select \\\"Submission date (original)\\\", and submit the search.\\n12. Search for instances of the six words in the results to find the paper titled \\\"Phase transition from egalitarian to hierarchical societies driven by competition between cognitive and social constraints\\\", indicating that \\\"egalitarian\\\" is the correct answer.\", \"Number of steps\": \"12\", \"How long did this take?\": \"8 minutes\", \"Tools\": \"1. Web browser\\n2. Image recognition tools (to identify and parse a figure with three axes)\", \"Number of tools\": \"2\"}}\n",
"\n",
"import random\n",
"# random.seed(42)\n",
"random_samples = random.sample(json_QA, 1)\n",
"for sample in random_samples:\n",
" print(\"=\" * 50)\n",
" print(f\"Task ID: {sample['task_id']}\")\n",
" print(f\"Question: {sample['Question']}\")\n",
" print(f\"Level: {sample['Level']}\")\n",
" print(f\"Final Answer: {sample['Final answer']}\")\n",
" print(f\"Annotator Metadata: \")\n",
" print(f\" ├── Steps: \")\n",
" for step in sample['Annotator Metadata']['Steps'].split('\\n'):\n",
" print(f\" │ ├── {step}\")\n",
" print(f\" ├── Number of steps: {sample['Annotator Metadata']['Number of steps']}\")\n",
" print(f\" ├── How long did this take?: {sample['Annotator Metadata']['How long did this take?']}\")\n",
" print(f\" ├── Tools:\")\n",
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
" print(f\" │ ├── {tool}\")\n",
" print(f\" └── Number of tools: {sample['Annotator Metadata']['Number of tools']}\")\n",
"print(\"=\" * 50)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fdd11b62",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/csefrassia/.pyenv/versions/3.12.9/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"### build a vector database based on the metadata.jsonl\n",
"# https://python.langchain.com/docs/integrations/vectorstores/supabase/\n",
"import os\n",
"from dotenv import load_dotenv\n",
"from langchain_huggingface import HuggingFaceEmbeddings\n",
"from langchain_community.vectorstores import SupabaseVectorStore\n",
"from supabase.client import Client, create_client\n",
"\n",
"\n",
"load_dotenv()\n",
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\") # dim=768\n",
"\n",
"supabase_url = os.environ.get(\"SUPABASE_URL\")\n",
"supabase_key = os.environ.get(\"SUPABASE_SERVICE_KEY\")\n",
"supabase: Client = create_client(supabase_url, supabase_key)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "04babae7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"service_role\n"
]
}
],
"source": [
"import jwt\n",
"import os\n",
"\n",
"token = os.environ[\"SUPABASE_SERVICE_KEY\"]\n",
"decoded = jwt.decode(token, options={\"verify_signature\": False})\n",
"print(decoded[\"role\"])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c8eda3dc",
"metadata": {},
"outputs": [],
"source": [
"# wrap the metadata.jsonl's questions and answers into a list of document\n",
"from langchain.schema import Document\n",
"docs = []\n",
"for sample in json_QA:\n",
" content = f\"Question : {sample['Question']}\\n\\nFinal answer : {sample['Final answer']}\"\n",
" doc = {\n",
" \"content\" : content,\n",
" \"metadata\" : { # meatadata的格式必须时source键,否则会报错\n",
" \"source\" : sample['task_id']\n",
" },\n",
" \"embedding\" : embeddings.embed_query(content),\n",
" }\n",
" docs.append(doc)\n",
"\n",
"# upload the documents to the vector database\n",
"try:\n",
" response = (\n",
" supabase.table(\"documents\")\n",
" .insert(docs)\n",
" .execute()\n",
" )\n",
"except Exception as exception:\n",
" print(\"Error inserting data into Supabase:\", exception)\n",
"\n",
"# ALTERNATIVE : Save the documents (a list of dict) into a csv file, and manually upload it to Supabase\n",
"# import pandas as pd\n",
"# df = pd.DataFrame(docs)\n",
"# df.to_csv('supabase_docs.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "406643cc",
"metadata": {},
"outputs": [],
"source": [
"# add items to vector database\n",
"vector_store = SupabaseVectorStore(\n",
" client=supabase,\n",
" embedding= embeddings,\n",
" table_name=\"documents\",\n",
" query_name=\"match_documents_langchain\",\n",
")\n",
"retriever = vector_store.as_retriever()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "93faf53b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Document(metadata={'source': '840bfca7-4f7b-481a-8794-c560c340185d'}, page_content='Question : On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\\n\\nFinal answer : 80GSFC21M0002')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?\"\n",
"# matched_docs = vector_store.similarity_search(query, 2)\n",
"docs = retriever.invoke(query)\n",
"docs[0]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a26cb46d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"List of tools used in all samples:\n",
"Total number of tools used: 83\n",
" ├── web browser: 107\n",
" ├── image recognition tools (to identify and parse a figure with three axes): 1\n",
" ├── search engine: 101\n",
" ├── calculator: 34\n",
" ├── unlambda compiler (optional): 1\n",
" ├── a web browser.: 2\n",
" ├── a search engine.: 2\n",
" ├── a calculator.: 1\n",
" ├── microsoft excel: 5\n",
" ├── google search: 1\n",
" ├── ne: 9\n",
" ├── pdf access: 7\n",
" ├── file handling: 2\n",
" ├── python: 3\n",
" ├── image recognition tools: 12\n",
" ├── jsonld file access: 1\n",
" ├── video parsing: 1\n",
" ├── python compiler: 1\n",
" ├── video recognition tools: 3\n",
" ├── pdf viewer: 7\n",
" ├── microsoft excel / google sheets: 3\n",
" ├── word document access: 1\n",
" ├── tool to extract text from images: 1\n",
" ├── a word reversal tool / script: 1\n",
" ├── counter: 1\n",
" ├── excel: 3\n",
" ├── image recognition: 5\n",
" ├── color recognition: 3\n",
" ├── excel file access: 3\n",
" ├── xml file access: 1\n",
" ├── access to the internet archive, web.archive.org: 1\n",
" ├── text processing/diff tool: 1\n",
" ├── gif parsing tools: 1\n",
" ├── a web browser: 7\n",
" ├── a search engine: 7\n",
" ├── a speech-to-text tool: 2\n",
" ├── code/data analysis tools: 1\n",
" ├── audio capability: 2\n",
" ├── pdf reader: 1\n",
" ├── markdown: 1\n",
" ├── a calculator: 5\n",
" ├── access to wikipedia: 3\n",
" ├── image recognition/ocr: 3\n",
" ├── google translate access: 1\n",
" ├── ocr: 4\n",
" ├── bass note data: 1\n",
" ├── text editor: 1\n",
" ├── xlsx file access: 1\n",
" ├── powerpoint viewer: 1\n",
" ├── csv file access: 1\n",
" ├── calculator (or use excel): 1\n",
" ├── computer algebra system: 1\n",
" ├── video processing software: 1\n",
" ├── audio processing software: 1\n",
" ├── computer vision: 1\n",
" ├── google maps: 1\n",
" ├── access to excel files: 1\n",
" ├── calculator (or ability to count): 1\n",
" ├── a file interface: 3\n",
" ├── a python ide: 1\n",
" ├── spreadsheet editor: 1\n",
" ├── tools required: 1\n",
" ├── b browser: 1\n",
" ├── image recognition and processing tools: 1\n",
" ├── computer vision or ocr: 1\n",
" ├── c++ compiler: 1\n",
" ├── access to google maps: 1\n",
" ├── youtube player: 1\n",
" ├── natural language processor: 1\n",
" ├── graph interaction tools: 1\n",
" ├── bablyonian cuniform -> arabic legend: 1\n",
" ├── access to youtube: 1\n",
" ├── image search tools: 1\n",
" ├── calculator or counting function: 1\n",
" ├── a speech-to-text audio processing tool: 1\n",
" ├── access to academic journal websites: 1\n",
" ├── pdf reader/extracter: 1\n",
" ├── rubik's cube model: 1\n",
" ├── wikipedia: 1\n",
" ├── video capability: 1\n",
" ├── image processing tools: 1\n",
" ├── age recognition software: 1\n",
" ├── youtube: 1\n"
]
}
],
"source": [
"# list of the tools used in all the samples\n",
"from collections import Counter, OrderedDict\n",
"\n",
"tools = []\n",
"for sample in json_QA:\n",
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
" tool = tool[2:].strip().lower()\n",
" if tool.startswith(\"(\"):\n",
" tool = tool[11:].strip()\n",
" tools.append(tool)\n",
"tools_counter = OrderedDict(Counter(tools))\n",
"print(\"List of tools used in all samples:\")\n",
"print(\"Total number of tools used:\", len(tools_counter))\n",
"for tool, count in tools_counter.items():\n",
" print(f\" ├── {tool}: {count}\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "cdfc8075",
"metadata": {},
"outputs": [],
"source": [
"system_prompt = \"\"\"\n",
"You are a helpful assistant tasked with answering questions using a set of tools.\n",
"If the tool is not available, you can try to find the information online. You can also use your own knowledge to answer the question. \n",
"You need to provide a step-by-step explanation of how you arrived at the answer.\n",
"==========================\n",
"Here is a few examples showing you how to answer the question step by step.\n",
"\"\"\"\n",
"for i, samples in enumerate(random_samples):\n",
" system_prompt += f\"\\nQuestion {i+1}: {samples['Question']}\\nSteps:\\n{samples['Annotator Metadata']['Steps']}\\nTools:\\n{samples['Annotator Metadata']['Tools']}\\nFinal Answer: {samples['Final answer']}\\n\"\n",
"system_prompt += \"\\n==========================\\n\"\n",
"system_prompt += \"Now, please answer the following question step by step.\\n\"\n",
"\n",
"# save the system_prompt to a file\n",
"with open('system_prompt.txt', 'w') as f:\n",
" f.write(system_prompt)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "186b13af",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"You are a helpful assistant tasked with answering questions using a set of tools.\n",
"If the tool is not available, you can try to find the information online. You can also use your own knowledge to answer the question. \n",
"You need to provide a step-by-step explanation of how you arrived at the answer.\n",
"==========================\n",
"Here is a few examples showing you how to answer the question step by step.\n",
"\n",
"Question 1: What is the absolute difference in tens of thousands between the population of chinstrap penguins on the Wikipedia page for penguin species populations as of the end of 2018 and the population recorded in the Nature.com \"global population assessment of the Chinstrap penguin\" article from 2020, assuming two penguins per breeding pair?\n",
"Steps:\n",
"1. Searched \"penguin species populations wikipedia\" on Google search.\n",
"2. Opened the \"List of Sphenisciformes by population\" Wikipedia article.\n",
"3. Clicked \"View history\".\n",
"4. Scrolled to the end of 2018 and opened the page.\n",
"5. Scrolled to the encoding for the population table.\n",
"6. Recorded the number of chinstrap penguins (8 million).\n",
"7. Searched \"Nature.com global population assessment of the Chinstrap penguin 2020\" in Google search.\n",
"8. Opened the top link to the article with the corresponding name and date.\n",
"9. Read the abstract and noted the number of breeding pairs (3.42 million).\n",
"10. Multiplied the breeding pairs by 2 to get the number of penguins (6.84 million).\n",
"11. Subtracted the Wikipedia population from the Nature.com population (1.16 million).\n",
"12. Multiplied 1.16 by 100 to get tens of thousands (116).\n",
"Tools:\n",
"1. Search engine\n",
"2. Web browser\n",
"3. Calculator\n",
"Final Answer: 116\n",
"\n",
"==========================\n",
"Now, please answer the following question step by step.\n",
"\n"
]
}
],
"source": [
"# load the system prompt from the file\n",
"with open('system_prompt.txt', 'r') as f:\n",
" system_prompt = f.read()\n",
"print(system_prompt)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "3a162284",
"metadata": {},
"outputs": [],
"source": [
"import dotenv\n",
"from langgraph.graph import MessagesState, START, StateGraph\n",
"from langgraph.prebuilt import tools_condition\n",
"from langgraph.prebuilt import ToolNode\n",
"from langchain_openai import ChatOpenAI\n",
"from langchain_huggingface import HuggingFaceEmbeddings\n",
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
"from langchain_community.document_loaders import WikipediaLoader\n",
"from langchain_community.document_loaders import ArxivLoader\n",
"from langchain_community.vectorstores import SupabaseVectorStore\n",
"from langchain.tools.retriever import create_retriever_tool\n",
"from langchain_core.messages import HumanMessage, SystemMessage\n",
"from langchain_core.tools import tool\n",
"from supabase.client import Client, create_client\n",
"\n",
"# Define the retriever from supabase\n",
"load_dotenv()\n",
"\n",
"\n",
"\n",
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\") # dim=768\n",
"\n",
"supabase_url = os.environ.get(\"SUPABASE_URL\")\n",
"supabase_key = os.environ.get(\"SUPABASE_SERVICE_KEY\")\n",
"supabase: Client = create_client(supabase_url, supabase_key)\n",
"vector_store = SupabaseVectorStore(\n",
" client=supabase,\n",
" embedding= embeddings,\n",
" table_name=\"documents\",\n",
" query_name=\"match_documents_langchain\",\n",
")\n",
"\n",
"question_retrieve_tool = create_retriever_tool(\n",
" vector_store.as_retriever(),\n",
" \"question_retriever\",\n",
" \"Find similar questions in the vector database for the given question.\",\n",
")\n",
"\n",
"@tool\n",
"def multiply(a: int, b: int) -> int:\n",
" \"\"\"Multiply two numbers.\n",
"\n",
" Args:\n",
" a: first int\n",
" b: second int\n",
" \"\"\"\n",
" return a * b\n",
"\n",
"@tool\n",
"def add(a: int, b: int) -> int:\n",
" \"\"\"Add two numbers.\n",
" \n",
" Args:\n",
" a: first int\n",
" b: second int\n",
" \"\"\"\n",
" return a + b\n",
"\n",
"@tool\n",
"def subtract(a: int, b: int) -> int:\n",
" \"\"\"Subtract two numbers.\n",
" \n",
" Args:\n",
" a: first int\n",
" b: second int\n",
" \"\"\"\n",
" return a - b\n",
"\n",
"@tool\n",
"def divide(a: int, b: int) -> int:\n",
" \"\"\"Divide two numbers.\n",
" \n",
" Args:\n",
" a: first int\n",
" b: second int\n",
" \"\"\"\n",
" if b == 0:\n",
" raise ValueError(\"Cannot divide by zero.\")\n",
" return a / b\n",
"\n",
"@tool\n",
"def modulus(a: int, b: int) -> int:\n",
" \"\"\"Get the modulus of two numbers.\n",
" \n",
" Args:\n",
" a: first int\n",
" b: second int\n",
" \"\"\"\n",
" return a % b\n",
"\n",
"@tool\n",
"def wiki_search(query: str) -> str:\n",
" \"\"\"Search Wikipedia for a query and return maximum 2 results.\n",
" \n",
" Args:\n",
" query: The search query.\"\"\"\n",
" search_docs = WikipediaLoader(query=query, load_max_docs=2).load()\n",
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
" [\n",
" f'\\n{doc.page_content}\\n'\n",
" for doc in search_docs\n",
" ])\n",
" return {\"wiki_results\": formatted_search_docs}\n",
"\n",
"@tool\n",
"def web_search(query: str) -> str:\n",
" \"\"\"Search Tavily for a query and return maximum 3 results.\n",
" \n",
" Args:\n",
" query: The search query.\"\"\"\n",
" search_docs = TavilySearchResults(max_results=3).invoke(query=query)\n",
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
" [\n",
" f'\\n{doc.page_content}\\n'\n",
" for doc in search_docs\n",
" ])\n",
" return {\"web_results\": formatted_search_docs}\n",
"\n",
"@tool\n",
"def arvix_search(query: str) -> str:\n",
" \"\"\"Search Arxiv for a query and return maximum 3 result.\n",
" \n",
" Args:\n",
" query: The search query.\"\"\"\n",
" search_docs = ArxivLoader(query=query, load_max_docs=3).load()\n",
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
" [\n",
" f'\\n{doc.page_content[:1000]}\\n'\n",
" for doc in search_docs\n",
" ])\n",
" return {\"arvix_results\": formatted_search_docs}\n",
"\n",
"@tool\n",
"def similar_question_search(question: str) -> str:\n",
" \"\"\"Search the vector database for similar questions and return the first results.\n",
" \n",
" Args:\n",
" question: the question human provided.\"\"\"\n",
" matched_docs = vector_store.similarity_search(query, 3)\n",
" formatted_search_docs = \"\\n\\n---\\n\\n\".join(\n",
" [\n",
" f'\\n{doc.page_content[:1000]}\\n'\n",
" for doc in matched_docs\n",
" ])\n",
" return {\"similar_questions\": formatted_search_docs}\n",
"\n",
"tools = [\n",
" multiply,\n",
" add,\n",
" subtract,\n",
" divide,\n",
" modulus,\n",
" wiki_search,\n",
" web_search,\n",
" arvix_search,\n",
" question_retrieve_tool\n",
"]\n",
"\n",
"\n",
"llm = ChatOpenAI(\n",
" model=os.environ.get(\"OPENAI_MODEL_NAME\", \"gpt-4o\"),\n",
" temperature=0.0\n",
")\n",
"llm_with_tools = llm.bind_tools(tools)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8fac9099",
"metadata": {},
"outputs": [],
"source": [
"# load the system prompt from the file\n",
"with open('system_prompt.txt', 'r') as f:\n",
" system_prompt = f.read()\n",
"\n",
"\n",
"# System message\n",
"sys_msg = SystemMessage(content=system_prompt)\n",
"\n",
"# Node\n",
"def assistant(state: MessagesState):\n",
" \"\"\"Assistant node\"\"\"\n",
" return {\"messages\": [llm_with_tools.invoke([sys_msg] + state[\"messages\"])]}\n",
"\n",
"# Build graph\n",
"builder = StateGraph(MessagesState)\n",
"builder.add_node(\"assistant\", assistant)\n",
"builder.add_node(\"tools\", ToolNode(tools))\n",
"builder.add_edge(START, \"assistant\")\n",
"builder.add_conditional_edges(\n",
" \"assistant\",\n",
" # If the latest message (result) from assistant is a tool call -> tools_condition routes to tools\n",
" # If the latest message (result) from assistant is a not a tool call -> tools_condition routes to END\n",
" tools_condition,\n",
")\n",
"builder.add_edge(\"tools\", \"assistant\")\n",
"\n",
"# Compile graph\n",
"graph = builder.compile()\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b91dcb05",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANgAAAD5CAIAAADKsmwpAAAQAElEQVR4nOzdB1xT1x4H8JNBQhIIkLCXAqKCKG6qtI7qw1EXTtC2jmfr6mut2qGttVpbbWuf1omrddddreLWJ+6+WieIgiAWEiKbkL14f8gr5fECassN5+ae74dPPuHekEDy48x7z+VWVlYigmhqXEQQGCBBJLBAgkhggQSRwAIJIoEFEkQCCySIdRl05iKZQVNh1lSYzKZKo4EGw1t8AZvLYwlduUJXtk+wANEQi4wjWmlUpsxfVdmp6hKF3t2bJ3TlwOcqlnCNehq8P07O7FIF/POYII6P0zWhUS6h7URh7VwQfZAgIngHrhwpVuRovYKcQ6NEgeFCRGcGnSU7VZX7QCt7qO0+WNqyoyuiA6YHMf1n5dndBfCBdXzZAzmWilIj/INBMRn3mq9IjHsbjNFBvHCwkOOEYgd7IcdV8kR/aI2871if4NZYl/TMDeK/9hVIfHjRPdwRAxxOkr0wUOoT7IxwxdAgHtkgD2olbN+TESm0OrxO1rqLuFVnTJuMbMQ8V44U+YcJGJVCMHRawI1zpUVyPcIS44KYebMCbjv1cbSuybNIfD8YmsWVFhzrQMYFMeVAYYfeTEyhVWhbl0uHixB+mBXEm+dLW3cWC1w4iKmgQZJ5U6VWmhBmmBXEnDR1t8ESxGw9hnveSilDmGFQEHPuqblObA6Hif2z2oJbi1IvlyPMMOhTeXRXHdJWhOzrgw8+OHLkCHp+ffv2lcvliAI8Z7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2bpc8dki9i+bjdb1m4llcOFhoNFaGtRNL/Wmwqj6MqJQX6v+1W/HaR8Gi+scrSBBpKfVqedoVpV5j1mmoWhmmUXgF8ssKDCFtRbGDPRu+nCUJIo3BR2fQYR3ESkuls+iZJq5IEAkskHFEAgskiAQWSBAJLJAgElggQSSwQIJIYOE/AAAA//9IOO73AAAABklEQVQDAFPPIzkUheU2AAAAAElFTkSuQmCC",
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import Image, display\n",
"\n",
"display(Image(graph.get_graph(xray=True).draw_mermaid_png()))"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "988462ef",
"metadata": {},
"outputs": [],
"source": [
"question = \"\"\n",
"messages = [HumanMessage(content=question)]\n",
"messages = graph.invoke({\"messages\": messages})"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "ef3ac15c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================\u001b[1m Human Message \u001b[0m=================================\n",
"\n",
"\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
"It seems like your message was empty. Could you please provide more details or ask a question?\n"
]
}
],
"source": [
"for m in messages['messages']:\n",
" m.pretty_print()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "3.12.9",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}