Skip to main content
All writing

Integration guides1 min read

Human Approval for LangChain and LangGraph Agents, on Your Phone

LangGraph's interrupt() pauses a graph until your code resumes it. Sometimes the person who should decide isn't at the terminal. Here is a tool that waits for them.

LangGraph has a proper human-in-the-loop primitive. interrupt() inside a node or tool stops the graph, a checkpointer saves its state, and you resume it later with Command(resume=...). LangChain 1.x wraps the common case as HumanInTheLoopMiddleware for create_agent. Both leave one job to you: getting the question to a person and their answer back.

If your agent runs as a script, a worker or a scheduled job, the simplest version of that job is a tool that asks and waits. The Vibez.now request API does the asking: the request appears on your Requests page and your phone, and the tool continues only once someone approves it.

The helper

One file, standard library only, so it drops into any project. ask_human submits a request and polls until it is approved or rejected, and ask_human_sync is the blocking version. Every failure, a missing key included, returns False.

vibez_approval.py
"""Ask a person through Vibez.now before an agent does something risky.

    from vibez_approval import ask_human, ask_human_sync
    if await ask_human("Run: rm -rf build", "rm -rf build", source="my-agent"):
        ...

Submits a request (it appears on your Requests page and phone), then polls
until it is approved or rejected. An expired request comes back rejected.
Anything unexpected - no key, a network error, running out of time - counts
as "not approved", so a failure never lets the action through.
Python 3.9+, standard library only. Set VIBEZ_API_KEY; VIBEZ_SANDBOX=1 exercises
the API without creating anything (sandbox requests stay pending).
"""

import asyncio
import json
import os
import time
import urllib.error
import urllib.request

API = os.environ.get("VIBEZ_API_URL", "https://vibez.now/api")


def _call(path, body=None, idempotency_key=None):
    headers = {"Content-Type": "application/json", "x-api-key": os.environ["VIBEZ_API_KEY"]}
    if os.environ.get("VIBEZ_SANDBOX") == "1":
        headers["x-sandbox"] = "true"
    if idempotency_key:
        headers["x-idempotency-key"] = idempotency_key
    data = json.dumps(body).encode() if body is not None else None
    request = urllib.request.Request(API + path, data=data, headers=headers)
    for _ in range(5):
        try:
            with urllib.request.urlopen(request, timeout=30) as response:
                return json.load(response)
        except urllib.error.HTTPError as error:
            if error.code != 429:
                raise
            # Over 60 calls a minute: wait as long as the server says.
            time.sleep(int(error.headers.get("retry-after") or 10))
    raise RuntimeError(f"{path}: still rate limited")


def ask_human_sync(title, detail, source="python-agent", timeout_minutes=30):
    """True only if a person approved. Blocks for up to timeout_minutes."""
    try:
        created = _call(
            "/submit-request",
            {
                "title": title[:255],
                "code_snippet": detail,
                "source": source,
                "expires_in_minutes": timeout_minutes,
            },
            # The same action retried within a minute gets the same request back.
            idempotency_key=f"{source}:{detail}:{int(time.time() // 60)}",
        )
        # An auto-approve rule can approve the request as it is created.
        status = created.get("status")
        deadline = time.monotonic() + timeout_minutes * 60
        delay = 3.0
        while status == "pending" and time.monotonic() < deadline:
            if os.environ.get("VIBEZ_SANDBOX") == "1":
                return False
            time.sleep(delay)
            delay = min(delay * 1.5, 30.0)
            status = _call(f"/check-status?request_id={created['request_id']}").get("status")
        return status == "approved"
    except Exception:
        return False


async def ask_human(title, detail, source="python-agent", timeout_minutes=30):
    """The same, without blocking the event loop."""
    return await asyncio.to_thread(ask_human_sync, title, detail, source, timeout_minutes)

The agent

create_agent from langchain.agents replaces LangGraph's create_react_agent, which is deprecated in LangGraph 1.0. The tool is async, so the agent runs with ainvoke.

langchain_agent.py
"""A LangChain agent whose shell tool waits for your approval on Vibez.now.

    pip install langchain langchain-anthropic
    VIBEZ_API_KEY=... ANTHROPIC_API_KEY=... python examples/python/langchain_agent.py

Written for langchain 1.4 (checked against its docs in November 2026). `create_agent` replaces LangGraph's deprecated
`create_react_agent`.
"""

import asyncio

from langchain.agents import create_agent
from langchain.tools import tool

from vibez_approval import ask_human


@tool
async def run_command(command: str) -> str:
    """Run a shell command. A person approves every command before it runs."""
    if not await ask_human(f"Run: {command[:80]}", command, source="langchain-agent"):
        return f'Not approved: "{command}" was not run.'
    proc = await asyncio.create_subprocess_shell(
        command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT
    )
    out, _ = await proc.communicate()
    return out.decode()


agent = create_agent(model="anthropic:claude-sonnet-5-5", tools=[run_command])


async def main():
    result = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "How much disk space is free here?"}]}
    )
    print(result["messages"][-1].content)


if __name__ == "__main__":
    asyncio.run(main())

interrupt() or a waiting tool?

interrupt() / middlewareWaiting tool
Process while waitingCan exit; state is in the checkpointerStays running
Needs a checkpointer and thread_idYesNo
Who delivers the questionYour codeVibez.now: web, iOS, webhooks
Good forLong waits, servers, chat UIsScripts, workers, minutes-long waits

The two combine well. A server-side graph can interrupt(), submit the request, and resume the thread when Vibez.now posts request.approved or request.rejected to the webhook URL in your Settings. Nothing holds a process open in the meantime.

Is create_react_agent deprecated?

Yes. In LangGraph 1.0 it moved to langchain.agents as create_agent, and the prebuilt version carries a deprecation warning.

Does the helper need any packages?

No. vibez_approval.py uses only the Python standard library and works on Python 3.9 or later.

What does the agent see when a command is rejected?

The tool returns a sentence saying the command was not approved and was not run, so the model can explain or choose another approach.

Keep reading