CoolFace
Apppublic

ShawnIL/GAIA_Agent_Evaluation

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

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)

  1. 1.web_search: Tavily-powered real-time web search
  2. 2.wiki_search: Wikipedia article retrieval
  3. 3.arxiv_search: Academic paper search

๐Ÿ’ป Code Execution (5 tools)

  1. 1.execute_code_multilang: Python, Bash, SQL, C, Java execution
  2. 2.add: Addition operation
  3. 3.subtract: Subtraction operation
  4. 4.multiply: Multiplication operation
  5. 5.divide: Division with zero-check

๐Ÿ“„ File & Data Processing (6 tools)

  1. 1.save_file: Write content to file
  2. 2.read_file: Read file content
  3. 3.download_file: Download from URL
  4. 4.analyze_csv: Pandas-based CSV analysis
  5. 5.analyze_excel: Excel file processing
  6. 6.extract_text_from_pdf: PDF text extraction

๐Ÿ–ผ๏ธ Image Processing (7 tools)

  1. 1.analyze_image: Size, format, color analysis
  2. 2.resize_image: Image resizing
  3. 3.rotate_image: Rotation transformation
  4. 4.crop_image: Image cropping
  5. 5.flip_image: Horizontal/vertical flip
  6. 6.adjust_brightness: Brightness control
  7. 7.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 price

Example 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 figures

Example 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

python
# 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

python
# 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.data

Langfuse Observability

python
# 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

bash
# Kill process on port 7860
lsof -ti:7860 | xargs kill -9

2. Supabase connection error

bash
# 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

bash
# Ensure Gradio 4.x (not 6.x for compatibility)
pip install "gradio>=4.0.0,<5.0.0"

4. Missing dependencies

bash
# Install all requirements
pip install -r requirements.txt

# Install system dependencies (macOS)
brew install tesseract  # For OCR

๐Ÿ“Š Performance Metrics

MetricValue
LLM Latency~1-2s (Groq inference)
RAG Search~200ms (Supabase RPC)
Tool ExecutionVariable (depends on tool)
Total Response2-5s average
Tools Available21
Supported Languages5 (Python, Bash, SQL, C, Java)
File Types15+ formats

๐Ÿ”— 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

bash
git clone <your-repo-url>
cd AI_Agents_Tutorial

2. Create Conda Environment

bash
# Create environment
conda create -p ./.conda python=3.11 -y
conda activate ./.conda

# Install dependencies
pip install -r requirements.txt

3. Environment Variables

Create .env file in project root:

env
# 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:

sql
-- 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

bash
# Activate environment
conda activate ./.conda

# Run the app
python app.py

Access 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)

bash
python evaluation_app.py

Workflow:

  1. 1.Login with Hugging Face account
  2. 2.Click "Run Evaluation & Submit All Answers"
  3. 3.Agent processes all GAIA benchmark questions
  4. 4.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 price

Example 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 figures

Example 5: Image OCR

User: [Uploads screenshot] "Extract the text from this image"
Agent: Calls extract_text_from_image โ†’ Tesseract OCR โ†’ Returns extracted text

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference