Skip to content

examples(typescript): add langchain-krewe-inference-chatbot#1222

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

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

Conversation

@harrydev44
Copy link
Copy Markdown

Summary

Adds a new LangChain chatbot example to typescript/examples/ that uses AgentKit's built-in x402ActionProvider to call krewe — a decentralized AI inference network on Base mainnet — for four job kinds (text.structure, text.embed, web.scrape, text.complete).

This is the canonical "x402-paywalled inference as a first-class agent tool" pattern: no API key, no provisioning step, the agent's CDP wallet IS the API key. Each call settles per-request in USDC via EIP-3009 transferWithAuthorization (handled transparently by x402ActionProvider + @x402/fetch), and the agent gets back 2-of-3 byte-equal miner consensus output.

Pricing surfaced in the system prompt so the agent makes cost-aware tool choices:

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

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

What's in this PR

  • typescript/examples/langchain-krewe-inference-chatbot/chatbot.ts — entrypoint, mirrors the structure of langchain-cdp-chatbot/chatbot.ts (chat mode + autonomous mode + identical CDP wallet wiring) so it's easy to diff and reason about.
  • package.json, tsconfig.json, .eslintrc.json, .prettierrc, .prettierignore — copied verbatim from the canonical langchain-cdp-chatbot example, with only the package name + description changed.
  • README.md — prompts to try, prerequisites, env vars, run instructions, and a walkthrough of what's happening during the x402 handshake.
  • .env-local — adds NETWORK_ID, KREWE_PREDICT_URL, KREWE_MAX_PAYMENT_USDC (all with sensible defaults).
  • Root README.md — adds the new example to the directory tree.

Why this is worth merging

  1. Demonstrates x402ActionProvider against a real, production x402 service. Today the canonical example registers https://www.x402.org/protected (a demo endpoint); this PR shows what a real production integration looks like, including a maximum-payment cap, a deterministic price table, and a system prompt that teaches the agent when to reach for the tool.
  2. Surfaces a new agent capability for free. Anyone copy-pasting from this example gets pay-per-call structured extraction, embeddings, scraping, and small-LM completion through their agent's existing wallet — no new SDK to learn.
  3. Bidirectional plumbing for the ecosystem. Each call funds the krewe miners directly via an hourly USDC → $KREW buyback. AgentKit users get a useful tool; krewe miners get paid traffic. Both expand x402 adoption without bespoke integration code.

Test plan

  • chatbot.ts 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 (tsconfig, eslint, prettier) copied verbatim from langchain-cdp-chatbot to match repo conventions.
  • Root README.md examples tree updated alphabetically.

Happy to address any feedback on naming, system prompt wording, or which AgentKit providers to bundle alongside x402 in the default config.


Links:

A LangChain chatbot that uses AgentKit's built-in x402ActionProvider to
call krewe (https://www.krewe.world) — a decentralized AI inference
network on Base mainnet. The agent's CDP wallet pays in USDC per call
(0.005 USD for text.structure up to 0.05 USD for text.complete) and
gets 2-of-3 byte-equal miner consensus output for four job kinds:
text.structure, text.embed, web.scrape, text.complete.

The example demonstrates the canonical "x402-paywalled inference as a
first-class agent tool" pattern: no API key, no provisioning step,
the wallet IS the API key. Pricing, max-payment cap, and orchestrator
URL are all env-configurable.

The chatbot exposes both chat mode and an autonomous mode that picks
creative krewe jobs on a 30s loop, useful for cost/perf testing.

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 20:31
@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

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 typescript

Development

Successfully merging this pull request may close these issues.

2 participants