Skip to content

01Vishwa/Agentloop

Repository files navigation

Agentloop β€” DS-STAR Agent Platform

Intelligent Document Processing (IDP) & Deep Research Platform powered by the DS-STAR Agent Workflow. Agentloop autonomously interprets, plans, codes, executes, and verifies complex data operations β€” secured by Supabase JWT authentication.

React FastAPI Python Supabase LangChain


πŸ“– Overview

Agentloop is a multi-agent AI platform built for Intelligent Document Processing. By leveraging the DS-STAR Framework (Data Science - Self-Taught Agent with Reasoning), the platform dynamically analyzes datasets, generates Python code to process them, executes the code in a secure sandbox, and self-verifies the output against user constraints.

DS-STAR+ extends the core loop with a deep research mode that decomposes open-ended queries into parallel sub-questions, runs each as an independent DS-STAR agent, and synthesizes a comprehensive research report.


✨ Key Features

  • Autonomous Agent Loop: Plan β†’ Code β†’ Execute β†’ Verify β†’ Route.
  • Deep Research Mode (DS-STAR+): Decompose β†’ Parallelize β†’ Synthesize for open-ended queries.
  • Supabase JWT Authentication: Secure sign-up/sign-in; every API call is auth-gated.
  • Workspace Management: Organize runs and file uploads into user-owned workspaces with RLS-enforced isolation.
  • Secure Sandboxing: Executes AI-generated code in isolated subprocesses (Docker-ready, fully supports matplotlib data visualization).
  • Hardened Orchestration: Fully asynchronous, deadlock-free (asyncio.Lock) execution loop with dynamic schema metadata injection to prevent hallucination.
  • Real-Time Streaming: Live agent states and execution artifacts via Server-Sent Events (SSE).
  • Persistent Analytics: Run history, metrics, and observability via Supabase PostgreSQL.
  • Modern UI: Glassmorphism design on React 19 + Tailwind CSS; workspace selector, auth modal.

πŸ—οΈ System Architecture

flowchart TD
    classDef frontend fill:#3b82f6,stroke:#1d4ed8,stroke-width:2px,color:#fff
    classDef backend fill:#10b981,stroke:#047857,stroke-width:2px,color:#fff
    classDef ai_layer fill:#8b5cf6,stroke:#6d28d9,stroke-width:2px,color:#fff
    classDef storage fill:#f59e0b,stroke:#b45309,stroke-width:2px,color:#fff
    classDef sandbox fill:#64748b,stroke:#334155,stroke-width:2px,stroke-dasharray: 5 5,color:#fff
    classDef auth fill:#ef4444,stroke:#b91c1c,stroke-width:2px,color:#fff

    User((User))

    subgraph Frontend [React 19 Frontend]
        UI[User Interface & Hooks]:::frontend
        Auth[AuthContext + AuthModal]:::auth
        WS[WorkspaceSelector]:::frontend
    end

    subgraph Backend_FastAPI [FastAPI Backend]
        JWT[JWT Middleware]:::auth
        REST_API[REST & SSE Endpoints]:::backend
        Orchestrator[DS-STAR Orchestrator]:::backend

        subgraph Agent_Loop [AI Control Loop]
            FileAnalyzer[File Analyzer]:::ai_layer
            Planner[Planner]:::ai_layer
            Coder[Coder]:::ai_layer
            Verifier[Verifier]:::ai_layer
            Router[Router]:::ai_layer
        end

        Sandbox[[CodeExecutor Sandbox]]:::sandbox
    end

    subgraph Infrastructure [Data & LLM]
        Supabase[(Supabase Auth + DB)]:::storage
        LLM[NVIDIA NIM via LangChain]:::ai_layer
    end

    User --> Auth
    Auth --> Supabase
    User --> UI
    UI -->|REST & SSE + Bearer token| REST_API
    REST_API --> JWT
    JWT -->|Verified user_id| Orchestrator
    Orchestrator --> FileAnalyzer
    Orchestrator --> Planner
    Planner --> Coder
    Coder -.->|Executes Code| Sandbox
    Sandbox -.->|Stdout/Artifacts| Verifier
    Verifier -->|Evaluates| Router
    Router -->|Retry/Refine| Planner
    Agent_Loop <-->|Inference| LLM
    Orchestrator -->|Metrics & History| Supabase
    WS --> Supabase
Loading

πŸ’» Tech Stack

Layer Technology
Frontend React 19, Vite, Tailwind CSS, Lucide React
State / Auth Zustand, @supabase/supabase-js
Backend FastAPI, Python 3.10+, PyJWT, Tenacity, asyncio
AI / LLM LangChain, langchain-nvidia-ai-endpoints (NVIDIA NIM)
Execution Subprocess sandbox (Docker-ready, Data Science env equipped)
Database / Auth Supabase (PostgreSQL + Row-Level Security)

πŸ“ Project Structure

Agentloop/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ controllers/       # Business logic controllers
β”‚   β”‚   └── routes.py          # FastAPI router β€” thin endpoint declarations
β”‚   β”œβ”€β”€ core/                  # DS-STAR Orchestrator, Planner, Coder, Verifier…
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”œβ”€β”€ create_workspaces.sql              # Workspaces table + RLS
β”‚   β”‚   β”œβ”€β”€ create_uploaded_files.sql          # File metadata table + RLS
β”‚   β”‚   β”œβ”€β”€ add_workspace_to_uploaded_files.sql # File workspace scoping migration
β”‚   β”‚   β”œβ”€β”€ create_agent_runs.sql              # Agent runs table + RLS
β”‚   β”‚   β”œβ”€β”€ create_reports_schema.sql          # Reports + sub_questions tables + RLS
β”‚   β”‚   β”œβ”€β”€ create_eval_schema.sql             # Evaluation metrics schema
β”‚   β”‚   └── add_eval_metrics_fk.sql            # Add eval metrics foreign keys
β”‚   β”œβ”€β”€ eval/                  # Evaluation framework and metrics
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.py            # JWT dependency (get_current_user / get_optional_user)
β”‚   β”‚   └── error_handler.py   # Global exception handler
β”‚   β”œβ”€β”€ models/                # Pydantic request/response schemas
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── supabase_service.py  # Supabase client + all DB/Storage ops
β”‚   β”œβ”€β”€ tests/
β”‚   β”‚   β”œβ”€β”€ test_auth_middleware.py    # Unit tests for JWT auth
β”‚   β”‚   β”œβ”€β”€ test_code_executor.py
β”‚   β”‚   β”œβ”€β”€ test_orchestrator_integration.py
β”‚   β”‚   β”œβ”€β”€ test_router_agent.py
β”‚   β”‚   └── test_verifier_agent.py
β”‚   β”œβ”€β”€ main.py                # FastAPI entry point
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ .env                   # Local secrets (git-ignored)
β”‚   └── .env.example           # Template β€” copy to .env
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ agent/             # AgentProgressPanel, HistoryPanel, AgentSettings
β”‚   β”‚   β”œβ”€β”€ shared/
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthModal.jsx        # Login / Sign-Up modal
β”‚   β”‚   β”‚   β”œβ”€β”€ WorkspaceSelector.jsx # Workspace dropdown
β”‚   β”‚   β”‚   β”œβ”€β”€ ConfirmDialog.jsx
β”‚   β”‚   β”‚   └── Toast.jsx
β”‚   β”‚   └── upload/
β”‚   β”‚       └── FileUploadPanel.jsx  # Drag-drop zone with WorkspaceSelector
β”‚   β”œβ”€β”€ contexts/
β”‚   β”‚   └── AuthContext.jsx    # AuthProvider + useAuth() hook
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”œβ”€β”€ useAgentRun.js     # DS-STAR live run state + history
β”‚   β”‚   └── useFileUpload.js   # File lifecycle: add, upload, process, clear
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   └── supabaseClient.js  # Singleton Supabase browser client
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ HomePage.jsx       # Main layout: Upload | Query | Agent output
β”‚   β”‚   └── EvalDashboard.jsx  # Evaluation metrics dashboard
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ api.js             # REST API calls (upload, process, clear) + auth headers
β”‚   β”‚   └── agentApi.js        # SSE streaming client + auth header
β”‚   β”œβ”€β”€ stores/
β”‚   β”‚   └── workspaceStore.js  # Zustand store for active workspace
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── index.js           # JSDoc typedefs (User, Session, Workspace, AgentRun…)
β”‚   β”œβ”€β”€ App.jsx                # Root: AuthProvider + Router
β”‚   └── main.jsx               # React DOM entry
β”œβ”€β”€ public/                    # Static assets
β”œβ”€β”€ .env                       # Frontend env vars (VITE_SUPABASE_*)
β”œβ”€β”€ .env.example               # Frontend env template
β”œβ”€β”€ vite.config.js             # Dev server + /api proxy β†’ localhost:8000
β”œβ”€β”€ package.json               # Node dependencies
└── docs/                      # Agent architecture documentation

πŸ” Authentication & Security

Agentloop uses Supabase JWT authentication end-to-end:

  1. Frontend: @supabase/supabase-js manages sign-in/sign-up, token refresh, and session persistence.
  2. API calls: Every request stamped with Authorization: Bearer <access_token> via authHeader() helpers in api.js and agentApi.js.
  3. Backend: get_current_user FastAPI dependency decodes and verifies the JWT using PyJWT + SUPABASE_JWT_SECRET. Returns AuthUser(user_id, email, role).
  4. Database: Supabase Row-Level Security policies enforce auth.uid() = user_id β€” users can only access their own rows.

Protected endpoints

Method Path Auth
POST /api/upload Optional (anonymous uploads allowed)
POST /api/process Optional
POST /api/agent/run Optional (user_id stamped when present)
GET /api/agent/runs Optional (scoped to user when authenticated)
GET /api/agent/runs/{id} Optional
GET /api/workspaces Required
POST /api/workspaces Required

πŸ€– Agent Workflow

Agentloop relies on the DS-STAR Orchestrator pattern:

  1. File Analyzer: Normalizes incoming unstructured data into context schemas.
  2. Retriever: Filters large documents using local sentence-transformers.
  3. Planner: Transforms user intent into a mutable multi-step plan.
  4. Coder: Translates each plan step into self-contained Python code.
  5. Code Executor: Runs generated code in an isolated sandbox.
  6. Debugger: Surgically corrects failing code blocks.
  7. Verifier & Router: Evaluate output and re-route for retries.
  8. Finalizer: Converts execution output into clean Markdown insights.

DS-STAR+ extends with:


πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Python 3.10+
  • Supabase project (free tier works)
  • NVIDIA NIM API key

1. Clone & configure

git clone <repo-url>
cd Agentloop

2. Supabase setup

  1. Create a project at supabase.com.
  2. Open the SQL Editor and run these migration files in order:
    backend/db/create_workspaces.sql
    backend/db/create_uploaded_files.sql
    backend/db/add_workspace_to_uploaded_files.sql
    backend/db/create_agent_runs.sql
    backend/db/create_reports_schema.sql
    backend/db/create_eval_schema.sql
    backend/db/add_eval_metrics_fk.sql
    
  3. From Settings β†’ API, collect:
    • Project URL β†’ SUPABASE_URL / VITE_SUPABASE_URL
    • anon public key β†’ VITE_SUPABASE_ANON_KEY
    • service_role or anon key β†’ SUPABASE_PUBLISHABLE_KEY
    • JWT Secret (Settings β†’ API β†’ JWT Settings) β†’ SUPABASE_JWT_SECRET

3. Backend setup

cd backend
python -m venv venv
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

pip install -r requirements.txt

# Copy template and fill in your keys
cp .env.example .env
# Edit .env: set SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, SUPABASE_JWT_SECRET, NVIDIA_API_KEY

uvicorn main:app --reload
# API running at http://localhost:8000

4. Frontend setup

# From project root
cp .env.example .env       # if .env doesn't exist
# Edit .env: set VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY

npm install
npm run dev
# App running at http://localhost:5173

Note: The Vite dev server proxies /api/* β†’ http://localhost:8000 automatically β€” no CORS configuration needed during development.

5. Run backend tests

cd backend
python -m pytest tests/ -v

πŸ”Œ API Reference

Method Path Auth Description
POST /api/upload Optional Upload files to session-scoped cache
POST /api/process Optional Build in-memory document context
POST /api/agent/run Optional Start DS-STAR agent run (SSE stream)
GET /api/agent/runs Optional List past runs (scoped to user)
GET /api/agent/runs/{id} Optional Get a single run by ID
GET /api/workspaces Required List authenticated user's workspaces
POST /api/workspaces Required Create a new workspace
DELETE /api/clear Optional Wipe session file cache
GET /api/eval/* Public Evaluation metrics endpoints

🀝 Contributing

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'feat: add amazing feature'
  4. Push: git push origin feature/amazing-feature
  5. Open a Pull Request.

πŸ“„ License

MIT License β€” see LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors