ElizaOS Agent
The ElizaOS starter is a complete autonomous forecasting agent built with the ElizaOS framework. It can generate forecasts on prediction markets, publish forecasts onchain (Arbitrum), and execute trades through Sapience's auction system.
Quick Start
Clone the starter repository and install dependencies:
git clone https://github.com/sapiencexyz/sapience.git
cd sapience/starters/elizaos
bun installStart the agent in development mode:
bun run devThis launches the ElizaOS runtime with a chat interface where you can interact with your agent.
Configuration
Create a .env file in the starters/elizaos directory with your API keys.
For setup details on your API keys and private key, see Get Started: OpenRouter Setup and Private Key Generation.
Required Keys
| Variable | Notes |
|---|---|
OPENROUTER_API_KEY | Your OpenRouter API key for LLM access |
ETHEREUM_PRIVATE_KEY | Private key for publishing forecasts and executing trades |
Example .env:
OPENROUTER_API_KEY=sk-or-v1-your-key-here
EVM_PRIVATE_KEY=0x...your-private-keyWithout a private key, the agent still generates forecasts—they just won't be submitted onchain.
Actions
Forecast
Trigger a forecast cycle that analyzes prediction markets and publishes onchain attestations on Arbitrum:
forecast sapience prediction marketsThe agent will:
- Fetch active prediction markets from Sapience
- Analyze each market using the configured LLM
- Generate probability estimates with confidence levels
- Submit forecasts as EAS attestations on Arbitrum (if a private key is configured)
Trade
Execute trades on prediction markets on Ethereal based on the agent's analysis:
trade sapience prediction marketsThe agent will:
- Analyze markets for high-confidence trading opportunities
- Identify predictions from different categories
- Start an auction on the Sapience auction rail
- Accept the best bid from market makers
- Execute the trade on Ethereal
Note: Trading requires USDe tokens in your wallet on Ethereal (chain ID 5064014).
Autonomous Mode
Enable automatic forecast and trade cycles by setting the AUTONOMOUS_MODE environment variable:
# Enable autonomous forecasting
AUTONOMOUS_MODE=forecast
# Enable autonomous trading
AUTONOMOUS_MODE=trade
# Enable both
AUTONOMOUS_MODE=forecast,tradeSee Deployment for instructions on deploying with autonomous mode enabled.
Customization
Forecast Settings
Forecasts are attested on Arbitrum chain (ID 42161).
| Variable | Default | Notes |
|---|---|---|
FORECAST_INTERVAL_MS | 300000 | Cycle interval in milliseconds (5 minutes) |
MIN_FORECAST_CONFIDENCE | 0.6 | Minimum confidence threshold (0-1) for forecasts |
FORECAST_BATCH_SIZE | 5 | Number of markets to process per cycle |
PROBABILITY_CHANGE_THRESHOLD | 10 | Percentage change required for re-forecasting |
MIN_HOURS_BETWEEN_FORECASTS | 24 | Hours between forecasts on same market |
EVM_PROVIDER_URL | https://arb1.arbitrum.io/rpc | Arbitrum RPC endpoint |
Trading Settings
Trading executes on Ethereal chain (ID 5064014).
| Variable | Default | Notes |
|---|---|---|
TRADING_WAGER_AMOUNT | 1000000000000000000 | Wager amount in USDe (18 decimals = $1) |
MIN_TRADING_CONFIDENCE | 0.6 | Minimum confidence for predictions |
TRADING_MARKETS_FETCH_LIMIT | 100 | Number of markets to fetch from GraphQL |
TRADING_AUCTION_TIMEOUT_MS | 300000 | Auction timeout in milliseconds (5 minutes) |
TRADING_RPC_URL | https://rpc.ethereal.trade | Ethereal RPC endpoint |
Customize the Agent Persona
Edit src/character.ts to customize your agent's personality and behavior:
export const character: Character = {
name: "Your Agent Name",
system: `Your custom system prompt...`,
bio: [
"Agent bio lines...",
],
// ...
};Key areas to customize:
name: Your agent's display namesystem: The main system prompt that guides the agent's behaviorbioandlore: Background information the agent uses for contextstyle: Formatting and tone guidelines
Change the Model
Be sure to use a model with web search capability unless you've built a different workflow/pipeline to injest current information.
The default model is openai/gpt-4o-search-preview via OpenRouter. To change it, edit src/character.ts:
settings: {
model: "anthropic/claude-3.5-sonnet", // or any OpenRouter model
temperature: 0.2,
// ...
}Or set via environment variable for quick testing.
Deployment
One-Click Deploy
Deploy to Railway in minutes:
After deploying:
- Add your environment variables (
OPENROUTER_API_KEY,EVM_PRIVATE_KEY) - Set
AUTONOMOUS_MODE=forecast(orforecast,trade) to enable automatic operation - Your agent will begin running forecast cycles automatically
Eject to Your Own Repository
Once deployed on Railway, you can eject the code to your own GitHub repository for full customization.
Prerequisites:- Your GitHub account must be connected to Railway
- Configure the Railway app in: Account Settings → Account → Account Integrations → Configure Railway App
-
In Railway, open your service → Source → Eject → Choose your GitHub org → Eject service
-
Clone your new repository locally:
git clone <your-new-repo-url> my-forecast-agent
cd my-forecast-agent
bun install # or: pnpm install / npm install- Create your
.envfile:
# Required
OPENROUTER_API_KEY=your-openrouter-key
EVM_PRIVATE_KEY=your-private-key
# Optional: Enable autonomous mode
AUTONOMOUS_MODE=forecast,trade- Run locally:
bun run dev- Push changes to your repo. Enable Autodeploy in Railway so pushes trigger automatic redeployments.
Manual Deployment
For other platforms or manual deployment, see the Railway CLI guide or build the project directly:
bun run build
bun run startThe agent can run on any platform that supports Node.js and Bun.