PancakeSwapAI is an intelligent, adaptive multi-agent trading system designed to operate in real-time DeFi environments like PancakeSwap. The system continuously ingests market state, interprets changing conditions, selects opportunities with explicit confidence, applies risk gates, and produces transparent execution plans in simulation-first mode.
It is engineered as a decision system, not a signal script: each cycle combines market context, temporal behavior, regime interpretation, strategy competition, and risk adjudication before any action is proposed.
DeFi markets are fast, fragmented, and noisy. Liquidity shifts quickly, volatility regimes change intraday, and static rule sets degrade under new conditions.
A resilient system must adapt in real time, avoid forcing low-quality trades, and make its internal reasoning observable. PancakeSwapAI is built around that principle.
The backend runs a continuous cycle and executes a deliberate multi-stage decision process:
- Market Agent normalizes market state from configured sources and provides a coherent snapshot for downstream reasoning.
- Signal Layer updates rolling history and extracts cross-pool and temporal features from recent behavior.
- Regime Detector classifies the active market context (
TRENDING,MEAN_REVERTING,VOLATILE, etc.) to condition strategy behavior. - Strategy Agent evaluates competing hypotheses across strategy modules and selects the highest expected-value candidate.
- Risk Agent validates position quality against constraints (size, slippage, confidence, and safety checks) and can veto execution.
- Execution Agent emits a simulated or executable trade plan with full context for review.
- State Export Layer publishes structured state to in-memory and file-backed channels for APIs and UI observability.
The dashboard polls backend state on a 2-second cadence and exposes:
- live cycle status and system health
- current regime and temporal metrics
- selected strategy with confidence/profit context
- per-agent pages (market, strategy, risk, execution, portfolio)
- decision timeline and logs for auditability
- market-data source settings controls
.
├── agents/ # market/strategy/risk/execution/portfolio agent logic
├── core/ # pipeline, signals, regime, history, export, adapters
├── strategies/ # pluggable strategy modules
├── shared/ # shared domain types
├── server.ts # Express server + /state endpoint
├── index.ts # bootstrap + continuous pipeline loop
├── config.ts # runtime defaults + source sync
└── dashboard/ # Next.js observability interface
The architecture is designed for AMM-style environments, optimized for pool-based liquidity behavior, and compatible with PancakeSwap-style markets without claiming official integration.
The system adjusts behavior from observed outcomes over time. Strategy confidence and selection priority evolve as new cycle evidence accumulates.
Operators can query system state and interpret why decisions were taken, reducing dependence on raw log inspection alone.
Trade paths can be evaluated in simulation-first mode before execution. This supports counterfactual analysis and safer strategy iteration.
Market State
↓
Signal Extraction
↓
Regime Classification
↓
Strategy Selection
↓
Risk Adjudication
↓
Execution Planning (Sim/Dry Run)
↓
Feedback + State Export
The dashboard is the system’s observability layer, focused on decision transparency rather than output-only reporting.
It surfaces live system thinking: regime interpretation, strategy rationale, risk approvals/rejections, and execution context across recent cycles.
Primary routes:
/live monitor/logs/agents/market/agents/strategy/agents/risk/agents/execution/agents/portfolio/liquidity/settings
---Local development note: the live-state hook currently targets
https://pancakeswapai-production.up.railway.app/state. For local backend integration, updatedashboard/app/hooks/useLiveState.ts.
- Node.js 20+
- npm 10+
npm install
npm --prefix dashboard installnpm run buildnpm startBackend default bind: 0.0.0.0:${PORT:-3000}.
npm run dev:frontendnpm run dev
npm run devstarts compiled backend (dist/index.js) and Next.js dev server concurrently. Build first (npm run build) or usenpm run dev:full.
| Variable | Required | Purpose |
|---|---|---|
PRIVATE_KEY |
Optional in demo mode | Wallet key for real execution paths |
PORT |
Optional | Backend listen port (default 3000) |
MARKET_DATA_SOURCE |
Optional | Initial source (ON_CHAIN, DEXSCREENER, SUBGRAPH) |
SIGNAL_NOISE_SEED |
Optional | Deterministic noise seed for temporal signals |
RAILWAY_GIT_COMMIT_SHA / GITHUB_SHA / VERCEL_GIT_COMMIT_SHA |
Optional | Commit metadata for boot logs |
config.ts includes defaults for chain/RPC (BSC), slippage, gas, sizing, poll interval, temporal signal noise, and market-data fallback order.
The backend reads preference from disk:
dashboard/public/market_data_config.json- fallback:
public/market_data_config.json
Dashboard settings API endpoints:
GET /api/market-dataPOST /api/market-data
- Adaptive: behavior changes with observed market outcomes.
- Selective: the system can intentionally abstain from trading.
- Transparent: decisions are exported for operator visibility.
- Modular: strategy modules are plug-and-play within the strategy agent.
Returns health text:
Backend alive
Returns, in order:
- latest valid in-memory exported state
- fallback
latest_state.jsonpayload - default boot response:
{ "status": "starting" }- Move dashboard state endpoint to environment-driven configuration.
- Expand automated tests for regime detection and strategy ranking.
- Add structured metrics endpoints for monitoring and alerting.
- Introduce persistent paper-trade ledger + replay tooling.
- Add CI checks for backend build and dashboard lint/build.



