Skip to content

examples(python): add langchain-krewe-inference-chatbot#1223

Open
harrydev44 wants to merge 1 commit into
coinbase:mainfrom
harrydev44:krewe-python-example
Open

examples(python): add langchain-krewe-inference-chatbot#1223
harrydev44 wants to merge 1 commit into
coinbase:mainfrom
harrydev44:krewe-python-example

Conversation

@harrydev44
Copy link
Copy Markdown

Summary

Adds the Python sibling to the TypeScript example proposed in #1222: a LangChain chatbot that uses AgentKit's built-in x402_action_provider to call krewe — a decentralized AI inference network on Base mainnet — for four pay-per-call job kinds.

Same orchestrator, same pricing table, same handshake — just native Python idioms and the canonical langchain-cdp-chatbot example structure.

Why both PRs

The agent ecosystem splits roughly 50/50 between TypeScript (Vercel AI SDK, Mastra, agentkit-langchain TS) and Python (LangChain Python, autogen, CrewAI, pydantic-ai). Shipping only one half leaves the other audience locked out of the x402 action provider pattern. These two PRs together demonstrate the canonical "x402-paywalled inference as a first-class agent tool" recipe against a real production endpoint, on both sides of the monorepo.

What's in this PR

  • python/examples/langchain-krewe-inference-chatbot/chatbot.py — entrypoint, mirrors langchain-cdp-chatbot/chatbot.py (chat + autonomous modes, identical CDP wallet wiring, persistent wallet file). Only the action-provider list and the system prompt differ.
  • pyproject.toml — uv-managed, lifted from langchain-cdp-chatbot with only the package name + description changed. Same dep pins, same ruff config, same [tool.uv.sources] workspace deps.
  • Makefile — identical install / run / lint / format targets.
  • .env.local — adds NETWORK_ID, KREWE_PREDICT_URL, KREWE_MAX_PAYMENT_USDC (all with sensible defaults).
  • README.md — prompts to try, prerequisites, env vars, run instructions, plus a section on the standalone krewe-x402 PyPI package for callers who don't need the full AgentKit stack.
  • Root README.md — adds the new example to the Python directory tree (alphabetically between langchain-eth-account-chatbot and langchain-nillion-secretvault-chatbot).

Pricing surfaced in the system prompt

kind Cost
text.structure $0.005
text.embed $0.01
web.scrape $0.02
text.complete $0.05

Quoted server-side per call; AgentKit's max_payment_usdc ceiling (default $0.10 in this example) protects against unexpected prices.

Production endpoint verified

The orchestrator at https://krewe-orchestrator-production.up.railway.app/v2/predict is live and returns the documented WWW-Authenticate: x402 scheme=\"x402-eip3009-usdc\" header on the 402 challenge — verified by hand with the existing x402_action_provider.

Test plan

  • chatbot.py mirrors the proven langchain-cdp-chatbot template structure — wallet config, agent setup, chat/auto loops are identical patterns.
  • x402 challenge against the production endpoint verified by hand: curl -X POST .../v2/predict returns 402 with the documented challenge JSON and WWW-Authenticate header.
  • Tooling files (pyproject.toml, Makefile, ruff config) lifted verbatim from langchain-cdp-chatbot to match repo conventions.
  • Root README.md Python examples tree updated alphabetically.

Happy to tweak the system prompt wording, the bundled action-provider list, or the env-var naming.


Companion PR: #1222 (TypeScript sibling).

Links:

Python sibling of typescript/examples/langchain-krewe-inference-chatbot
(opened in coinbase#1222). Same orchestrator, same pricing table, same 4 job
kinds (text.structure, text.embed, web.scrape, text.complete) accessed
via AgentKit's built-in x402 action provider.

Each call settles per-request in USDC on Base via EIP-3009 — no API
keys, no provisioning. Funds the krewe miners that answer the job via
an hourly USDC -> $KREW buyback. Same idiomatic structure as
langchain-cdp-chatbot (chat + auto modes, persistent CDP wallet file,
ruff/uv tooling).

Closes the symmetry gap: the agent ecosystem's Python half (LangChain
Python, autogen, CrewAI) can now reach krewe inference through the same
canonical AgentKit pattern as the TypeScript side.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@harrydev44 harrydev44 requested a review from murrlincoln as a code owner May 18, 2026 21:28
@cb-heimdall
Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@github-actions github-actions Bot added documentation Improvements or additions to documentation example New example agent python labels May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation example New example agent python

Development

Successfully merging this pull request may close these issues.

2 participants