{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%%capture --no-stderr\n", "%pip install -U tavily-python langchain_community" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from typing import Annotated\n", "\n", "from langchain_openai import ChatOpenAI as Chat\n", "from langchain_community.tools.tavily_search import TavilySearchResults\n", "from langchain_core.messages import BaseMessage\n", "# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n", "from pydantic import BaseModel\n", "from typing_extensions import TypedDict\n", "\n", "from langgraph.checkpoint.memory import MemorySaver\n", "from langgraph.graph import StateGraph\n", "from langgraph.graph.message import add_messages\n", "from langgraph.prebuilt import ToolNode, tools_condition\n", "\n", "import os\n", "from dotenv import load_dotenv\n", "\n", "load_dotenv()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "openai_api_key = os.getenv(\"OPENAI_API_KEY\")\n", "model = os.getenv(\"OPENAI_MODEL\", \"gpt-4o\")\n", "temperature = float(os.getenv(\"OPENAI_TEMPERATURE\", 0))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "class State(TypedDict):\n", " messages: Annotated[list, add_messages]\n", " # This flag is new\n", " ask_human: bool" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "class RequestAssistance(BaseModel):\n", " \"\"\"Escalate the conversation to an expert. Use this if you are unable to assist directly or if the user requires support beyond your permissions.\n", "\n", " To use this function, relay the user's 'request' so the expert can provide the right guidance.\n", " \"\"\"\n", "\n", " request: str\n", "\n", "\n", "tool = TavilySearchResults(max_results=2)\n", "tools = [tool]\n", "llm = Chat(\n", " openai_api_key=openai_api_key,\n", " model=model,\n", " temperature=temperature\n", ")\n", "# We can bind the llm to a tool definition, a pydantic model, or a json schema\n", "llm_with_tools = llm.bind_tools(tools + [RequestAssistance])\n", "\n", "\n", "def chatbot(state: State):\n", " response = llm_with_tools.invoke(state[\"messages\"])\n", " ask_human = False\n", " if (\n", " response.tool_calls\n", " and response.tool_calls[0][\"name\"] == RequestAssistance.__name__\n", " ):\n", " ask_human = True\n", " return {\"messages\": [response], \"ask_human\": ask_human}" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "graph_builder = StateGraph(State)\n", "\n", "graph_builder.add_node(\"chatbot\", chatbot)\n", "graph_builder.add_node(\"tools\", ToolNode(tools=[tool]))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "from langchain_core.messages import AIMessage, ToolMessage\n", "\n", "def create_response(response: str, ai_message: AIMessage):\n", " return ToolMessage(\n", " content=response,\n", " tool_call_id=ai_message.tool_calls[0][\"id\"],\n", " )\n", "\n", "\n", "def human_node(state: State):\n", " new_messages = []\n", " if not isinstance(state[\"messages\"][-1], ToolMessage):\n", " # Typically, the user will have updated the state during the interrupt.\n", " # If they choose not to, we will include a placeholder ToolMessage to\n", " # let the LLM continue.\n", " new_messages.append(\n", " create_response(\"No response from human.\", state[\"messages\"][-1])\n", " )\n", " return {\n", " # Append the new messages\n", " \"messages\": new_messages,\n", " # Unset the flag\n", " \"ask_human\": False,\n", " }" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "graph_builder.add_node(\"human\", human_node)\n", "\n", "\n", "def select_next_node(state: State):\n", " if state[\"ask_human\"]:\n", " return \"human\"\n", " # Otherwise, we can route as before\n", " return tools_condition(state)\n", "\n", "\n", "graph_builder.add_conditional_edges(\n", " \"chatbot\",\n", " select_next_node,\n", " {\"human\": \"human\", \"tools\": \"tools\", \"__end__\": \"__end__\"},\n", ")\n", "graph_builder.add_edge(\"tools\", \"chatbot\")\n", "graph_builder.add_edge(\"human\", \"chatbot\")\n", "graph_builder.set_entry_point(\"chatbot\")\n", "memory = MemorySaver()\n", "graph = graph_builder.compile(\n", " checkpointer=memory,\n", " interrupt_before=[\"human\"],\n", ")" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAEjAaMDASIAAhEBAxEB/8QAHQABAAMBAAMBAQAAAAAAAAAAAAUGBwQCAwgBCf/EAFgQAAEEAQIDAggICQgGBgsAAAEAAgMEBQYRB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WdsM67t8bEW4P542tP+BTIw9/lJaNrvy2eq4PsKMDG2MjK3arjoSA9wHTcj+jGPS89B/aQD5adwz8TWnksvZNkbkvjFuZgPK6QgDZu/Xla1rWj8zRv1JXswunMbp6OVmPqMrmUh0su5dJKR0Be9xLnnb0uJKkljVVTEZNGj9zyERFpQREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQFnvH8gcIs/uSBtB3f9vH+cLQlnvH/f8EWf2232g+Ntt/p4/Wg0JERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQFnnhAjfhDqDqG9IOpHT/TxrQ1nnhA7fgh1Bv0G0Ho3/18aDQ0REBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEUPqHUIworwwwG5kLTi2vWDuUO225nOdseVjQRudj3gAEkAwJzuryemPwgHqNyY7f39l1XRRgV1xlRa3GbLZdkVI+HdYfMMH73N/DT4d1h8wwfvc38NbO617Y9YLLuvk3w7PCTt8F8RU07No6TK4vUFcOiy7b4ibHNHKHPiMZiduQ0MO+4+P3eb13v4d1h8wwfvc38NZn4QnCPLeERw+fpfM1sPS5bEdqtehsSukgkaepAMY3BaXNI/Pv6E7rXtj1gsufg5cZbnHvhnX1jZ0zJpeC3YkjqVpLYsmaFmw7Xm5GbAv527bf0N9+vTUFmumINQ6P05jMHisTgq2Nx1aOrXiFubzY2NDR/q+p2HU+kqT+HdYfMMH73N/DTute2PWCy7oqR8O6w+YYP3ub+Gnw7rD5hg/e5v4ad1r2x6wWXdFS2ai1XDu+bE4qxG3qYq92Rsjht/R5o+Xf1AkD1kK0YjK183jobtVznQyg7c7S1zSCQ5rgeoIIIIPcQVqxMGvDi86OE3LOxERaEEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERBStRn/wB4uEHqxV4j838tVUkozUf84+E/RN3/ADqqk16v5eH5e8sp1CI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yHtnm/qKX3dPIDIe2eb+opfd0vh78c+hbi70XB5AZD2zzf1FL7unkBkPbPN/UUvu6Xw9+OfQtxd6Lg8gMh7Z5v6il93TyAyHtnm/qKX3dL4e/HPoW4u9FweQGQ9s839RS+7p5AZD2zzf1FL7ul8Pfjn0LcXei4PIDIe2eb+opfd08gMh7Z5v6il93S+Hvxz6FuLvRcHkBkPbPN/UUvu6eQGQ9s839RS+7pfD3459C3F3ouDyAyHtnm/qKX3dPIDIe2eb+opfd0vh78c+hbi70XB5AZD2zzf1FL7uvJmgbm5Eurs1Mw97ezqM36+tsAI/uPpUvh78c+hbi/eH7CL2rZQd2S5cFp2PoqVmH/wATXD+5W9cmKxVXCY+GlShEFaIENbuXEkkkuJO5c4kklxJJJJJJJXWuLGrjErmqNHTMTnERFpQREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERB//9k=", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Image, display\n", "\n", "try:\n", " display(Image(graph.get_graph().draw_mermaid_png()))\n", "except Exception:\n", " # This requires some extra dependencies and is optional\n", " pass" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "================================\u001b[1m Human Message \u001b[0m=================================\n", "\n", "I need some expert guidance for building this AI agent. Could you request assistance for me?\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "Tool Calls:\n", " RequestAssistance (call_I7J538pxIJ61RlE8CTndDi5i)\n", " Call ID: call_I7J538pxIJ61RlE8CTndDi5i\n", " Args:\n", " request: I need expert guidance for building an AI agent.\n" ] } ], "source": [ "user_input = \"I need some expert guidance for building this AI agent. Could you request assistance for me?\"\n", "config = {\"configurable\": {\"thread_id\": \"1\"}}\n", "# The config is the **second positional argument** to stream() or invoke()!\n", "events = graph.stream(\n", " {\"messages\": [(\"user\", user_input)]}, config, stream_mode=\"values\"\n", ")\n", "for event in events:\n", " if \"messages\" in event:\n", " event[\"messages\"][-1].pretty_print()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('human',)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "snapshot = graph.get_state(config)\n", "snapshot.next" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'configurable': {'thread_id': '1',\n", " 'checkpoint_ns': '',\n", " 'checkpoint_id': '1ef97775-7f9c-69e4-8002-c2bb25439766'}}" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ai_message = snapshot.values[\"messages\"][-1]\n", "human_response = (\n", " \"We, the experts are here to help! We'd recommend you check out LangGraph to build your agent.\"\n", " \" It's much more reliable and extensible than simple autonomous agents.\"\n", ")\n", "tool_message = create_response(human_response, ai_message)\n", "graph.update_state(config, {\"messages\": [tool_message]})" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[HumanMessage(content='I need some expert guidance for building this AI agent. Could you request assistance for me?', additional_kwargs={}, response_metadata={}, id='72a2beaf-917b-42e4-9e31-caa4d4617fc2'),\n", " AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_I7J538pxIJ61RlE8CTndDi5i', 'function': {'arguments': '{\"request\":\"I need expert guidance for building an AI agent.\"}', 'name': 'RequestAssistance'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 24, 'prompt_tokens': 160, 'total_tokens': 184, 'completion_tokens_details': {'audio_tokens': None, 'reasoning_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_a7d06e42a7', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-81f37266-03c6-48b9-b7c1-8c5de886bec1-0', tool_calls=[{'name': 'RequestAssistance', 'args': {'request': 'I need expert guidance for building an AI agent.'}, 'id': 'call_I7J538pxIJ61RlE8CTndDi5i', 'type': 'tool_call'}], usage_metadata={'input_tokens': 160, 'output_tokens': 24, 'total_tokens': 184, 'input_token_details': {'cache_read': 0}, 'output_token_details': {'reasoning': 0}}),\n", " ToolMessage(content=\"We, the experts are here to help! We'd recommend you check out LangGraph to build your agent. It's much more reliable and extensible than simple autonomous agents.\", id='7fa1dfff-e757-4941-82b9-73bdfc81cf33', tool_call_id='call_I7J538pxIJ61RlE8CTndDi5i')]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "graph.get_state(config).values[\"messages\"]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "=================================\u001b[1m Tool Message \u001b[0m=================================\n", "\n", "We, the experts are here to help! We'd recommend you check out LangGraph to build your agent. It's much more reliable and extensible than simple autonomous agents.\n", "=================================\u001b[1m Tool Message \u001b[0m=================================\n", "\n", "We, the experts are here to help! We'd recommend you check out LangGraph to build your agent. It's much more reliable and extensible than simple autonomous agents.\n", "==================================\u001b[1m Ai Message \u001b[0m==================================\n", "\n", "I've requested expert assistance for you, and the experts recommend checking out LangGraph for building your AI agent. It's noted to be more reliable and extensible than simple autonomous agents. If you need further assistance, feel free to ask!\n" ] } ], "source": [ "events = graph.stream(None, config, stream_mode=\"values\")\n", "for event in events:\n", " if \"messages\" in event:\n", " event[\"messages\"][-1].pretty_print()" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }