[PR #4583] Implement post_model_hook and HumanInterruptNode #3932

Closed
opened 2026-02-20 17:49:23 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/4583

State: closed
Merged: Yes


Sample usage:

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.prebuilt.interrupt import HumanInterruptConfig, InterruptToolNode

def get_weather(city: str) -> str:
    """Get the weather for a given city."""
    return f"The weather in {city} is sunny."


agent = create_react_agent(
    ChatOpenAI(model="gpt-3.5-turbo",),
    tools=[get_weather],
    prompt="You are a helpful weather assistant.",
    post_model_hook=InterruptToolNode(
        get_weather=HumanInterruptConfig(
              allow_accept=True,
              allow_edit=True,
              allow_ignore=True,
              allow_respond=True,
          )
    ),
    checkpointer=InMemorySaver(),
)

Sample behavior:

==============================================================
RUNNING: ./test_prebuilts/accept.py
==============================================================

================================ Human Message =================================

what is the weather in sf?
================================== Ai Message ==================================
Tool Calls:
  get_weather (call_TJaaMv6iXNTxmusv3hxJKCB0)
 Call ID: call_TJaaMv6iXNTxmusv3hxJKCB0
  Args:
    city: San Francisco
================================= Tool Message =================================
Name: get_weather

The weather in San Francisco is sunny.
================================== Ai Message ==================================

The weather in San Francisco is sunny.



==============================================================
RUNNING: ./test_prebuilts/edit.py
==============================================================

================================ Human Message =================================

what is the weather in sf?
================================== Ai Message ==================================
Tool Calls:
  get_weather (call_fI8cjf7SWc4V7Y0z6ahNIQHY)
 Call ID: call_fI8cjf7SWc4V7Y0z6ahNIQHY
  Args:
    city: new york city
================================= Tool Message =================================
Name: get_weather

The weather in new york city is sunny.
================================== Ai Message ==================================

The weather in New York City is sunny.



==============================================================
RUNNING: ./test_prebuilts/ignore.py
==============================================================

================================ Human Message =================================

what is the weather in sf?
================================== Ai Message ==================================
Tool Calls:
  get_weather (call_EoDCkXb60mh0tAzCPov2ipCF)
 Call ID: call_EoDCkXb60mh0tAzCPov2ipCF
  Args:
    city: San Francisco
================================= Tool Message =================================
Name: get_weather

User ignored the tool call: get_weather:call_EoDCkXb60mh0tAzCPov2ipCF
================================== Ai Message ==================================

I'm sorry, but I couldn't retrieve the weather information for San Francisco at the moment. Let me try again.
Tool Calls:
  get_weather (call_9U9pJKDili3Al0uu187ykIuF)
 Call ID: call_9U9pJKDili3Al0uu187ykIuF
  Args:
    city: San Francisco



==============================================================
RUNNING: ./test_prebuilts/response.py
==============================================================

================================ Human Message =================================

what is the weather in sf?
================================== Ai Message ==================================
Tool Calls:
  get_weather (call_jaUBParDqSQrKvPyiEH6pMFS)
 Call ID: call_jaUBParDqSQrKvPyiEH6pMFS
  Args:
    city: San Francisco
================================= Tool Message =================================
Name: get_weather

actually, please fetch the weather in NYC
================================== Ai Message ==================================
Tool Calls:
  get_weather (call_2KeaoS4u1WZ7QpFgwFQfadBe)
 Call ID: call_2KeaoS4u1WZ7QpFgwFQfadBe
  Args:
    city: New York City
================================= Tool Message =================================
Name: get_weather

The weather in New York City is sunny.
================================== Ai Message ==================================

The weather in New York City is sunny.
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/4583 **State:** closed **Merged:** Yes --- Sample usage: ```py from langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent from langgraph.checkpoint.memory import InMemorySaver from langgraph.prebuilt.interrupt import HumanInterruptConfig, InterruptToolNode def get_weather(city: str) -> str: """Get the weather for a given city.""" return f"The weather in {city} is sunny." agent = create_react_agent( ChatOpenAI(model="gpt-3.5-turbo",), tools=[get_weather], prompt="You are a helpful weather assistant.", post_model_hook=InterruptToolNode( get_weather=HumanInterruptConfig( allow_accept=True, allow_edit=True, allow_ignore=True, allow_respond=True, ) ), checkpointer=InMemorySaver(), ) ``` Sample behavior: ``` ============================================================== RUNNING: ./test_prebuilts/accept.py ============================================================== ================================ Human Message ================================= what is the weather in sf? ================================== Ai Message ================================== Tool Calls: get_weather (call_TJaaMv6iXNTxmusv3hxJKCB0) Call ID: call_TJaaMv6iXNTxmusv3hxJKCB0 Args: city: San Francisco ================================= Tool Message ================================= Name: get_weather The weather in San Francisco is sunny. ================================== Ai Message ================================== The weather in San Francisco is sunny. ============================================================== RUNNING: ./test_prebuilts/edit.py ============================================================== ================================ Human Message ================================= what is the weather in sf? ================================== Ai Message ================================== Tool Calls: get_weather (call_fI8cjf7SWc4V7Y0z6ahNIQHY) Call ID: call_fI8cjf7SWc4V7Y0z6ahNIQHY Args: city: new york city ================================= Tool Message ================================= Name: get_weather The weather in new york city is sunny. ================================== Ai Message ================================== The weather in New York City is sunny. ============================================================== RUNNING: ./test_prebuilts/ignore.py ============================================================== ================================ Human Message ================================= what is the weather in sf? ================================== Ai Message ================================== Tool Calls: get_weather (call_EoDCkXb60mh0tAzCPov2ipCF) Call ID: call_EoDCkXb60mh0tAzCPov2ipCF Args: city: San Francisco ================================= Tool Message ================================= Name: get_weather User ignored the tool call: get_weather:call_EoDCkXb60mh0tAzCPov2ipCF ================================== Ai Message ================================== I'm sorry, but I couldn't retrieve the weather information for San Francisco at the moment. Let me try again. Tool Calls: get_weather (call_9U9pJKDili3Al0uu187ykIuF) Call ID: call_9U9pJKDili3Al0uu187ykIuF Args: city: San Francisco ============================================================== RUNNING: ./test_prebuilts/response.py ============================================================== ================================ Human Message ================================= what is the weather in sf? ================================== Ai Message ================================== Tool Calls: get_weather (call_jaUBParDqSQrKvPyiEH6pMFS) Call ID: call_jaUBParDqSQrKvPyiEH6pMFS Args: city: San Francisco ================================= Tool Message ================================= Name: get_weather actually, please fetch the weather in NYC ================================== Ai Message ================================== Tool Calls: get_weather (call_2KeaoS4u1WZ7QpFgwFQfadBe) Call ID: call_2KeaoS4u1WZ7QpFgwFQfadBe Args: city: New York City ================================= Tool Message ================================= Name: get_weather The weather in New York City is sunny. ================================== Ai Message ================================== The weather in New York City is sunny. ```
yindo added the pull-request label 2026-02-20 17:49:23 -05:00
yindo closed this issue 2026-02-20 17:49:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#3932