ShawnIL/GAIA_Agent_Evaluation
0
yy
๐ค GAIA Agent - Advanced Q&A Chatbot
A sophisticated AI Agent powered by LangGraph, LangChain, and Groq LLM with RAG capabilities, 21+ integrated tools, and comprehensive observability through Langfuse.
๐ Overview
GAIA Agent is a production-ready AI chatbot that combines:
- ๐ง Advanced Reasoning: Groq qwen3-32b LLM with tool-calling
- ๐ RAG (Retrieval-Augmented Generation): Supabase vector DB for contextual knowledge
- ๐ ๏ธ 21+ Tools: Web search, code execution, file processing, image analysis
- ๐จ Modern UI: Gradio 6.0 interface with file upload support
- ๐ Observability: Langfuse integration for LLM monitoring
- โก Fast: RPC-based Supabase retrieval for speed
๐ Key Features
Core Capabilities
- ๐ Multi-Source Search: Tavily web search, Wikipedia, arXiv papers
- ๐ป Code Execution: Python, Bash, SQL, C, Java with sandboxed execution
- ๐ผ๏ธ Image Processing: OCR, analysis, transformations, generation
- ๐ Document Intelligence: PDF, CSV, Excel analysis with pandas
- ๐งฎ Mathematical Tools: Complete math operations suite
- ๐ File Upload: Drag-and-drop support for multiple file types
Technical Stack
- LLM: Groq (qwen3-32b) for fast inference
- Orchestration: LangGraph StateGraph for agent workflow
- Vector DB: Supabase with custom RPC for similarity search
- Embeddings: HuggingFace sentence-transformers (768-dim)
- UI: Gradio 6.0 with custom CSS and message format
- Monitoring: Langfuse for LLM tracing and observability
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GAIA Agent Flow โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ User Question โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโ โ
โ โ Retriever โ โ Supabase RPC (match_documents_2) โ
โ โ Node โ Semantic search for similar Q&A โ
โ โโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโ โ
โ โ Assistant โ โ Groq qwen3-32b + 21 tools bound โ
โ โ Node โ Langfuse callback for tracing โ
โ โโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโ Tool Calls? โโโ โ
โ โ โ โ
โ โผ โผ โ
โ Response โโโโโโโโโโโโโโโ โ
โ โ Tools โ โ
โ โ Node โ โ
โ โโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโ Back to Assistant โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๐ฆ Project Structure
AI_Agents_Tutorial/
โโโ app.py # Main Gradio Q&A interface (Gradio 6.0)
โโโ evaluation_app.py # GAIA benchmark evaluation runner
โโโ agent.py # Core agent: LangGraph + tools + RAG
โโโ code_interpreter.py # Multi-language code execution
โโโ image_processing.py # Image processing utilities
โโโ system_prompt.txt # System instructions for LLM
โโโ requirements.txt # Python dependencies
โโโ .env # Environment variables (NOT in git)
โโโ metadata.jsonl # GAIA benchmark metadata
โโโ ARCHITECTURE.md # System architecture documentation
โโโ DATA_FLOW.md # Data flow diagrams
โโโ DEVELOPMENT_GUIDE.md # Comprehensive development guide
โโโ README.md # This file๐ ๏ธ Complete Tool Inventory (21 Tools)
๐ Search & Research (3 tools)
- web_search: Tavily-powered real-time web search
- wiki_search: Wikipedia article retrieval
- arxiv_search: Academic paper search
๐ป Code Execution (5 tools)
- execute_code_multilang: Python, Bash, SQL, C, Java execution
- add: Addition operation
- subtract: Subtraction operation
- multiply: Multiplication operation
- divide: Division with zero-check
๐ File & Data Processing (6 tools)
- save_file: Write content to file
- read_file: Read file content
- download_file: Download from URL
- analyze_csv: Pandas-based CSV analysis
- analyze_excel: Excel file processing
- extract_text_from_pdf: PDF text extraction
๐ผ๏ธ Image Processing (7 tools)
- analyze_image: Size, format, color analysis
- resize_image: Image resizing
- rotate_image: Rotation transformation
- crop_image: Image cropping
- flip_image: Horizontal/vertical flip
- adjust_brightness: Brightness control
- extract_text_from_image: OCR with Tesseract
๐ฏ Usage Examples
Example 1: Simple Question
User: "What is the capital of France?"
Agent: Uses RAG retriever โ Finds similar Q&A โ Returns "Paris"Example 2: Web Search
User: "What's the current Bitcoin price?"
Agent: Detects need for real-time data โ Calls web_search tool โ Returns latest priceExample 3: Code Execution
User: "Calculate fibonacci sequence up to 10"
Agent: Generates Python code โ Executes via execute_code_multilang โ Returns [0,1,1,2,3,5,8,13,21,34]Example 4: File Analysis
User: [Uploads sales.csv] "What are the top 3 products?"
Agent: Calls analyze_csv โ Pandas analysis โ Returns top products with sales figuresExample 5: Image OCR
User: [Uploads screenshot] "Extract the text from this image"
Agent: Calls extract_text_from_image โ Tesseract OCR โ Returns extracted text๐ง Technical Details
LangGraph Implementation
# Graph structure (agent.py)
builder = StateGraph(MessagesState)
builder.add_node("retriever", retriever_node) # RAG search
builder.add_node("assistant", assistant_node) # LLM + tools
builder.add_node("tools", ToolNode(tools)) # Tool execution
builder.add_edge(START, "retriever")
builder.add_edge("retriever", "assistant")
builder.add_conditional_edges("assistant", tools_condition)
builder.add_edge("tools", "assistant")RAG with Supabase RPC
# Custom RPC-based retriever (avoids supabase-py version issues)
def supabase_similarity_search(query: str, k: int = 3):
embedding = embeddings.embed_query(query)
result = supabase.rpc("match_documents_2", {
"query_embedding": embedding,
"match_count": k
}).execute()
return result.dataLangfuse Observability
# Optional callback for LLM tracing
lf_handler = get_langfuse_handler() # Reads from .env
llm = ChatGroq(model="qwen/qwen3-32b", callbacks=[lf_handler])
result = graph.invoke({"messages": messages}, config={"callbacks": [lf_handler]})๐จ Troubleshooting
Common Issues
1. Port already in use
# Kill process on port 7860
lsof -ti:7860 | xargs kill -92. Supabase connection error
# Check environment variables
echo $SUPABASE_URL
echo $SUPABASE_SERVICE_ROLE_KEY
# Test connection
python -c "from supabase import create_client; import os; client = create_client(os.getenv('SUPABASE_URL'), os.getenv('SUPABASE_SERVICE_ROLE_KEY')); print('Connected!')"3. Gradio version mismatch
# Ensure Gradio 4.x (not 6.x for compatibility)
pip install "gradio>=4.0.0,<5.0.0"4. Missing dependencies
# Install all requirements
pip install -r requirements.txt
# Install system dependencies (macOS)
brew install tesseract # For OCR๐ Performance Metrics
๐ Resources & Documentation
- [ARCHITECTURE.md](ARCHITECTURE.md): System architecture deep-dive
- [DATA_FLOW.md](DATA_FLOW.md): Data flow diagrams and explanations
- [DEVELOPMENT_GUIDE.md](DEVELOPMENT_GUIDE.md): Complete development guide
- [LangGraph Docs](https://langchain-ai.github.io/langgraph/): Official documentation
- [Groq](https://groq.com/): Fast LLM inference
- [Supabase](https://supabase.com/): Vector database
- [Langfuse](https://langfuse.com/): LLM observability
๐ค Contributing
Contributions are welcome! Areas for improvement:
- โจ New specialized tools
- ๐จ UI/UX enhancements
- โก Performance optimizations
- ๐ Documentation expansion
- ๐งช Test coverage
๐ License
MIT License - See LICENSE file for details.
๐ Acknowledgments
Built with:
- LangChain & LangGraph for agent orchestration
- Groq for blazing-fast LLM inference
- Supabase for vector database
- Gradio for beautiful UI
- Hugging Face for embeddings and hosting
Last Updated: January 2026 Version: 1.0.0
โ๏ธ Installation & Setup
Prerequisites
- Python 3.11+
- Conda (recommended) or venv
- API Keys: Groq, Tavily, Supabase, Langfuse (optional)
1. Clone Repository
git clone <your-repo-url>
cd AI_Agents_Tutorial2. Create Conda Environment
# Create environment
conda create -p ./.conda python=3.11 -y
conda activate ./.conda
# Install dependencies
pip install -r requirements.txt3. Environment Variables
Create .env file in project root:
# LLM Provider
GROQ_API_KEY=gsk_your_groq_api_key
# Search API
TAVILY_API_KEY=tvly-your_tavily_key
# Vector Database
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=eyJhbG...your_key
# Observability (Optional)
LANGFUSE_HOST=https://cloud.langfuse.com
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...4. Supabase Database Setup
Execute this SQL in your Supabase SQL Editor:
-- Enable pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Create documents table (if not exists)
CREATE TABLE IF NOT EXISTS public.documents2 (
id BIGSERIAL PRIMARY KEY,
content TEXT,
metadata JSONB,
embedding VECTOR(768)
);
-- Create RPC function for similarity search
CREATE OR REPLACE FUNCTION public.match_documents_2(
query_embedding VECTOR(768),
match_count INT DEFAULT 3
)
RETURNS TABLE(
id BIGINT,
content TEXT,
metadata JSONB,
similarity FLOAT
)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT
documents2.id,
documents2.content,
documents2.metadata,
1 - (documents2.embedding <=> query_embedding) AS similarity
FROM public.documents2
ORDER BY documents2.embedding <=> query_embedding
LIMIT match_count;
END;
$$;
-- Create index for faster searches
CREATE INDEX IF NOT EXISTS documents2_embedding_idx
ON public.documents2
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
-- Grant permissions
GRANT EXECUTE ON FUNCTION public.match_documents_2(VECTOR, INT)
TO anon, authenticated, service_role;๐ Running the Application
Main Q&A Chatbot Interface
# Activate environment
conda activate ./.conda
# Run the app
python app.pyAccess at: http://localhost:7860
Features:
- ๐ฌ Natural language Q&A
- ๐ Drag-and-drop file upload (images, CSV, PDF, etc.)
- ๐ Real-time web search
- ๐ป Code execution with results
- ๐ Data analysis and visualization
- ๐งน Clear history and export chat
Evaluation Runner (GAIA Benchmark)
python evaluation_app.pyWorkflow:
- Login with Hugging Face account
- Click "Run Evaluation & Submit All Answers"
- Agent processes all GAIA benchmark questions
- Automatic submission and scoring
๐ฏ Usage Examples
Example 1: Simple Question
User: "What is the capital of France?"
Agent: Uses RAG retriever โ Finds similar Q&A โ Returns "Paris"Example 2: Web Search
User: "What's the current Bitcoin price?"
Agent: Detects need for real-time data โ Calls web_search tool โ Returns latest priceExample 3: Code Execution
User: "Calculate fibonacci sequence up to 10"
Agent: Generates Python code โ Executes via execute_code_multilang โ Returns [0,1,1,2,3,5,8,13,21,34]Example 4: File Analysis
User: [Uploads sales.csv] "What are the top 3 products?"
Agent: Calls analyze_csv โ Pandas analysis โ Returns top products with sales figuresExample 5: Image OCR
User: [Uploads screenshot] "Extract the text from this image"
Agent: Calls extract_text_from_image โ Tesseract OCR โ Returns extracted textCheck out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
