Enterprise Advisory Workbench powered by TORQ AI
TORQ Console is an enterprise advisory workbench that surfaces structured intelligence across advisory, market, document review, drafting, and orchestration workspaces. TORQ AI is the lead advisor, powered by a fine-tuned Qwen3-8B model (prince-flowers V4) and routed through a 4-tier model cascade. The system classifies every user message into a render type, routes it to the appropriate backend intelligence path, and returns structured payloads rendered on dedicated workspace canvases.
The frontend is a visualization and orchestration layer — not a chat app. Structured canvases own the center workspace. Chat is a demoted fallback renderer.
TORQ Console is a governed, adaptive, agentic intelligence platform — far more than a chat interface. It combines a clean React frontend with a layered, self-improving backend that enforces policy, learns from outcomes, and scales securely.
The entire system is visualized in docs/workflows.html (open it in any browser). The single source of truth is docs/workflows.json, which defines planes, nodes, flows, clusters, and interactive view modes.
The system is cleanly separated into four horizontal planes:
- Operator Plane — Human interface: chat, enforcement dashboard, memory inspector, observability dashboard, and Slack notifications.
- Control Plane (Adaptive Intelligence) — Prince Flowers core + governance, risk classification, routing, and policy evolution.
- Execution Plane — Runtime services: FastAPI backend, event bus, embedding pipeline, metrics, and external model providers.
- Persistence Plane — Supabase Postgres + pgvector RAG, decision memory, audit logs, and GitHub as source-of-truth.
At the heart of the system sits Prince Flowers, the adaptive intelligence engine (highlighted in purple in the visualizer). It powers:
- 8-stage deterministic classifier
- L17–L28 Adaptive Intelligence Stack — a numbered ladder of specialized layers:
- L17 Evolution / Mutation Engine
- L18 Governance Layer (promotion policy engine — configurable benchmark thresholds, supervised/automatic approval modes, append-only decision audit)
- L19 Predictive Intelligence
- L20 Strategic Intervention
- L21 Enforcement Ladder
- L22.5 Context Pipeline
- L22.6 Decision Memory
- L25 Risk Classifier
- L26 DefendSwarm Specialists
- L27 4-Tier Model Router
- L28 Experience Engine
This stack turns every decision into learning data, continuously evolving policy, prompts, and routing weights through a closed-loop feedback system.
- Live Proof Path — The exact end-to-end production path (risk → enforcement → classification → routing → Claude response).
- Risk-First Execution — Every request is classified for risk (LOW/MED/HIGH/CRITICAL) before any model call.
- Adaptive Learning Loop — Decision events → Experience Engine (L28) → mutation proposals → governance approval → live policy updates.
- Governance & Rollback — Multi-party approval workflows, staged commits, append-only audit trail, and one-click rollback.
- Observability Pipeline — Full OpenTelemetry tracing + metrics surfaced in the operator dashboard.
- RAG Ingestion & Retrieval — Automatic freshness tracking from GitHub into pgvector.
The architecture visualizer supports multiple curated views so stakeholders see exactly what they need:
- Working Now — Live runtime only (green nodes)
- Full System — Everything, including planned and future items
- Learning Loop — Adaptive feedback cycle
- Governance Loop — Approval, audit, rollback
- Failure Paths — Rejection, block, retry, and degraded modes
- Risk-First + Enforcement — Safety is never an afterthought.
- Adaptive Intelligence — The system literally improves itself from real outcomes (
torq_score). - Tiered Intelligence — Local Ollama → GLM (Z.ai) → Claude Sonnet/Opus with intelligent routing.
- Governed Evolution — No uncontrolled changes; every mutation goes through human + automated review.
Explore the full interactive diagram: docs/workflows.html
Every classified request is routed to the cheapest model that can satisfy it. Stakes, intent class, and web-search needs can escalate a request to a higher tier.
| Tier | Model | Provider | Role |
|---|---|---|---|
| 1a | llama3.1:8b |
Local Ollama (via tunnel) | Fast, free, clean output |
| 1b | qwen3:8b (prince-flowers V4) |
Local Ollama (via tunnel) | Thinking model for RAG / advisory |
| 2 | glm-5-turbo |
Z.ai (GLM) | Medium-complexity, cheap cloud |
| 2.5 | NVIDIA NIM | Self-hostable GPU | Enterprise / GPU-optimized (optional) |
| 3 | Claude Sonnet / Opus (frontier: claude-opus-4-6) |
Anthropic | Highest quality, web search, full history |
Web search (web_search_20250305) only works on Tier 3 Claude — Tier 1 (local) has no network and Tier 2 (GLM) does not honor the Anthropic tool type, so search-needing intents are force-routed to Tier 3. The frontier model is configurable via TORQ_FRONTIER_MODEL.
- PDF: Print dialog via
window.open()with styled HTML - DOCX: Full markdown-to-Word conversion (headings, lists, blockquotes, tables, inline formatting) via
docx-js - Markdown: Direct
.mdfile download
- Messages stored in
chat_sessionstable (JSONB array) - Loaded via
SessionStore.get_session_history()withmax_messages=10 - Multi-turn recall verified across sessions
user_contexttable:context_type+context_key+ JSONB value- Portfolio holdings, strategy preferences, watchlist
- 5-minute cache on Vercel, injected into every request
torq_memorytable with importance scoring (0.0-1.0)- IRS tax knowledge (4 rows: deductions, entity_structure, rates_and_limits, citations)
- Injected into system prompt via
_load_dream_memories()
TORQ AI's primary local model is a fine-tuned Qwen3-8B trained on 8,381 examples of TORQ advisory identity, reasoning patterns, and domain vocabulary.
- Base model: Qwen3-8B (Q4_K_M quantization via llama.cpp)
- Training data: 8,381 curated examples covering advisory analysis, market commentary, document review, drafting, and run orchestration
- Serving: Ollama on Railway, exposed as Tier 1b in the L27 router
- Identity: Inherits TORQ AI system prompt, calibrated for structured JSON output with confidence scoring
- Model file:
prince-flowers-model/(Modelfile, training data, export scripts)
TORQ Console is built using a file-driven, multi-agent V5 harness that runs as a 6-pane Windows Terminal session. Each pane is a Claude Code instance bound to a role; hand-off happens by writing harness_status.json, and the convention-based state machine moves a task through design → review → build → audit → refine.
| Role | Model | Provider | Responsibility |
|---|---|---|---|
| g1d (Design) | claude-opus-4-7 |
Anthropic | Reads the PRD, writes build_spec.md + design_questions.md |
| g1r (Gate-1 Review) | claude-opus-4-7 |
Anthropic | Reviews the design contract, approves/rejects |
| builder | deepseek-v4-pro |
DeepSeek | Implements the spec, writes build_result.md with evidence |
| g2a (Gate-2 Audit) | claude-opus-4-7 |
Anthropic | Independently verifies ACs + invariants, writes audit_report.md |
| refine_bug | kimi-k2.6 |
Moonshot | Bug / race-condition refinement |
| refine_ui | glm-5.1 |
Z.ai | UI-polish refinement |
- Artifacts:
.torq/v5/artifacts/(00_input/,01_design/,02_build/,03_audit/,04_refine/,status/) - State machine:
ready → design_complete → gate1_passed → build_complete → complete, with rejection routing back to the appropriate role. - Cost guardrails: $5.00 max per PRD, $3.00 alert threshold.
- Launcher:
.torq/v5/launch/Start-TorqV5Harness.ps1boots the 6-pane session; provider keys are read from.envat startup (never hardcoded).
A curated, version-controlled set of Claude Code subagent specs lives under .claude/agents/fleet/ — 27 specs (e.g. backend-engineer, code-reviewer, credential-security-agent) auto-discovered by Claude Code's recursive .claude/agents/**/*.md scan and selectable by description. Committing them to the repo makes the fleet reproducible on any machine that checks out TORQ-CONSOLE.
These specs are also surfaced inside the runtime AgentRegistry (torq_console/agents/registry.py): a stdlib frontmatter parser loads each spec at __init__ as a lowest-precedence fleet:-prefixed entry, behind the hardcoded DEFAULT_AGENTS and any Supabase overlay (both win on a name collision). The fleet README.md is excluded.
- Claude native
web_search_20250305tool on Railway + Anthropic fallback path - TORQ AI answers real-time market and news queries
Railway web search conditionally enabled — only fires for queries that need real-time data (market_insight, standard_chat). Draft, document review, advisory, and timeline queries skip web search entirely. Reduces input tokens by ~23-38% on non-market calls.
Incoming webhook integration for real-time notifications.
- "Send to Slack" button in Draft workspace alongside PDF/DOCX/MD exports
- Block Kit formatted messages with render-type-specific styling
- L25 governance parameter changes alert to Slack automatically
- Workspace events logged for every Slack export
- Graceful degradation when
TORQ_SLACK_WEBHOOK_URLnot set
Set TORQ_SLACK_WEBHOOK_URL in Railway + Vercel to activate.
TORQ AI matches response depth to query complexity:
- Simple questions: concise 2-4 paragraph answers
- Complex multi-part questions: comprehensive structured analysis
- Long document pastes (>1000 chars): proportional depth with full reasoning
- Deep Mode triggers: "deep dive", "ultrathink", "full analysis" produce 5,000+ character exhaustive analysis with bull/base/bear scenarios, contrarian views, and decision matrices
render_decisionstable: persists every classification decisionlearning_eventstable: persists every interaction for learning context- Writes use httpx REST API with 3s timeout on Vercel
- Agent reads recent learning context into system prompt
Built from PRD v3.0 Complete Build Specification across 8 phases.
[IconRail 56px] [WorkspaceHost flex-1] [ContextPanel 320px conditional]
WorkspaceHost = WorkspaceHeader + CommandSurface + ModeWorkspaceHost + AgentActivityBar
const RENDERER_REGISTRY = new Map<RenderType, RendererConfig>();
// advisory_brief → AdvisoryCanvas + AdvisoryRail
// market_insight → MarketCanvas + MarketRail
// document_review → DocumentCanvas + DocumentRail
// draft_output → DraftCanvas + DraftRail
// run_timeline → RunTimeline + RunRail
// standard_chat → ChatThread + GenericRail (fallback)Map-based dispatch (no switch statements). Unknown types fall back to standard_chat.
| Rail | Data Sources |
|---|---|
| AdvisoryRail | L12 EpistemicArtifactPublisher, LocalQualificationEngine, ContradictionManager + Synthesis |
| DocumentRail | L12 EpistemicAuditService, FederatedClaimRegistry + Risk synthesis |
| MarketRail | L12 signals + market data hooks |
| DraftRail | Templates, version history, export gating |
| RunRail | Teams (TeamExecutionCard, RoundTimeline, RoleRoster, DecisionSummary) |
| Platform | URL / ID | Purpose |
|---|---|---|
| GitHub | github.com/pilotwaffle/TORQ-CONSOLE |
Source (main branch) |
| Vercel | torq-console.vercel.app |
Frontend + API routes (auto-deploys from main) |
| Railway | ROOT railway_app.py via start_railway.py |
Backend intelligence + enforcement |
| Supabase | npukynbaglmcdvzyklqa |
PostgreSQL + pgvector (160+ tables/views — enforcement_events, learning_events, render_decisions, chat_sessions, user_context, torq_memory, torq_config, torq_model_usage, evaluation_results, governance_decisions) |
- Frontend
chatStreaming.tscalls/api/chat/v2(Vercel, non-streaming) api/index.pyclassifies intent, loads user context + dreams + historydraft_output→ Vercel bypass (fast, prepends_SYSTEM_PROMPT)- All others → Railway proxy (
connect=10s, read=120s) - Railway runs enforcement, calls Anthropic Claude, returns structured response
- Fallback: if Railway fails, Vercel calls Anthropic directly (
_chat_anthropic, 170s cap)
ANTHROPIC_API_KEY= # Claude API key
SUPABASE_URL= # Supabase project URL
SUPABASE_SERVICE_ROLE_KEY= # Supabase service role keyRAILWAY_URL= # Railway deployment URL
GLM_API_KEY= # GLM for L22.5 context compaction + Tier 2 routingTORQ_SLACK_WEBHOOK_URL= # Slack incoming webhook (enables Slack integration)
ZHIPU_API_KEY= # Z.AI API key for GLM context compaction (System B)DEEPSEEK_API_KEY= # Builder lane (deepseek-v4-pro)
KIMI_API_KEY= # refine_bug lane (kimi-k2.6)
GLM_API_KEY= # refine_ui lane (glm-5.1, Z.ai)Read from .env by Start-TorqV5Harness.ps1 at launch. Never commit these.
TORQ_TIER3_ENABLED=true
TORQ_TIER3_PROVIDER=glm
TORQ_TIER3_MODEL=glm-5-turbo
TORQ_FRONTIER_MODEL=claude-opus-4-6# Clone
git clone https://github.com/pilotwaffle/TORQ-CONSOLE.git
cd TORQ-CONSOLE
# Backend
pip install -r requirements.txt
cp .env.example .env # Edit with your API keys
python start_railway.py
# Frontend (separate terminal)
cd frontend && npm install && npm run dev| Component | Timeout |
|---|---|
| Frontend abort | 180s |
| Vercel maxDuration | 180s |
| Railway proxy (connect/read) | 10s / 120s |
_chat_anthropic cap |
170s |
| Fallback budget | max(170 - elapsed, 30) |
| Railway Anthropic httpx | 180s |
TORQ Console tracks system health across multiple tables:
| Table | Purpose |
|---|---|
workspace_events |
User interaction telemetry |
render_decisions |
Classifier routing log |
torq_session_metadata |
Session health, cache, frustration |
torq_model_usage |
Token costs across all providers |
torq_config |
Runtime governance parameters |
torq_config_audit |
Append-only governance change log |
torq_enforcement_log |
Enforcement + fast path decisions |
torq_memory |
Dream System persistent memories |
chat_sessions |
Chat history per session |
learning_events |
Interaction history for learning context |
user_context |
Portfolio holdings, strategy preferences, watchlist |
evaluation_results |
L28 torq_score composite scores per response |
governance_decisions |
L18 promotion / lifecycle decision audit trail |
drift_metrics |
Classifier drift scores and anomaly detection |
experience_records |
Experience capture for cognitive learning |
| Optimization | Impact |
|---|---|
| Prompt caching | 69% to 13% cache miss rate |
| Dream memory cache | Per-session 5-min TTL, prefix stable |
| Web search gate | 23-38% input token reduction |
| Draft direct bypass | $0.118/call vs $0.229 fallback |
| Conversation guards | 20 msg / 40K char cap per session |
| Classifier truncation | First 500 chars only |
| 4-tier model routing | Cheapest-capable model per request (local → GLM → Claude) |
v0.30.1— L27 router tier refresh, prince-flowers V4, V5 harness, fleet registryv0.30.0— L25 Phase C Vocabulary Expansion, L27 4-tier router, prince-flowers V4, Phase D monitoring, TORQ AI brandingv0.29.0— L25 Runtime Governance (audit log, validation, risk classifier, fast path)v0.28.1— L22.5 System B Context Pipeline (GLM compaction, 150K threshold)v0.28.0— L22.5 Session Intelligence (frustration, tokens, cache, memory-as-hint)v0.27.0— Multi-model cost routing (Tier 3 GLM-4-Flash), render decision persistence, learning loop
# Backend tests
pytest
# Enforcement tests (125+)
PYTHONPATH=. pytest tests/test_enforcement/ tests/layer21/ -v
# Frontend build verification
cd frontend && npm run buildapi/index.py # Vercel serverless — classifier, routing, bypass, fallback
railway_app.py # Railway backend — enforcement, LLM, web search (ROOT entrypoint)
start_railway.py # Railway start script → uvicorn railway_app:app
.claude/agents/
├── architect.md # V5 harness role prompts (architect/builder/verifier)
├── builder.md
├── verifier.md
└── fleet/ # 27 version-controlled Claude Code subagent specs
.torq/v5/ # V5 development harness (config.yaml, launch/, prompts/, artifacts/)
torq_console/
├── agents/ # AgentRegistry (registry.py), torq_prince_flowers/ + classifier.py
├── integrations/ # slack.py (Slack webhook connector)
├── intelligence/ # l27_router.py (4-tier), context_pipeline.py (L22.5)
├── risk/ # classifier.py (L25 risk levels + fast path)
├── enforcement/ # policy.py, kairos_tick.py, shadow mode, activation
├── layer12-21/ # Epistemic intelligence through historical strategy
├── layer18/ # Governance — promotion_policy_engine.py
├── l28_experience/ # Experience Engine — evaluator.py (torq_score)
├── mission_graph/ # Mission planning and execution
├── teams/ # Multi-agent debate and decisions
└── safety/ # Safety manager with L21 enforcement hook
frontend/src/
├── features/ # Advisory, Market, Documents, Drafts, Runs pages
├── components/
│ ├── shell/ # IconRail, WorkspaceHeader, ModeWorkspaceHost
│ ├── renderers/ # RendererRegistry, ChatThread, types
│ ├── right-rail/ # 5 domain rails + GenericRail
│ ├── command/ # CommandInput, CommandPalette
│ └── chat/ # ChatWindow, ChatMessage (demoted)
├── services/ # chatStreaming.ts, normalizeResponse.ts, telemetry
├── state/ # Zustand stores (session, appShell, workspace, etc.)
├── utils/ # docxExporter.ts
└── router/ # Work-type routes + /system/* legacy routes
Auto-deploys from main branch. Config in vercel.json. maxDuration: 180.
Config in railway.json. Start: python start_railway.py. Entrypoint: ROOT railway_app.py.
Important: ROOT railway_app.py is the only authoritative entrypoint. The prior stale variants (torq_console/railway_app.py, torq_console/ui/railway_app.py) have been removed — do not recreate them.
Contributions welcome! Please see docs/CONTRIBUTING.md for guidelines.
MIT License — see LICENSE for details.
TORQ Console builds on excellent work by:
- Anthropic (Claude API)
- Supabase (PostgreSQL + real-time)
- ZhipuAI / Z.ai (GLM for context compaction + Tier 2 routing)
- DeepSeek, Moonshot (Kimi) — V5 harness builder + refine lanes
- React, Zustand, TanStack Query, Tailwind CSS, docx-js
- The open-source AI community