Solution ready: update agent.py
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user