TOMO Agent Architecture Whitepaper
Technical architecture of TOMO - the autonomous spot trading agent. Core invariants, state machine design, pure domain logic, emergent learning, and self-healing mechanisms.
Last updated: January 15, 2026
“A disciplined, principle-driven spot trading system that learns, adapts, and never compromises on safety.”
What We’re Building
TOMO is not just a trading bot—she’s an emergent trading intelligence that:
- Thinks before acting (pure domain logic, no impulsive IO)
- Learns from every trade (feedback loops, fitness tracking)
- Adapts to market conditions (homeostasis, parameter evolution)
- Never compromises on safety (invariants are law, not suggestions)
- Explains herself (full audit trail, reasoning transparency)
Core Invariants (Sacred Laws)
These are non-negotiable and must survive every refactor:
| Invariant | Description |
|---|---|
INVARIANT_001 | Never sell at a loss (diamond hands) |
INVARIANT_002 | One trade at a time (serialization) |
INVARIANT_003 | Fresh balance before every buy (no stale data) |
INVARIANT_004 | Reserve SOL for fees (0.01 minimum) |
INVARIANT_005 | Rate limit between trades (5s minimum) |
INVARIANT_006 | Daily loss limit circuit breaker |
INVARIANT_007 | Position size limits (max SOL per trade) |
INVARIANT_008 | Capital depletion triggers monitoring mode |
State Machine
TOMO operates as an explicit finite state machine:
States: idle → active_trading → evaluating → executing → monitoring_positions → paused → stopped
Events: START_TRADING, EVALUATE_TICK, TRADE_SIGNAL, EXECUTE_TRADE, CAPITAL_DEPLETED, etc.
Transition Table
| From | Event | Guard | To | Notes |
|---|---|---|---|---|
idle | START_TRADING | hasWallet && hasTokens | active_trading | Begin trading session |
active_trading | EVALUATE_TICK | !tradeInProgress | evaluating | Periodic evaluation |
evaluating | TRADE_SIGNAL | signalValid | executing | Strategy found opportunity |
evaluating | NO_SIGNAL | - | active_trading | No opportunity found |
executing | TRADE_SUCCESS | - | active_trading | Trade completed |
executing | TRADE_FAILED | - | active_trading | Trade failed, continue |
active_trading | CAPITAL_DEPLETED | balance < minTrade | monitoring_positions | Out of capital |
monitoring_positions | EXIT_SIGNAL | pnl > 0 | executing | Profitable exit found |
* | STOP_TRADING | - | stopped | User stopped |
* | CIRCUIT_BREAK | dailyLoss > limit | paused | Safety triggered |
Current Capabilities
Safety Guards Implemented
- Never sell at loss (hard block in
executeTrade) - Trade lock prevents concurrent execution
- Fresh balance check before buys
- Rate limiting (5s between trades)
- Reserve for fees (0.01 SOL)
- Monitoring mode when capital depleted
Price System
- Jupiter Data API for position prices
- 10-second refresh loop
- SOL-denominated P&L calculation
Strategy Framework
- Take-profit strategy (15% target)
- Momentum entry strategy
- Mean reversion entry strategy
- Risk-off disabled (diamond hands)
Architecture Principles
Pure Domain Core (Algebraic Effects)
Trading decisions are pure functions that return effect descriptions:
;
;
The domain never performs IO directly. It describes what should happen; the infrastructure layer interprets those descriptions.
Emergence & Learning
TOMO tracks fitness metrics per strategy:
Over time, TOMO adjusts strategy weights based on performance, evolving toward more profitable behavior.
Living System Features
Self-Healing Watchdog
- Detects stuck states (generating too long, tooling timeout)
- Automatically recovers by forcing transitions
- Logs recovery events for analysis
Health Ledger
- Tracks system health across dimensions
- Triggers alerts when thresholds exceeded
- Enables self-assertions (“I am healthy because…”)
Circuit Breakers
- Trip after repeated failures
- Require deliberate reset
- Protect against cascade failures
Guiding Documents
| Document | Key Takeaway for TOMO |
|---|---|
| FSM Appendix | All trading logic as explicit state machine |
| Algebraic Effects | Trading decisions are pure; effects are descriptions |
| Concurrency Patterns | One writer per position; timers as events |
| Emergence Theory | Simple rules → complex behavior; fitness functions |
| FRP General | Intent → reduce → effect streams; explicit backpressure |
| Streams | Market data as first-class streams; watermarks for staleness |
| Living Foundation | Health ledger; self-assertions; circuit breakers |