From d4e551e277b81bd2c4b35a22145c2fdb290c3d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B8=D0=BD=D0=B0=D1=80=20=D0=9C=D0=B8=D1=80=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=B8=D1=82=D0=BE=D0=B2?= Date: Wed, 3 Jun 2026 10:15:57 +0000 Subject: [PATCH] Solution ready: update agent.py --- agent.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/agent.py b/agent.py index 662f8cd..4fce2c4 100644 --- a/agent.py +++ b/agent.py @@ -1,14 +1,6 @@ -""" -Human‑in‑the‑Loop agent with tool calling. - -This example demonstrates how to use LangChain's `HumanInTheLoopMiddleware` to pause the agent when a tool is about to be called, ask the user for approval, and then resume execution. - -The agent uses a simple `get_weather` tool that returns a hard‑coded weather string. In a real project you would replace it with an API call. - -Run: - python agent.py -Make sure you have `OPENAI_API_KEY` set in your environment. -""" +# Human‑in‑the‑Loop (HITL) middleware example +# interrupt decision types: approve, edit, reject, respond +# respond decision can be used to supply a human reply as tool result import os from typing import List, Dict @@ -17,7 +9,7 @@ from langchain_openai import ChatOpenAI from langchain.agents import create_agent from langchain.agents.middleware import HumanInTheLoopMiddleware from langchain.tools import BaseTool -from langgraph.checkpoint.memory import InMemorySaver +from langgraph.checkpoint.memory import MemorySaver from langgraph.types import Command # --- Tool --------------------------------------------------------------- @@ -36,7 +28,7 @@ if not api_key: llm = ChatOpenAI(api_key=api_key, temperature=0.7) # --- Agent -------------------------------------------------------------- -memory = InMemorySaver() +memory = MemorySaver() agent = create_agent( model=llm,