TraceAI is a framework-free, autonomous AI agent system that implements the ReAct (Reason + Act) paradigm from scratch. It features strict output parsing, multi-step tool execution, and complete execution trace visibility via a Next.js frontend, providing a transparent, controllable, and debuggable AI experience.
- Framework-Free: Built without black-box agent frameworks (like LangChain or AutoGen) to ensure complete understanding and control over the agent loop.
- Strict Output Parsing: Uses rigid schema validation to prevent LLM hallucinations and parse reasoning traces robustly.
- Multiple Tools: Includes basic tools (Calculator, Wikipedia) and advanced tools (Web Search, In-depth Research) for multifaceted agent capabilities.
- Full Observability: The Next.js frontend provides a real-time, step-by-step reasoning trace (Thought ➔ Action ➔ Input ➔ Observation).
- Error Resiliency: Auto-retries on format errors or tool failures, with safety constraints (
max_steps, safe AST evaluation).
flowchart TD
A[User Input] --> B[Next.js Frontend]
B --> C[FastAPI Backend /chat]
C --> D[Agent Controller Loop]
subgraph Agent Loop
D --> E[Prompt + History]
E --> F[LLM Client Gemini]
F --> G{Output Parser}
G -- Invalid --> H[Retry with Error Correction]
H --> E
G -- Valid Action --> I[Tool Executor]
I --> J[Observation]
J --> E
G -- Final Answer --> K[Return Final Output]
end
K --> L[UI Trace Renderer]
- Frontend (Next.js & React): Provides a conversational UI to visualize the real-time reasoning trace of the agent, rendering complex intermediate steps cleanly.
- Backend API (FastAPI): Exposes streaming and synchronous REST endpoints for chat interaction and tool listing.
- Agent Loop (
agent/loop.py): The orchestrator. Manages state, bounds maximum steps and retries, appends history, and passes data to the LLM. - Output Parser (
agent/parser.py): Strictly regex-extracts and validatesThought,Action,Action Inputfrom the LLM to ensure structural integrity. - Tool Registry (
tools/): Safely maps LLM-requested actions to underlying Python functions (e.g., usingastparsing for safe math calculation).
- Node.js 18+
- Python 3.9+
- Navigate to the backend directory:
cd backend - Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create a
.envfile in thebackendfolder and add your Gemini API Key:GEMINI_API_KEY=your_google_gemini_api_key_here
- Run the server:
python main.py # Or using uvicorn: uvicorn main:app --reload
- Navigate to the frontend directory:
cd frontend - Install dependencies:
npm install
- Create a
.env.localfile (optional, defaults to localhost:8000):NEXT_PUBLIC_API_URL=http://localhost:8000
- Start the dev server:
npm run dev
Built for transparency, designed for production.