{"id":50319956,"url":"https://github.com/spfunctions/langchain-prediction-markets","last_synced_at":"2026-06-02T00:03:36.562Z","repository":{"id":356047592,"uuid":"1202626237","full_name":"spfunctions/langchain-prediction-markets","owner":"spfunctions","description":"LangChain adapter for SimpleFunctions prediction-market context: world state, uncertainty, edges, and market reads.","archived":false,"fork":false,"pushed_at":"2026-05-06T10:39:24.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-06T12:34:37.690Z","etag":null,"topics":["agent-context","ai-agents","framework-adapter","kalshi","langchain","polymarket","prediction-markets"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spfunctions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-06T08:18:04.000Z","updated_at":"2026-05-06T10:39:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/spfunctions/langchain-prediction-markets","commit_stats":null,"previous_names":["spfunctions/langchain-prediction-markets"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/spfunctions/langchain-prediction-markets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spfunctions%2Flangchain-prediction-markets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spfunctions%2Flangchain-prediction-markets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spfunctions%2Flangchain-prediction-markets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spfunctions%2Flangchain-prediction-markets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spfunctions","download_url":"https://codeload.github.com/spfunctions/langchain-prediction-markets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spfunctions%2Flangchain-prediction-markets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33798943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-context","ai-agents","framework-adapter","kalshi","langchain","polymarket","prediction-markets"],"created_at":"2026-05-29T03:00:35.907Z","updated_at":"2026-06-02T00:03:36.557Z","avatar_url":"https://github.com/spfunctions.png","language":"TypeScript","funding_links":[],"categories":["Prediction Market Tools"],"sub_categories":["By Sparkco"],"readme":"# langchain-prediction-markets\n\n[![npm](https://img.shields.io/npm/v/langchain-prediction-markets)](https://www.npmjs.com/package/langchain-prediction-markets)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\nLangChain tools for **real-time prediction market data**. Drop-in tools that give any\nLangChain agent (`createReactAgent`, `createOpenAIToolsAgent`, custom chains) world\nawareness from the active Kalshi and Polymarket market universe — no auth required.\n\n```ts\nimport { ChatOpenAI } from '@langchain/openai'\nimport { createReactAgent } from '@langchain/langgraph/prebuilt'\nimport { predictionMarketTools } from 'langchain-prediction-markets'\n\nconst agent = createReactAgent({\n  llm: new ChatOpenAI({ model: 'gpt-4o' }),\n  tools: predictionMarketTools(),\n})\n\nconst result = await agent.invoke({\n  messages: [{ role: 'user', content: \"What's the highest-conviction trade idea right now?\" }],\n})\n```\n\n---\n\n## Install\n\n```bash\nnpm install langchain-prediction-markets @langchain/core\n```\n\nPeer dep: `@langchain/core \u003e= 0.2.0`. Works with all LangChain JS chat models\n(`@langchain/openai`, `@langchain/anthropic`, `@langchain/google-genai`, etc.).\n\n## Tools\n\nAll six tools hit the public SimpleFunctions API. **No API key, no rate limit, no\nauth.** Every endpoint below is verified live.\n\n| Tool | Endpoint | When to use |\n|------|----------|-------------|\n| `get_context` | `/api/public/context` | **Start here.** Single bundle: edges, movers, highlights, traditional-market context. |\n| `get_world_state` | `/api/agent/world` | ~800-token compressed snapshot of all markets, ideal for system-prompt injection. |\n| `get_world_changes` | `/api/agent/world/delta` | ~30-50 token incremental delta — cheap polling loops. |\n| `get_market_edges` | `/api/edges` | Raw mispricings (thesis price vs market price) with reasoning. |\n| `get_uncertainty_index` | `/api/public/index` | Single numeric pulse: uncertainty, geopolitical risk, momentum, activity. |\n| `get_ideas` | `/api/public/ideas` | LLM-generated trade ideas with conviction, catalyst, time horizon. |\n\n## Quick start: ReAct agent\n\n```ts\nimport { ChatAnthropic } from '@langchain/anthropic'\nimport { createReactAgent } from '@langchain/langgraph/prebuilt'\nimport { predictionMarketTools } from 'langchain-prediction-markets'\n\nconst agent = createReactAgent({\n  llm: new ChatAnthropic({ model: 'claude-sonnet-4-5' }),\n  tools: predictionMarketTools(),\n  stateModifier:\n    'You are a market intelligence assistant. Use the tools to ground every claim in real-time prediction-market data. Cite tickers explicitly.',\n})\n\nconst result = await agent.invoke({\n  messages: [{ role: 'user', content: 'What changed in markets in the last 6 hours?' }],\n})\nconsole.log(result.messages.at(-1)?.content)\n```\n\n## Use individual tools in a custom chain\n\n```ts\nimport { getContext, getMarketEdges } from 'langchain-prediction-markets'\nimport { ChatOpenAI } from '@langchain/openai'\n\nconst llm = new ChatOpenAI({ model: 'gpt-4o' }).bindTools([getContext, getMarketEdges])\n\nconst out = await llm.invoke('Show me the open edges right now.')\nfor (const call of out.tool_calls ?? []) {\n  if (call.name === 'get_market_edges') {\n    const edges = await getMarketEdges.invoke(call.args)\n    console.log(edges)\n  }\n}\n```\n\n## Direct invocation (no LangChain agent)\n\nEvery tool is a standard LangChain `tool` — you can call `.invoke()` directly:\n\n```ts\nimport { getUncertaintyIndex, getIdeas } from 'langchain-prediction-markets'\n\nconst index = JSON.parse(await getUncertaintyIndex.invoke({}))\nconsole.log(`Uncertainty: ${index.uncertainty}/100`)\n\nconst { ideas } = JSON.parse(await getIdeas.invoke({}))\nconsole.log(`Top idea: ${ideas[0].headline}`)\n```\n\n## Response shapes\n\nTools return **JSON-stringified** payloads (LangChain expects string outputs).\n`get_world_state` and `get_world_changes` return raw markdown strings.\n\n### `get_context`\n```ts\n{\n  edges: Edge[]\n  movers: Mover[]\n  highlights: Highlight[]\n  traditionalMarkets: { [topic: string]: TraditionalMarket[] }\n}\n```\n\n### `get_uncertainty_index`\n```ts\n{\n  uncertainty: number    // 0-100\n  geopolitical: number   // 0-100\n  momentum: number       // -1 to +1\n  activity: number       // 0-100\n  components: { medianSpread: number; avgSpread: number; ... }\n  timestamp: string\n}\n```\n\n### `get_market_edges`\n```ts\n{\n  edges: {\n    ticker: string\n    venue: 'kalshi' | 'polymarket'\n    title: string\n    marketPrice: number\n    thesisPrice: number\n    executableEdge: number\n    confidence: number\n    liquidityScore: 'high' | 'medium' | 'low'\n    direction: 'yes' | 'no'\n    reasoning: string\n  }[]\n}\n```\n\n### `get_ideas`\n```ts\n{\n  generatedAt: string\n  cached: boolean\n  ideas: {\n    headline: string\n    pitch: string\n    conviction: 'high' | 'medium' | 'low'\n    direction: 'buy_yes' | 'buy_no'\n    markets: { url: string; ticker: string; currentPrice: number; venue: string }[]\n    catalyst: string\n    timeHorizon: string\n    risk: string\n  }[]\n}\n```\n\n## Errors\n\nAll tools throw `Error(\"SimpleFunctions API error \u003cstatus\u003e for \u003cpath\u003e\")` on non-2xx\nresponses. LangChain agents will see the error string in the tool message and can\nretry or recover.\n\n## Sister packages\n\nIf you're not on LangChain, use the wrapper for your stack:\n\n| Stack | Package |\n|-------|---------|\n| Vercel AI SDK | [`vercel-ai-prediction-markets`](https://github.com/spfunctions/vercel-ai-prediction-markets) |\n| OpenAI Agents SDK / function calling | [`openai-agents-prediction-markets`](https://github.com/spfunctions/openai-agents-prediction-markets) |\n| CrewAI (Python) | [`crewai-prediction-markets`](https://github.com/spfunctions/crewai-prediction-markets) |\n| MCP / Claude / Cursor | [`simplefunctions-cli`](https://github.com/spfunctions/simplefunctions-cli) |\n| Bare Python SDK | [`simplefunctions-python`](https://github.com/spfunctions/simplefunctions-python) |\n\n## Testing\n\n```bash\nnpm test\n```\n\n12 tests, all `fetch`-mocked — no network required.\n\n## License\n\nMIT — built by [SimpleFunctions](https://simplefunctions.dev).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspfunctions%2Flangchain-prediction-markets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspfunctions%2Flangchain-prediction-markets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspfunctions%2Flangchain-prediction-markets/lists"}