CortexAI
v1.0.0

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:

terminal
npm install @Cortex-ai/agent-sdk

# or
yarn add @Cortex-ai/agent-sdk
pnpm add @Cortex-ai/agent-sdk
Requires Node.js 18+TypeScript 5.0+

Quick Start

Create your first Cortex agent in under 5 minutes:

agent.ts
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:

wallet
string
Path to wallet keypair file or private key
chains
string[]
Array of chains to operate on: 'solana', 'ethereum', 'polygon', 'bnb', 'base'
model
string
AI model version: 'Cortex-v1' or 'Cortex-v2' (recommended)
riskLevel
string
'conservative', 'moderate', or 'aggressive'
notifications
string
'telegram', 'discord', or 'webhook'
stopLoss
string
Max loss threshold before auto-pause, e.g. '10%'
maxSlippage
number
Maximum allowed slippage in percentage

Creating Agents

Agents are autonomous entities that execute strategies on your behalf. Each agent runs independently and can be configured with different parameters.

multi-agent.ts
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:

strategy.ts
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:

SolanaPrimary
Mainnet-Beta~12ms
Ethereum
Mainnet~24ms
Polygon
PoS Mainnet~18ms
BNB Chain
BSC Mainnet~22ms
Base
L2 Mainnet~15ms

Token Swaps

Execute swaps across all supported DEXs with automatic best-route selection:

swap.ts
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 paid

Cross-Chain Bridge

Bridge assets between chains using integrated Wormhole and LayerZero protocols:

bridge.ts
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.

predict.ts
// 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:

stake.ts
// 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:

risk.ts
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:

events.ts
// 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:

deploy.ts
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.