Framework guide

Monitor and control LangGraph agents in production

LangGraph and LangChain make it quick to build a tool-calling agent. Once it serves users, you also need to see what each agent costs, know when it breaks, and be able to stop or change it without a deploy. This guide adds that with Agent Control Panel around graph.invoke. The code was run against the real LangGraph and LangChain packages before we published it.

By the Agent Control Panel teamPublished 4 min read

On this page
  1. What you get
  2. Set up
  3. Wrap each graph run
  4. Answer users while the agent is paused
  5. How we tested this code
  6. Frequently asked questions

What you get

  • Every run, with cost. Status, duration, tokens of every model call in the run, the model, the question and the answer, per agent.
  • Pause and stop. From the dashboard, or automatically when an alert rule fires on daily spend, error rate, a spend anomaly or a lost heartbeat.
  • Model swaps without a redeploy. Pick another model in the dashboard; the next run uses it.
  • Approved prompt changes. An owner or admin approves a new prompt; the next run uses it.
  • Liveness. A heartbeat every 30 seconds, so a crashed worker shows up as lost, not as quiet.

Model calls still go from your app to the provider with your own keys. If Agent Control Panel is unreachable, your agent keeps working: see fail-open vs in-path.

Set up

  1. Create an app in Agent Control Panel and copy its API key, agent ID and webhook secret. New apps start in monitor scope; allow the control scope when you are ready to pause and swap models.
  2. Install the SDK next to your framework: pip install agent-control-panel langchain langchain-openai.
  3. Create the client once at startup and call start(), as in the quickstart. The examples import it from your own acp.py.

Wrap each graph run

Three things change in your code: the system prompt comes from Agent Control Panel (with your own default), the model comes from it (with your own default), and the run goes through the wrapper. A graph returns its state, not a model response; agent-control-panel 0.1.4 or later reads that state as it is: the answer from the last AI message and the tokens of every model call from the messages’ usage_metadata.

from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI

from acp import acp  # create_client(...) + acp.start(), see the quickstart

DEFAULT_PROMPT = "You are a helpful support assistant."  # used when ACP has no prompt or cannot be reached


@tool
def order_status(order_id: str) -> str:
    """Look up an order."""
    return get_order_status(order_id)  # your code


def answer(question: str) -> str:
    prompt = acp.fetch_prompt() or DEFAULT_PROMPT        # the approved prompt
    model = acp.get_effective_model("gpt-4.1-mini")       # a model swap from ACP, or your default
    graph = create_agent(ChatOpenAI(model=model), tools=[order_status], system_prompt=prompt)

    # The SDK reads the graph state as it is: the answer from the last AI message, the tokens of every model call
    # from the messages' usage_metadata (agent-control-panel 0.1.4 or later).
    state = acp.wrap_agent_run(lambda: graph.invoke({"messages": [("user", question)]}),
                               user_input=question, model_used=model)
    return state["messages"][-1].content

create_agent is LangChain 1.x’s agent, built on LangGraph; it replaces langgraph.prebuilt.create_react_agent, which LangGraph 1.x marks as deprecated. The same wrapper works for a graph you build yourself with StateGraph, as long as its state keeps the conversation in messages.

Building the graph on each call is cheap and means a model swap or a new prompt applies on the very next run. A pushed prompt applies at once when your app receives Agent Control Panel’s signed webhook; without a public webhook URL it applies within 60 seconds, and model swaps and pauses within one 30-second heartbeat.

Answer users while the agent is paused

While the agent is paused or stopped, the wrapper raises AgentPausedError before your code runs, so no model is called and no tokens are spent. Catch it where you answer the user:

from agent_control_panel import AgentPausedError

try:
    reply = answer(question)
except AgentPausedError:
    reply = "The assistant is paused right now. Please try again later."

After a restart, the first run waits up to three seconds for Agent Control Panel’s answer, so a pause holds across deploys. If no answer comes in time the run goes ahead.

How we tested this code

On November 11, 2026 we ran this example on Python 3.10 with langgraph 1.2.20, langchain 1.4.10, langchain-openai 1.7.4 and agent-control-panel 0.1.4 (the example as shown, with no adapter), against a stand-in OpenAI-compatible server and a stand-in Agent Control Panel server, so the test needed no API keys. The agent called the tool and then answered, and we checked that:

  • the run was reported once, as a success, with the tokens of both model calls, the model, the question and the answer;
  • a model swap and a pushed prompt were used on the next run;
  • after a pause, the next call raised AgentPausedError and the model was not called.

What it does not do: Agent Control Panel records each run as one record, not a step-by-step trace of the graph’s nodes. LangSmith or your own tracing keeps working alongside it. Async graphs (ainvoke) and streaming were not part of this test; for streaming, report the run with report_run when the stream ends.

Frequently asked questions

Does Agent Control Panel work with LangGraph?

Yes. Wrap graph.invoke with wrap_agent_run. It reports the last message and the summed usage_metadata of the run’s AI messages, which the SDK reads from the graph state as it is (agent-control-panel 0.1.4 or later).

Do I use create_agent or create_react_agent?

In LangGraph 1.x, create_react_agent is deprecated in favour of LangChain’s create_agent, which runs on LangGraph. The guide uses create_agent; the wrapper is the same for both.

Does it replace LangSmith?

No. LangSmith traces each step of a run for debugging. Agent Control Panel records each run with its cost and lets you pause, stop or change the agent in production. They work side by side.

How are tokens counted for runs with tool calls?

Each AI message carries the tokens of the model call that produced it. The SDK adds them up, so a run that calls a tool and then answers is reported with the tokens of both calls.