Docs  /  Grok × `_AugmentedIntelligence` integration brainstorm

Grok × _AugmentedIntelligence integration brainstorm

Status: design / brainstorm (not an implementation PR)
Date: 2026-07-18
Provider: xAI Grok via OpenAI-compatible API (https://api.x.ai/v1, env XAI_API_KEY)


0. What you already have (do not reinvent)

Piece Role today
Settings · grok_api_* Enable flag, key, endpoint, model, temperature, system prompt, max tokens
_LLM_API::initialize(...) Shared multi-provider call surface used across domains
_Thought::Thought2SQL(... grok_response ...) Columns already reserved for Grok replies in MySQL thought
_LLMOrchestration Task router (Chat / Code / Vision / Fast / Reasoning / Driving / Memory)
_DomainLLMBridge Slow-path MathNN curriculum + Gaming coach
Semantic multi-*2vec + ai rag Grounding corpus before LLM (Phase B live)
EthicsGood · LegalShield Safety gates before actions
AgentRuntime · Lua scripts Multi-agent orchestration
Pixel 7 Pro companion Remote typed commands + mic + dashboard

Implication: integration is mostly wiring Grok as a first-class backend into routers, RAG, agents, and settings—not a greenfield chatbot.


1. Positioning: where Grok fits in the stack

Typed commands / speech / mobile
        │
        ▼
 Decision trees + intent (keyword + embed prototypes)
        │
        ▼
 EthicsGood → LegalShield
        │
        ▼
 LLMOrchestration.RouteTask  ──►  backend pick
        │                          ├─ Grok (cloud, general/code/vision/tools)
        │                          ├─ Local (Ollama / llama.cpp / NetLLM)
        │                          └─ Other cloud APIs (legacy)
        ▼
 Grounding pack (optional, always preferred for truthy tasks)
   ├─ semantic RRF / corpus / bible / law
   ├─ memory (working / short / long)
   ├─ thought graph
   └─ portal state / discovery journal
        │
        ▼
 Grok chat/completions (or Responses API)
        │
        ▼
 Parse tool commands → ExecuteToolCommands (dry-run default)
        │
        ▼
 Thought2SQL (fill grok_response) + audit log + optional WP draft

Design rule (same as DomainLLMBridge): Grok shapes plans, curriculum, explanations, routing. Closed-loop 20 ms control stays on MathNN / kernels / A* / RL policies.


2. Integration surfaces (by product area)

2.1 Core LLM provider (highest leverage)

Idea Detail
Grok backend in _LLM_API Map model names grok-4.5, grok-4.3, grok-4.20-*POST https://api.x.ai/v1/chat/completions (or /v1/responses) with Bearer XAI_API_KEY / grok_api_key
Default endpoint Settings default api.x.ai if empty; support custom hostname for proxies
Streaming Console / Dear ImGui / portal SSE stream tokens for long answers
Typed commands llm provider grok, llm model grok-4.5, llm chat …, llm status show Grok enabled + latency
Fallback chain Grok → local Ollama → stub message (never hang agents)

2.2 LLMOrchestration task profiles

Task Suggested Grok model Why
Chat / general grok-4.5 Strongest default intelligence
Code / RSI agents grok-4.5 or grok-build-0.1 Build/code oriented
Reasoning / courtroom / research grok-4.20-*-reasoning Long context + deliberate reasoning
Fast / callouts smaller/faster alias when available Latency budget
Vision multimodal Grok when image path set Desktop camera / screenshot path
Memory-grounded chat any + forced RAG pack Hallucination control

Commands sketch

llm route code
llm route auto "refactor MathNN train loop"
llm grounded chat memory explain last discovery
llm provider grok on

2.3 Semantic RAG + Grok (you just built this)

Idea Detail
RAG-then-Grok ai rag … top-k → inject as system/context → Grok answer with “cite labels”
Law-safe counsel source=law RRF + LegalShield + Grok only for educational framing
Bible / literature coach source=bible or book + Grok literary analysis
Thought continuity NN over thought_graph_nodes → Grok continues prior plan
Hybrid command grok ask with rag law: due process

2.4 Agents & Lua

Agent / script Grok role
Remote-LLM-Router-Agent.lua Prefer Grok when online; local when offline
RSI / multi-agent council scripts Grok as “critic” or “architect” seat
Discovery → WordPress Grok drafts post from discovery JSON (dry-run)
Desktop Support / Application Support Grok explains logs + suggests typed commands
Features-V11-Harness.lua Self-test Grok status + one dry chat

Lua sketch:

grok_status()
grok_chat(system, user)           -- returns text
grok_chat_rag(user, method, source)
llm_route_set_backend("code", "grok-4.5")

2.5 EthicsGood · LegalShield · Safety

Idea Detail
Pre-call gate Assess user text before network call
Post-call gate Scan Grok output for tool-like harmful instructions before ExecuteToolCommands
System prompt charter Always prepend Ethics “Be Good” + LegalShield disclaimer for public modes
Dual-control High-risk intents: Grok may explain law publicly, never give step-by-step crime
Audit ai_features.ai_audit_log + rag_query_log + Thought SQL grok_response

2.6 MathNN / Gaming / DomainLLMBridge

Hook Grok use
llm math curriculum Generate richer JSONL problems (validate schema offline)
llm math distill Better action traces for warm-start (still offline train)
llm gaming coach Narrative coach from episode metrics blob
llm gaming scenario Scenario ideation for RL curriculum
Not Grok as FPS aim policy or PDE stepper

2.7 Tools / function calling (Grok as planner)

Expose a strict allowlist of tools Grok may emit (already partially in ParseToolCommands):

  • semantic docs … / ai rag …
  • tree route intent|domain …
  • discovery record … (draft)
  • graphs export (read-only)
  • kernel catalog / cutlass status (read-only)
  • portal export (read-only)
  • Never raw shell, arbitrary typing inject, IIS recycle without apply + human confirm

Pattern: Grok returns JSON plan → orchestration validates → dry-run by default → human/agent confirm.

2.8 Realtime knowledge (Grok strengths)

xAI docs: enable Web Search / X Search tools for current events.

Use in AI How
News / weather assist Grok + web search; still run WeatherHazards module for structured hazards
X / social situational awareness Grok X Search (policy-limited); do not replace Safety/Legal
Research agents Grok + citations → Discovery journal draft

2.9 Multimodal: Imagine + vision

Capability Integration idea
Grok Imagine image Generate icons / slides / teaching diagrams → CreativeDesk / portal assets
Grok Imagine video Short explainers for MathNN concepts or game coach clips
Image input Desktop camera frame / screenshot → Grok vision for “what’s on screen” when local OD fails
Voice API Optional speech path alongside GoogleSpeech / local STT

2.10 Mobile companion (Pixel 7 Pro)

Idea Detail
Keep Grok on desktop Phone only sends typed commands; keys never on device
rsi agent profile AndroidCompanion Desktop Grok summarizes mic transcript + vision events
Offline phone Local TFLite only; Grok when LAN to desktop is up

2.11 Settings · MySQL · portal

Idea Detail
Settings UI polish Endpoint default https://api.x.ai/v1, model catalog from docs
MySQL ai_settings Persist Grok key encrypted / profile grok_lab
Portal Graphs Node grok → edges from LLM route, RAG, agents
Usage meter Log tokens + latency per call for cost control
Profile presets settings profile apply grok_default / grok_code / grok_rag

2.12 Brainstorm stack / integrate hub

Idea Detail
InitBrainstormStack Probe Grok: llm provider grok doctor (HTTP health, no secrets printed)
Architecture graph Node grok category model, edges rag→grok, grok→tools
Stack selftest Soft check: if key set, one tiny completion; else SKIP
Doc index This file linked from BrainstormStack + ChatSession-Features

3. Concrete command surface (proposed)

# Provider
llm provider list
llm provider grok on|off|status|doctor
llm model set grok-4.5
grok status | grok chat <text…> | grok stream <text…>

# Grounded
grok rag [source=law|bible|book] [method=rrf] <question…>
llm grounded chat semantic <question…>

# Orchestration
llm route reasoning
llm route auto <prompt…>
llm domain profile load research_grok

# Safety
legal check <text>
ethics good evaluate <text>

# Agents
agent spawn remote_llm
lua run lua_scripts/Remote-LLM-Router-Agent.lua

4. Phased roadmap

Phase G0 — Wire existing settings (1–2 days)

  • [ ] Confirm _LLM_API path for grok_* settings hits api.x.ai
  • [ ] Normalize endpoint to OpenAI-compatible /v1/chat/completions
  • [ ] Default model string → grok-4.5
  • [ ] Fill Thought2SQL grok_response on success
  • [ ] llm status / grok status shows enabled, model, last latency (no key leak)

Phase G1 — Orchestration + RAG (3–5 days)

  • [ ] Router backends: grok for Chat/Code/Reasoning when online
  • [ ] grok rag = Phase B RRF + Grok synthesis
  • [ ] Tool parse allowlist + dry-run
  • [ ] Lua: grok_chat, grok_status
  • [ ] Audit + portal node

Phase G2 — Domain usefulness (1 week)

  • [ ] DomainLLMBridge uses Grok when enabled for curriculum/coach
  • [ ] Discovery draft posts via Grok
  • [ ] Agent profiles: Research, Desktop Support, Law-education (safe)

Phase G3 — Multimodal & realtime (later)

  • [ ] Image input path (screenshot / camera)
  • [ ] Imagine image/video for CreativeDesk
  • [ ] Web/X search tools for research agents
  • [ ] Optional Voice API

Setting Recommended default
grok_api_enabled false until key present
grok_api_key from XAI_API_KEY env if file empty
grok_api_endpoint https://api.x.ai/v1
grok_model grok-4.5
grok_max_tokens 4096 (raise for reasoning)
grok_temperature 0.3 tools / 0.7 chat
grok_system_prompt Be Good + tool rules + “prefer grounded facts from RAG”

Never log full API keys; mask in status (sk-…****).


6. Safety, privacy, cost

Risk Mitigation
Key leakage Settings + env only; never mobile app; never portal JSON
Tool abuse Allowlist + dry-run + LegalShield/Ethics on plan + human confirm for mutations
Hallucinated law/medicine Force RAG source filters; refuse “how to” crime; disclaimers
Cost blowups Token caps, per-session budget, cache repeated RAG packs
Offline enterprise Router falls back to local models; Grok optional
PII to cloud Redact memory dumps; policy toggle grok_allow_memory_upload

7. Success metrics

Metric Target
Cold chat latency (grok-4.5) Track p50/p95 in status
RAG+Grok citation rate ≥ 1 retrieved label referenced in answer (spot check)
Tool plan valid rate ≥ 90% parse + allowlist pass
Fallback success Offline still answers via local path
Zero key-in-logs Grep audit for key patterns = 0

8. “Do this first” shortlist (if you implement next)

  1. G0: Live Grok completion through existing _LLM_API + settings.
  2. grok rag command reusing Phase B semantic stack.
  3. Router default: Reasoning/Code → Grok when enabled.
  4. Lua + one agent script for Remote LLM Router.
  5. Architecture graph node + stack doctor line.


Living brainstorm — tick roadmap items as they land in code; keep model names synced with https://docs.x.ai/developers/models.

Generated from the project markdown docs on 2026-07-24. This is a static, self-contained site.