Cortex Agent SDK
Build autonomous AI agents that execute on-chain actions across Solana, Ethereum, Polygon, BNB Chain, and Base.
Installation
Install the Cortex Agent SDK using your preferred package manager:
npm install @Cortex-ai/agent-sdk
# or
yarn add @Cortex-ai/agent-sdk
pnpm add @Cortex-ai/agent-sdkQuick Start
Create your first Cortex agent in under 5 minutes:
import { Cortex } from '@Cortex-ai/agent-sdk'
// Initialize the agent
const agent = new Cortex({
wallet: process.env.WALLET_KEY,
chains: ['solana', 'ethereum', 'base'],
model: 'Cortex-v2',
riskLevel: 'moderate'
})
// Execute a simple swap on Solana
const result = await agent.execute({
action: 'swap',
chain: 'solana',
from: 'SOL',
to: 'USDC',
amount: '1.5',
slippage: 0.5
})
console.log('Transaction:', result.txHash)
console.log('Amount received:', result.amountOut)Configuration
The Cortex constructor accepts a configuration object with the following options:
walletstringchainsstring[]modelstringriskLevelstringnotificationsstringstopLossstringmaxSlippagenumberCreating Agents
Agents are autonomous entities that execute strategies on your behalf. Each agent runs independently and can be configured with different parameters.
import { Cortex } from '@Cortex-ai/agent-sdk'
// Trading agent — focuses on DEX swaps
const trader = new Cortex({
wallet: process.env.WALLET_KEY,
chains: ['solana'],
model: 'Cortex-v2',
riskLevel: 'aggressive'
})
// Prediction agent — focuses on prediction markets
const predictor = new Cortex({
wallet: process.env.WALLET_KEY,
chains: ['polygon', 'ethereum'],
model: 'Cortex-v2',
riskLevel: 'conservative'
})
// Deploy both agents
await Promise.all([
trader.deploy({ mode: 'autonomous' }),
predictor.deploy({ mode: 'autonomous' })
])Strategies
Define custom strategies that your agent executes autonomously:
agent.strategy('alpha-hunter', {
// What triggers the strategy
triggers: [
{ type: 'price_change', threshold: '5%', timeframe: '1h' },
{ type: 'whale_alert', minAmount: 100_000 },
{ type: 'new_pool', dex: 'raydium' }
],
// Actions to execute when triggered
actions: [
'analyze_sentiment',
'check_liquidity',
'calculate_position_size',
'execute_swap'
],
// Risk parameters
risk: {
maxPositionSize: '5%',
stopLoss: '10%',
takeProfit: '25%'
}
})Supported Chains
Cortex connects directly to private validator and RPC nodes across all supported chains:
Token Swaps
Execute swaps across all supported DEXs with automatic best-route selection:
const result = await agent.execute({
action: 'swap',
chain: 'solana',
from: 'SOL',
to: 'BONK',
amount: '2.0',
slippage: 1.0,
dex: 'auto' // auto-routes via Jupiter, Raydium, Orca
})
// result.txHash — transaction signature
// result.amountOut — tokens received
// result.route — DEX route used
// result.fee — transaction fee paidCross-Chain Bridge
Bridge assets between chains using integrated Wormhole and LayerZero protocols:
const bridge = await agent.execute({
action: 'bridge',
from: { chain: 'solana', token: 'USDC' },
to: { chain: 'ethereum', token: 'USDC' },
amount: '500',
protocol: 'auto' // selects cheapest route
})
// Monitor bridge status
const status = await agent.getBridgeStatus(bridge.bridgeId)
console.log(status) // 'pending' | 'confirmed' | 'completed'Prediction Markets
Interact with prediction markets using AI-powered analysis. Supported platforms: Polymarket, Azuro, Overtime, Hedgehog, SX Bet, Thales.
// Analyze and bet on a prediction market
const prediction = await agent.execute({
action: 'predict',
platform: 'polymarket',
market: 'us-presidential-election-2028',
analysis: {
sources: ['on-chain', 'sentiment', 'historical'],
minConfidence: 0.85
}
})
// prediction.confidence — AI confidence score
// prediction.recommendation — 'yes' | 'no' | 'skip'
// prediction.reasoning — AI explanation
// Place the bet if confidence is high
if (prediction.confidence > 0.85) {
await agent.execute({
action: 'bet',
platform: 'polymarket',
marketId: prediction.marketId,
outcome: prediction.recommendation,
amount: '50' // USDC
})
}Staking
Stake tokens across liquid staking protocols:
// Liquid stake SOL via Marinade
const stake = await agent.execute({
action: 'stake',
chain: 'solana',
protocol: 'marinade',
token: 'SOL',
amount: '10'
})
// Stake ETH via Lido
const ethStake = await agent.execute({
action: 'stake',
chain: 'ethereum',
protocol: 'lido',
token: 'ETH',
amount: '1.0'
})Risk Management
Built-in risk management protects your portfolio:
agent.setRiskParameters({
// Portfolio-level limits
maxDrawdown: '15%',
maxDailyLoss: '5%',
maxPositionSize: '10%',
// Per-trade limits
maxSlippage: 1.0,
minLiquidity: 50_000, // USD
// MEV protection
mev: {
solana: 'jito', // Jito bundles
ethereum: 'flashbots' // Flashbots Protect
},
// Auto-pause conditions
pauseOn: [
'anomaly_detected',
'high_volatility',
'low_liquidity'
]
})Event Listeners
React to on-chain events in real-time:
// Listen for whale movements
agent.on('whale_transfer', async (event) => {
console.log(`Whale moved ${event.amount} ${event.token}`)
if (event.amount > 1_000_000) {
await agent.execute({
action: 'analyze',
target: event.token,
context: event
})
}
})
// Listen for new liquidity pools
agent.on('new_pool', async (event) => {
console.log(`New pool: ${event.pair} on ${event.dex}`)
})
// Listen for prediction market resolutions
agent.on('market_resolved', async (event) => {
console.log(`Market ${event.marketId} resolved: ${event.outcome}`)
})Deploying Agents
Deploy your agent to run autonomously on Cortex infrastructure:
const deployment = await agent.deploy({
mode: 'autonomous',
// Notifications
notifications: {
telegram: process.env.TELEGRAM_BOT_TOKEN,
chatId: process.env.TELEGRAM_CHAT_ID,
events: ['trade_executed', 'stop_loss', 'prediction_placed']
},
// Scheduling
schedule: {
active: 'always', // or cron: '0 9 * * 1-5'
timezone: 'UTC'
},
// Safety
stopLoss: '15%',
maxDailyTrades: 50
})
console.log('Agent deployed:', deployment.agentId)
console.log('Dashboard:', deployment.dashboardUrl)What happens after deployment?
- Your agent runs 24/7 on our private node infrastructure
- All transactions are executed directly via private RPC — no intermediaries
- Instant Telegram/Discord notifications for every action
- Auto-pause if risk parameters are breached
2025 Cortex. All rights reserved.