examples(python): add langchain-krewe-inference-chatbot#1223
Open
harrydev44 wants to merge 1 commit into
Open
Conversation
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>
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the Python sibling to the TypeScript example proposed in #1222: a LangChain chatbot that uses AgentKit's built-in
x402_action_providerto 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-chatbotexample 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
x402action 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, mirrorslangchain-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 fromlangchain-cdp-chatbotwith 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— addsNETWORK_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 standalonekrewe-x402PyPI package for callers who don't need the full AgentKit stack.README.md— adds the new example to the Python directory tree (alphabetically betweenlangchain-eth-account-chatbotandlangchain-nillion-secretvault-chatbot).Pricing surfaced in the system prompt
kindtext.structuretext.embedweb.scrapetext.completeQuoted server-side per call; AgentKit's
max_payment_usdcceiling (default $0.10 in this example) protects against unexpected prices.Production endpoint verified
The orchestrator at
https://krewe-orchestrator-production.up.railway.app/v2/predictis live and returns the documentedWWW-Authenticate: x402 scheme=\"x402-eip3009-usdc\"header on the 402 challenge — verified by hand with the existingx402_action_provider.Test plan
chatbot.pymirrors the provenlangchain-cdp-chatbottemplate structure — wallet config, agent setup, chat/auto loops are identical patterns.curl -X POST .../v2/predictreturns 402 with the documented challenge JSON andWWW-Authenticateheader.pyproject.toml,Makefile, ruff config) lifted verbatim fromlangchain-cdp-chatbotto match repo conventions.README.mdPython 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: