Skip to content

Repository files navigation

VAPM-QVAC: Sovereign AI Trading Agent

An autonomous AI trading agent where ALL inference runs locally via QVAC SDK. No cloud APIs. No data leakage. Your strategy never leaves your device.

Hackathon: Frontier Hackathon (Tether QVAC Side Track)


The Problem

AI trading agents today rely on cloud APIs for inference. Every prediction request sends your market data, position sizes, and strategy signals to a third-party server. Your alpha leaks. Your privacy is gone. Your strategy is one API log away from being copied.

The Solution

VAPM-QVAC runs ALL AI inference locally using Tether's QVAC SDK:

  • XGBoost price prediction -- trained model runs on your machine
  • QVAC local LLM (Llama 3.2) -- explains trade reasoning in natural language, assesses risk, analyzes market conditions. All on-device, zero cloud calls.
  • Dune SIM -- real-time wallet data and transaction history

The agent's strategy, predictions, and reasoning never leave your device. This is sovereign intelligence for trading.

How QVAC Is Used (Core Integration)

QVAC is not a wrapper or demo. It provides three critical capabilities that run the agent's decision-making:

1. Trade Reasoning

The XGBoost model outputs "BUY with 72% confidence." But WHY? QVAC's local LLM reads the SHAP feature importances and generates a natural language explanation: "RSI is oversold at 35, MACD just crossed bullish, and volatility is declining -- conditions favor a long entry."

2. Risk Assessment

Before every trade, QVAC's local LLM evaluates whether the proposed trade violates risk limits and whether the confidence level justifies the position size. This is an AI-powered risk manager running entirely on your hardware.

3. Market Analysis

QVAC analyzes raw technical indicators and produces a human-readable market summary. No cloud API needed -- the analysis runs in milliseconds on your GPU via Vulkan.

Without QVAC: The agent can predict UP/DOWN but cannot explain why, cannot assess risk in natural language, and cannot analyze market conditions. It becomes a black box.

How Dune SIM Is Used

Dune SIM provides real-time wallet data:

  • Wallet balance tracking across Solana tokens
  • Transaction history for portfolio analysis
  • Token metadata enrichment

Replaces raw Solana RPC calls with SIM's pre-enriched data (200ms from block propagation).

Architecture

  Browser (Next.js Dashboard, port 3000)
       |                    |
       | /predict           | /api/cycle
       v                    v
  ML Backend            QVAC Server
  (FastAPI, 8001)       (Node.js, 8002)
       |                    |
  XGBoost + SHAP       QVAC SDK (Llama 3.2 1B)
  (local inference)     (local GPU inference via Vulkan)
                            |
                    +-------+-------+
                    |       |       |
               Reasoning  Risk   Market
               "WHY?"   "SHOULD?" "WHAT?"
                            |
                       Dune SIM API
                    (wallet balances, tx history)

Three services, all local:

Service Port Role
ML Backend (Python) 8001 XGBoost prediction + SHAP explainability
QVAC Server (Node.js) 8002 Local LLM reasoning, risk assessment, market analysis
Frontend (Next.js) 3000 Dashboard with live inference status

Quick Start

# 1. Install Node.js dependencies (QVAC SDK requires Node >= 22)
nvm use 22   # or install: nvm install 22
npm install

# 2. Start the ML prediction service
cd backend && pip install fastapi uvicorn joblib && python main.py &

# 3. Start the QVAC server (loads Llama 3.2 locally, exposes HTTP API on port 8002)
npm run serve

# 4. Start the frontend dashboard
cd frontend && npm run dev

# 5. Open http://localhost:3000 and click "Run Agent Cycle (Live QVAC)"

The dashboard works in two modes:

  • Live QVAC mode: When npm run serve is running, the "Run Agent Cycle" button triggers real on-device LLM inference via QVAC SDK. All reasoning is generated by Llama 3.2 1B running locally.
  • Demo mode: Without the QVAC server, the dashboard still shows ML predictions from XGBoost but displays pre-computed reasoning text. A banner indicates demo mode.
# Alternative: Run CLI agent (one-shot cycle, no frontend)
node src/agent.js

# Test QVAC reasoner directly
node src/qvac-reasoner.js

Requirements

  • Node.js >= 22.17
  • Python 3.11+
  • GPU with Vulkan support (QVAC uses hardware-agnostic GPU inference)
  • ~700MB disk for the Llama 3.2 1B model (downloaded once)

Project Structure

vapm-qvac/
  src/
    server.js           -- QVAC HTTP server (LLM + RAG + TTS endpoints)
    agent.js            -- CLI agent orchestrator (one-shot cycle)
    qvac-reasoner.js    -- QVAC LLM integration (reasoning, risk, analysis)
    qvac-rag.js         -- QVAC RAG integration (embeddings, knowledge search)
    dune-sim.js         -- Dune SIM wallet data client
  data/
    knowledge/          -- Trading knowledge base for RAG
      trading_rules.txt       -- Position sizing, risk limits, entry/exit rules
      sol_market_context.txt  -- SOL/USDC market context and technical levels
      shap_interpretation.txt -- Guide for interpreting SHAP feature values
  frontend/             -- Next.js dashboard (calls QVAC server for live inference)
  backend/
    main.py             -- FastAPI ML prediction service
  ml/
    models/             -- XGBoost model + comparison results
    backtest_results.json

API Endpoints

ML Backend (port 8001)

GET  /health             Health check
GET  /predict            XGBoost prediction + SHAP values
GET  /features/latest    Current technical indicator values
GET  /risk/state         Risk metrics (daily PnL, drawdown, exposure)
GET  /predict/model      Model metadata and accuracy
GET  /backtest/results   Historical backtest performance

QVAC Server (port 8002)

GET  /health             Server + model loading + RAG status
POST /api/cycle          Full agent cycle (predict + RAG search + reason + risk + market)
POST /api/reason         Trade reasoning from SHAP data (real LLM inference)
POST /api/risk           Risk assessment for proposed trade (real LLM inference)
POST /api/market         Market analysis from technical indicators (real LLM inference)
GET  /api/rag-status     RAG knowledge base status (initialized, file count)

Key QVAC Capabilities Used

Capability SDK Function Usage
LLM Loading loadModel (Llama 3.2 1B Q4_0) Load quantized LLM with progress tracking
LLM Inference completion({ stream: true }) Streaming token generation for reasoning
Embeddings loadModel (EmbeddingGemma 300M Q4_0) Load embedding model for RAG
RAG Chunking ragChunk Split knowledge documents into indexed chunks
RAG Ingestion ragIngest Embed and index chunks into local workspace
RAG Search ragSearch Retrieve relevant context before LLM inference
Model Lifecycle unloadModel Clean shutdown of GPU resources

How RAG Works

The agent maintains a local knowledge base (data/knowledge/) containing trading rules, risk guidelines, SOL market context, and SHAP interpretation guides. On startup, these documents are chunked, embedded using EmbeddingGemma 300M, and indexed into a QVAC RAG workspace.

Before each trade reasoning call, the agent searches the knowledge base with a query derived from the current prediction and top SHAP features. Retrieved context is prepended to the LLM prompt, making the reasoning informed by domain expertise -- not just raw SHAP numbers.

All embedding and retrieval runs locally. No external search API. No cloud vector database.

Why Local AI Matters for Trading

Cloud AI QVAC Local AI
Every request sends your data to a server Data never leaves your device
API provider sees your strategy Nobody sees your strategy
Dependent on internet connection Works offline
API costs per request One-time model download
Provider can log and sell your patterns Sovereign -- you own everything

Built for the Frontier Hackathon, Tether QVAC Side Track.

About

Sovereign AI trading agent -- all inference runs locally via QVAC SDK (Llama 3.2), no cloud APIs

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages