RAG Math Routing Agent — Interactive Playground

Simulated demo of the RAG Math Routing Agent pipeline. Enter a math question, watch the routing and retrieval steps, and see a generated solution (simulation).

Try it — Simulation

Simulation (client-side)

Result

Run the simulation to see the answer here.

Architecture & Code Explanation

System Architecture

High-level components: API Gateway, Math Router, Knowledge Base, Web Search (MCP), DSPy reasoning engine, Feedback system.

RAG Math Routing Architecture

Unified System and Data Flow Architecture

Project Structure

math-routing-agent/
├─ math_agent/
│  ├─ core.py          # orchestrates request -> routing -> solution
│  ├─ routing_agent.py # routing & decision logic (KB vs Web vs DSPy)
│  ├─ knowledge_base.py# FAISS embeddings & retrieval
│  ├─ web_search.py    # MCP + web search adaptors
│  └─ feedback_system.py # feedback storage & KB updater

Code-by-code (Selected snippets)

Routing decision (high-level)
def route_request(query):
    # 1) check knowledge base similarity threshold
    hits = kb.search(query, k=5)
    if hits and hits[0].score > 0.8:
        return 'knowledge', hits[0]
    # 2) otherwise call web search (MCP) and DSPy reasoning
    results = web_search.fetch(query)
    return 'web', results
Exported attention / reasoning flow (DSPy)
def generate_solution(query, context):
    # Build prompt with retrieved context and call LLM orchestrator
    prompt = build_prompt(query, context)
    answer = llm_orchestrator.call(prompt)
    return answer
Feedback ingestion (simplified)
def ingest_feedback(solution_id, rating, corrected_solution=None):
    db.insert_feedback(solution_id, rating, corrected_solution)
    if rating >= 4 and corrected_solution:
        kb.upsert(corrected_solution)

How the simulation works

  1. Query parsing & intent detection
  2. Knowledge Base lookup (FAISS)
  3. Routing decision (KB / Web / DSPy)
  4. Context assembly and LLM reasoning
  5. Return structured solution + sources