agents
agents copied to clipboard
Add BlockRun integration for x402 USDC micropayments
Summary
This PR adds BlockRun as an alternative LLM provider, enabling Polymarket agents to pay for AI inference with USDC micropayments via the x402 protocol on Base.
What is BlockRun?
BlockRun is a crypto-native AI gateway that provides:
- 31+ AI models - GPT-4, Claude, Gemini, and more through a single endpoint
- No API keys - Agents pay directly with their wallet via x402
- Pay-per-use - USDC micropayments on Base network
- 0% markup - Same pricing as official APIs during beta
Changes
agents/connectors/blockrun.py- New connector with LangChain-compatible LLM provideragents/application/executor.py- Updated to support BlockRun as alternative to OpenAI.env.example- Added BlockRun configuration optionsREADME.md- Added documentation for BlockRun setup and usage
Usage
from agents.application.executor import Executor
# Enable BlockRun via environment variable
# BLOCKRUN_ENABLED=true
# Or programmatically
executor = Executor(default_model='gpt-4o', use_blockrun=True)
# Use Claude instead of GPT
executor = Executor(default_model='claude-3-5-sonnet', use_blockrun=True)
Why This Matters for Polymarket Agents
- True Agent Autonomy - Agents pay for their own AI with their trading wallet
- No API Key Management - Eliminates credential handling for LLM access
- Model Flexibility - Switch between GPT-4, Claude, Gemini without changing providers
- Same Wallet - Use the same wallet for trading AND AI payments
Testing
The integration uses the existing LangChain ChatOpenAI class with BlockRun's OpenAI-compatible API, ensuring compatibility with all existing code paths.
Learn more: blockrun.ai | x402 Protocol
[!NOTE] Introduces BlockRun as an alternative LLM backend using x402 USDC micropayments and integrates it into the agent runtime.
- New
agents/connectors/blockrun.py: BlockRun client and LangChain-compatibleBlockRunLLM, model mappings, and token limitsagents/application/executor.py: Addsuse_blockrunflag (orBLOCKRUN_ENABLED) to switch between OpenAI and BlockRun; sets token limits via BlockRun helpers.env.example: AddsBLOCKRUN_ENABLED,BLOCKRUN_WALLET_KEY, andBLOCKRUN_API_URLconfigurationREADME.md: Setup/usage docs for BlockRun, model list, and examplesrequirements.txt: Addsblockrun-llmdependencyWritten by Cursor Bugbot for commit 183441d9be491601fd955808d0009fd0713468fb. This will update automatically on new commits. Configure here.