Skip to main content

langchain-graph-advocate

LangChain tool wrapper for Graph Advocate — drop-in onchain data routing for AI agents. Plain-English queries return a working GraphQL query, subgraph ID, or REST call you can execute against The Graph or Token API.

  • 15,500+ subgraphs across 20+ chains
  • Wallet balances, token holders, DEX swaps, NFTs, lending data, prediction markets, ENS domains, ERC-8004 agent discovery
  • $0.01 USDC per query via x402 on Base (auto-pay built in)

Install

# Includes x402 SDK by default — required to make paid calls
pip install 'langchain-graph-advocate[x402]'

# Or core only (returns HTTP 402 helper info on every call)
pip install langchain-graph-advocate

Quick start

import os
from langchain_graph_advocate import GraphAdvocateTool

# x402_private_key is required to pay $0.01 USDC per query.
# The signing wallet needs USDC on Base — bridge at bridge.base.org.
tool = GraphAdvocateTool(
    x402_private_key=os.environ["X402_PRIVATE_KEY"],
)

result = tool.invoke({"request": "Top 20 USDC holders on Ethereum"})
print(result)
# Returns JSON with recommendation, query_ready, curl_example, alternatives

What happens without an x402 key

The endpoint returns HTTP 402. The tool surfaces this as a structured JSON error containing the pay_to address, network, and onboarding info, so the agent can decide whether to acquire USDC and retry — or the user can fund the wallet ahead of time.

# No key — tool still returns a structured response, just not data
tool = GraphAdvocateTool()
result = tool.invoke({"request": "anything"})
# {"error": "payment_required", "price_usdc": 0.01, "network": "eip155:8453",
#  "pay_to": "0x0FF5A6...", "facilitator": "https://api.cdp.coinbase.com/...", ...}

Use it in an agent

from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from langchain_graph_advocate import GraphAdvocateTool

llm = ChatAnthropic(model="claude-opus-4-7")
tools = [GraphAdvocateTool()]

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an onchain analyst. Use the graph_advocate tool to "
               "answer any onchain data questions."),
    ("user", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

executor.invoke({"input": "Who are the top 10 USDC holders on Ethereum?"})

What you get back

{
  "recommendation": "token-api",
  "reason": "getV1EvmHolders returns ranked holder lists by token contract.",
  "confidence": "high",
  "query_ready": {
    "tool": "getV1EvmHolders",
    "args": {
      "network": "mainnet",
      "contract": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "limit": 20
    }
  },
  "curl_example": "curl 'https://token-api.thegraph.com/...'",
  "get_started": "Free API key: https://thegraph.com/studio/",
  "alternatives": []
}

Your agent then runs the query_ready against the Graph gateway (or whichever service was recommended) using a free API key from thegraph.com/studio.

Pricing

Tier Price How
Free 10 queries/day per sender Just call the tool — no setup
Paid $0.01 USDC Pass x402_private_key to auto-pay

Why this exists

Without Graph Advocate, an agent that wants Aave liquidations on Base has to: (1) discover candidate subgraphs, (2) compare query volumes for reliability, (3) read schemas, (4) write GraphQL, (5) test against the indexer. That's 5–10 minutes of model + tool time per data question.

Graph Advocate returns the working query in one HTTP round trip for $0.01.

Links

License

MIT

Metadata

Release files for langchain-graph-advocate 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-graph-advocate 0.1.2
File Size Uploaded
langchain_graph_advocate-0.1.2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-graph-advocate 0.1.2
File Interpreter ABI Platform
langchain_graph_advocate-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.0 kB

Release files / langchain_graph_advocate-0.1.2.tar.gz

Download URL langchain_graph_advocate-0.1.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
35ed99e0fbec683f1a7a48598e0646599d6affba33927b2204b3644b64ea31c1
BLAKE2b-256 checksum
How to use checksums
736058698237ab9165dceb10f02df1103f8574107e171188659c5ed91e3f8a01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release files / langchain_graph_advocate-0.1.2-py3-none-any.whl

Download URL langchain_graph_advocate-0.1.2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6530091ed5c3bfb24e9718d60a2b458875e82acf554c56a56cecab11f7c7e01
BLAKE2b-256 checksum
How to use checksums
9762a308415500637c476bac96d110e96b7d5a4c8dc25a574f417aa3c5862598
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 4, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page