LangChainpylive · you pay per call

A paid tool inside a subagent

A Deep Agents market-research agent where the paid capability lives inside a subagent. The x402 token survives the task() delegation hop, so @requires_payment needs no changes.

langchain-deep-agent-py/
1 What you'll learn

Payment context survives one delegation hop — so paid tools can live where the work does.

  • Put a paid tool behind a task() delegation and keep the payment lifecycle intact
  • Cap paid calls per run — a deep agent decides for itself how many subagent hops a request warrants
  • Guard against the supervisor answering a paid question from its own knowledge (giving it away free)
  • Compare harnesses side by side with the sibling create_react_agent research agent
2 How it works

The buyer attaches an x402 token to the run. The supervisor never touches it — it delegates via the built-in task tool, and LangGraph copies configurable down into the subagent's tool calls. So @requires_payment works unchanged one hop away from where the token was supplied.

A deep agent can bill several times per user turn, so the tutorial caps it explicitly with NVM_MAX_PAID_CALLS_PER_RUN and sends a fresh nvm_run_id to scope the cap per-run rather than per-conversation.

main agentsupervisor
task()delegate
research-subowns the tool
market_researchPAID
3 Under the hood
create_deep_agentLangChain v1 stackpayments-py[langsmith]OpenAI gpt-4o-mini
# the buyer scopes the per-run cap with a fresh run id
"config": {"configurable": {
    "payment_token": token,
    "nvm_run_id": str(uuid.uuid4()),
}}
src/agent.pycreate_deep_agent supervisor + research-sub owning the paid tool
src/buyer.pysends token + nvm_run_id; prints the raw ToolMessage as source of truth
4 See it run
A paid tool inside a subagent

Sandbox agent — real payment round-trips (402 → authorize → settle) with a per-session credit balance, no external service and no real money. Deep Agents needs its own virtualenv (LangChain v1); the paid tool sits one task() hop away in a subagent, and the token survives the delegation. See the README to run it against a hosted deployment.