Start here: need to register a service and create a plan first? Follow the
5-minute setup.
Runnable tutorial
langchain-deep-agent-py — a freemium market-research agent on the Deep
Agents harness, where the paid tool lives inside a subagent. Clone, fill in
.env, run poetry run buyer to watch the free path and the paid path
back to back.create_deep_agent() returns a compiled LangGraph graph that already has planning, a filesystem, and subagent delegation built in. You reach for it when one agent needs to plan a job and hand pieces of it to specialists.
The Nevermined integration does not change. @requires_payment works on a Deep Agents tool exactly as it does on a plain LangChain one — this page is about the one property that makes that true, and the two harness behaviours you should design around.
The delegation hop
A buyer supplies an x402 access token once, on the run:task tool, and LangGraph copies configurable down into the subagent’s own tool calls — so the decorator finds the token one hop below where it was supplied:
The buyer does not need to know the agent’s internal topology. The contract is
the same one the LangChain guide
describes — put the token on the run and let the graph route it.
Quick start
Give the paid tool only to the subagent, so every paid call has to cross a delegation boundary:create_deep_agent() returns a compiled graph, deployment is unchanged — point langgraph.json at it and langgraph dev or LangSmith Deployment will serve it:
Two harness behaviours to design around
These are properties of the harness, not bugs. Both are worth handling before you put a deep agent in front of paying users. Cap it explicitly rather than trusting the model to be frugal — but note where a run’s identity has to come from. LangGraph does not put a run id inconfig["configurable"]. A tool sees only thread_id, checkpoint bookkeeping, and whatever the caller passed (verified against langgraph 1.2 / deepagents 0.7). Since thread_id is stable for a whole conversation, keying a “per-run” cap on it silently makes it per-conversation: after N paid calls the tool refuses forever, however many new questions the user asks.
So the caller declares the run — it is the only party that knows where one ends:
- Refund the reservation when a call raises
PaymentRequiredError— otherwise a user who authorizes mid-run gets fewer paid calls than they paid for. - Bound the counter map. The agent is a long-running server, so a plain dict keyed on run or thread grows for the life of the process. An LRU with a fixed ceiling is enough; evicting a key only refills that budget, so the worst case is a long-idle caller getting a fresh allowance rather than an over-charge.
Counting from graph state via
InjectedState looks like a tidier
alternative, and it does work inside a subagent tool — but it exposes the
subagent’s own isolated conversation, which resets on every task()
hop. It therefore cannot see sibling delegations within a single turn,
which is exactly the case the cap exists for.Version requirements
deepagents requires the LangChain v1 stack (langchain>=1.3.18, langchain-core>=1.6.1). If your existing project pins an older langchain-core, give the deep agent its own virtualenv rather than upgrading around it.
Observability
SetLANGSMITH_TRACING=true and LANGSMITH_API_KEY to emit nvm:verify and nvm:settlement spans. On a deep agent these nest under the task span, so you can see which subagent hop incurred each charge — which is exactly what you need when reasoning about the multi-billing behaviour above.
Which harness should I use?
Start from the LangChain guide if you want the smallest thing that works. Come here when the agent needs to plan, delegate, or manage its own context — and note that the payment integration itself does not change.
Related
- LangChain integration — the decorator and HTTP-middleware approaches in full.
- LangSmith Deployment — hosting a gated graph.
langchain-deep-agent-py— the runnable tutorial for this page.langchain-research-agent-py— the same freemium pattern oncreate_react_agent.