Skip to content

feat(examples): add langchain-flipcoin-chatbot autonomous bettor example#1148

Open
MrTalecky wants to merge 4 commits intocoinbase:mainfrom
MrTalecky:feat/flipcoin-example-chatbot
Open

feat(examples): add langchain-flipcoin-chatbot autonomous bettor example#1148
MrTalecky wants to merge 4 commits intocoinbase:mainfrom
MrTalecky:feat/flipcoin-example-chatbot

Conversation

@MrTalecky
Copy link
Copy Markdown

Summary

Adds a new LangChain example under typescript/examples/langchain-flipcoin-chatbot that demonstrates autonomous prediction-market trading on FlipCoin using the flipcoinActionProvider introduced in #1147.

  • Chat mode — interactive REPL for ad-hoc queries (list markets, quote odds, place trades, check portfolio).
  • Autonomous mode — rotating prompt bank that scans markets, looks for mispriced odds, places small trades, and reviews the portfolio for profit-taking. Interval configurable via AGENT_INTERVAL_SECONDS.
  • WalletViemWalletProvider on Base mainnet with a local private key (signs EIP-712 TradeIntent typed data for the hybrid /intent/relay flow).
  • LLMgpt-4o-mini via @langchain/openai (swap freely).

Dependency

This PR depends on #1147 (the FlipCoin action provider). Please merge #1147 first; CI may fail here until the provider is on main.

Test plan

  • Merge feat: add FlipCoin action provider for prediction markets on Base #1147 first, then rebase this branch onto main.
  • cd typescript/examples/langchain-flipcoin-chatbot && cp .env.example .env, fill in OPENAI_API_KEY, PRIVATE_KEY, FLIPCOIN_API_KEY.
  • pnpm install && pnpm start — chat mode, ask "list the 5 hottest markets" and "what are the odds on <conditionId>?".
  • pnpm start autonomous — confirm the agent rotates through prompts and respects price-impact guard.
  • pnpm run lint — passes.

Notes

  • Pre-flight (covered in README): fund the FlipCoin vault via POST /api/agent/vault/deposit/intent and call ShareToken.setApprovalForAll(router, true) once per chain.
  • Agent API keys are created at https://www.flipcoin.fun/app/settings. Scopes required: trade, portfolio:read.

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

…n Base

FlipCoin (https://www.flipcoin.fun) is a LMSR-based prediction-market protocol
deployed on Base. This provider gives AgentKit agents 5 actions:

- get_prediction_markets: list tradable markets with prices and volume
- get_market_odds: fetch firm quote (priceYesBps, sharesOut, priceImpact)
- buy_prediction_shares: buy YES/NO shares via EIP-712 intent -> wallet
  signTypedData -> FlipCoin relay, which broadcasts the tx on-chain
- sell_prediction_shares: sell YES/NO shares back into the LMSR pool
- get_agent_portfolio: read agent positions and unrealized P&L

Trades use FlipCoin's two-phase intent/relay pattern: the provider requests
an EIP-712 TradeIntent from /api/agent/trade/intent, signs it with the
supplied EvmWalletProvider, and submits it to /api/agent/trade/relay where
FlipCoin's relayer covers gas and broadcasts the transaction.

Supports Base mainnet and Base Sepolia. Requires a FlipCoin agent API key
(obtained at https://www.flipcoin.fun/app/settings).

19 unit tests covering all actions, error paths, price-impact guard and
approval-required flow.
@MrTalecky MrTalecky requested a review from murrlincoln as a code owner April 23, 2026 21:03
@cb-heimdall
Copy link
Copy Markdown

cb-heimdall commented Apr 23, 2026

🟡 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 action provider New action provider example New example agent typescript labels Apr 23, 2026
V.Talecky and others added 3 commits April 24, 2026 00:14
…h OpenAPI spec

Review against canonical OpenAPI + Agent API docs surfaced three issues that would
break the provider at runtime:

1. Trade intent body used `amount`, but the API requires `usdcAmount` (buy) or
   `sharesAmount` (sell). See openapi TradeIntentRequest schema. Without this fix
   every buy/sell returns 400 `usdcAmount is required for buy` /
   `sharesAmount is required for sell`.

2. `approvalRequired` gate was `approvalRequired && !approvalRequired.approved`,
   but the intent route always returns `approved: true` inside the object (it's
   the target value to pass to setApprovalForAll, not the current state). The
   mere presence of the object means approval is missing. Gate now checks
   presence only.

3. `get_market_odds` for sells must pass `amount` in shares (the quote endpoint
   switches amountType based on action). Schema field renamed from `amountUsdc`
   to a generic `amount` with docs clarifying the per-action interpretation.

Also:
- DEFAULT_MAX_SLIPPAGE_BPS: 200 → 100 (matches FlipCoin's documented default).
- DEFAULT_MAX_FEE_BPS: 300 → 200 (matches FlipCoin's documented default).
- Remove fabricated `minOut` / `maxFeeBps` / per-quote echo fields from
  TradeIntentResponse.quote type — OpenAPI spec only declares sharesOut,
  avgPriceBps, priceImpactBps, fee.
- README: updated `router` to `operator` (provider surfaces it from
  approvalRequired.operator), fixed vault deposit example to use the
  single-endpoint `{action: "intent"|"relay"}` pattern.

Tests updated to assert the new request body shape and approvalRequired
semantics. All 39 provider tests pass; lint + format clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- LangChain agent wired to AgentKit's FlipCoin action provider.
- Chat mode (REPL) and autonomous mode (rotating prompt bank, configurable interval).
- ViemWalletProvider on Base mainnet; private key via .env.
- System prompt with prediction-market trading heuristics (reject blocked price impact, prefer liquid markets, size positions 0.5-2 USDC).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Correct the preflight instructions to the two-phase single-endpoint
  flow (POST /api/agent/vault/deposit with {action: "intent"|"relay"}),
  matching the canonical FlipCoin Agent API / OpenAPI spec.
- Reference approvalRequired.operator for the ShareToken approval
  address (surfaced by the action provider).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MrTalecky MrTalecky force-pushed the feat/flipcoin-example-chatbot branch from 557cef1 to 0715e05 Compare April 23, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation example New example agent typescript

Development

Successfully merging this pull request may close these issues.

2 participants