CoolFace
Apppublic

sharmanikhiljiit/Agentic_Research_Evaluator

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

Enhanced Research Paper Analysis Agent with Evaluator Node

A hallucination-preventing research assistant built with LangGraph, following the Sidekick pattern from lab4.ipynb. This enhanced version adds an evaluator node that validates every response against the source PDF content.

๐Ÿง  What's New: Hallucination Prevention

Unlike the original single-node agent, this version includes:

  • โ€”Evaluator Node: Validates responses for accuracy and grounding
  • โ€”Iterative Refinement: Failed evaluations trigger response improvement
  • โ€”PDF Content Validation: Ensures answers are based solely on provided documents
  • โ€”Structured Feedback: Pydantic models provide consistent evaluation criteria

๐Ÿ—๏ธ Architecture: Sidekick Pattern

Following the exact same pattern from LangGraph lab4.ipynb:

START โ†’ Researcher โ†’ (Tools OR Evaluator) โ†’ (Continue OR END)
                     โ†“
                Tool Results
                     โ†“
               Back to Researcher
                     โ†“
                 Evaluator
                 โ†™        โ†˜
          Continue? โ†’ YES    NO โ†’ Back to Researcher
               โ†“             โ†“
              END     Iterative Improvement

Key Components

Researcher Node
  • โ€”Analyzes PDF content with tool integration
  • โ€”Receives feedback from evaluator for improvement
  • โ€”Processes both small and large documents with chunking
Evaluator Node
  • โ€”Pydantic Structured Output: Consistent evaluation schema
  • โ€”PDF Content Validation: Checks grounding against source material
  • โ€”Hallucination Detection: Identifies unverified information
  • โ€”Feedback Generation: Provides specific improvement suggestions
State Management
python
class State(TypedDict):
    messages: Annotated[List[Any], add_messages]
    pdf_content: str
    question: str
    user_registered: bool
    # NEW: Evaluator fields
    success_criteria: str
    feedback_on_work: Optional[str]
    success_criteria_met: bool
    user_input_needed: bool

๐Ÿš€ Quick Start

1. Setup Environment

bash
cd /Users/nikk/Desktop/projects/Agentic_Research_Evaluator
python run_evaluator_agent.py

The launcher automatically:

  • โ€”Creates a .venv virtual environment
  • โ€”Installs all dependencies
  • โ€”Starts the web interface

2. Set Environment Variables

bash
cp env_example .env
# Edit .env with your OpenAI API key

3. Run the Agent

bash
# Web interface (recommended)
python run_evaluator_agent.py

# CLI mode
python main.py path/to/paper.pdf "What is the main contribution?"

๐Ÿ” How the Evaluator Works

Evaluation Criteria

  1. 1.Accuracy: Information matches PDF content exactly
  2. 2.Grounding: No external knowledge or assumptions
  3. 3.Relevance: Directly answers the question asked
  4. 4.Completeness: Addresses question based on available content
  5. 5.Limitations: Acknowledges when paper lacks information

Super-Step Process

User Question โ†’ Research Analysis โ†’ Evaluator Validation
                                           โ†“
                                    Criteria Met?
                                 โ†™           โ†˜
                            YES โ†’ END    NO โ†’ Feedback to Researcher
                                 โ†“              โ†“
                            Final Answer    Improved Analysis โ†’ Evaluator...

๐Ÿ“‹ Example Scenarios

โœ… Accurate Response (Evaluator Approves)

Question: "What datasets were used?"
PDF Content: "We evaluated on ImageNet, CIFAR-10, and MNIST datasets..."
Response: "The paper evaluates on ImageNet, CIFAR-10, and MNIST datasets."
โ†’ โœ… Success criteria met, response grounded in PDF

โŒ Hallucination Detected (Evaluator Rejects)

Question: "How does this compare to BERT?"
PDF Content: "Our method achieves 85% accuracy..." (no BERT mention)
Response: "This approach outperforms BERT by 10%..."
โ†’ โŒ Hallucination detected, sent back for correction

๐Ÿ› ๏ธ Technical Details

Dependencies Added

pydantic>=2.0.0  # For structured evaluator output

Router Functions

  • โ€”research_router(): Routes after research (tools vs evaluator)
  • โ€”evaluation_router(): Routes after evaluation (continue vs end)

Checkpointing

  • โ€”SQLite-based conversation persistence
  • โ€”Maintains evaluation history across sessions

๐Ÿงช Testing & Debugging

Debug Evaluation Execution

Inspect the evaluator node step-by-step to see exactly how it works:

bash
python debug_evaluator.py <pdf_path> <question>
# Example
python debug_evaluator.py research_paper.pdf "What is the main contribution?"

This shows:

  • โ€”Research node response generation
  • โ€”Router decision (tools vs evaluator)
  • โ€”Detailed evaluation feedback
  • โ€”Success criteria assessment
  • โ€”Final routing decision

Test Hallucination Detection

Run without arguments to see test cases for different prompt types:

bash
python debug_evaluator.py

Web Interface Testing

Use the full Gradio interface to see evaluation in action:

bash
python run_evaluator_agent.py

Look for ๐Ÿ” evaluation messages in the chat after asking questions.

๐Ÿ”ง Development

Virtual Environment

The launcher script automatically manages the .venv environment:

  • โ€”Creates virtual environment if needed
  • โ€”Installs/updates dependencies
  • โ€”Activates environment for debugging

Debugging Tips

  • โ€”Check evaluation feedback in logs
  • โ€”Monitor success_criteria_met flag
  • โ€”Review feedback_on_work for improvement suggestions

๐Ÿ“Š Benefits Over Original Agent

FeatureOriginal AgentEnhanced with Evaluator
Hallucination PreventionโŒ Noneโœ… Built-in validation
Response Accuracyโš ๏ธ Variableโœ… Guaranteed grounding
Iterative ImprovementโŒ Single shotโœ… Feedback loop
PDF Content ValidationโŒ Noneโœ… Every response checked
Structured EvaluationโŒ Noneโœ… Pydantic schemas

๐ŸŽฏ Use Cases

  • โ€”Research Analysis: Ensure accurate paper summaries
  • โ€”Literature Review: Prevent cross-contamination between papers
  • โ€”Academic Q&A: Maintain source fidelity
  • โ€”Document Analysis: Validate against specific content

Built following LangGraph Sidekick pattern for maximum reliability and accuracy.