CoolFace
Apppublic

snehagupt/news_investigation_agent

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

title: Fake News Investigation Agent emoji: ๐Ÿ“ฐ colorFrom: blue colorTo: purple sdk: docker app_file: app.py pinned: false ---

Fake News Investigation Agent - OpenEnv Environment

Overview

This is a complete, production-ready OpenEnv-compliant environment for training and evaluating AI agents on fake news detection through multi-step investigation.

Unlike simple ML classifiers, this environment simulates a real-world investigative process where agents must:

  • โ€”Analyze article text for red flags
  • โ€”Check source credibility
  • โ€”Detect bias and one-sided reporting
  • โ€”Verify key claims
  • โ€”Make informed final decisions

The environment includes sophisticated reward shaping, state management, and deterministic grading to evaluate agent performance across multiple dimensions.


Key Features

โœ… Multi-Step Reasoning - Agents must investigate before deciding (not a simple classifier) โœ… Sophisticated Reward Shaping - Incentivizes thorough investigation with correct conclusions โœ… Dynamic State Management - State evolves based on agent actions โœ… Deterministic Grading - Objective evaluation based on correctness, efficiency, and action quality โœ… 3 Difficulty Levels - Easy, medium, and hard investigation tasks โœ… Type-Safe Design - Full Pydantic model validation โœ… OpenEnv Compliant - Follows industry standards for environments โœ… Baseline Agent Included - Demonstrates interaction with environment โœ… Docker Support - Easy containerization and deployment


Environment Architecture

Core Components

openenv_env/
โ”œโ”€โ”€ env.py              # Main environment class (FakeNewsInvestigationEnv)
โ”œโ”€โ”€ state.py            # Pydantic models for state/action/reward
โ”œโ”€โ”€ actions.py          # Action processing and heuristic analysis
โ”œโ”€โ”€ tasks/
โ”‚   โ””โ”€โ”€ __init__.py     # Task definitions (3 difficulty levels)
โ”œโ”€โ”€ graders/
โ”‚   โ””โ”€โ”€ __init__.py     # Deterministic grading system
โ””โ”€โ”€ baseline_agent.py   # Example agent implementation

State Space

The agent observes:

python
{
    "text": str,                  # News article content
    "source": str,                # Publication/source name
    "analysis_done": bool,        # Text analysis completed?
    "source_checked": bool,       # Source credibility checked?
    "bias_checked": bool,         # Bias detection completed?
    "claims_verified": bool,      # Claims verification completed?
    "steps_taken": int,           # Number of steps taken
    "max_steps": int,             # Maximum allowed steps
    "final_answer": str|None,     # REAL, FAKE, or None
    "action_history": list,       # History of actions
    "internal_evidence": dict     # Evidence gathered
}

Action Space

Six discrete actions available:

ActionDescriptionBase Reward
analyze_textAnalyze text for misinformation patterns+0.10
check_sourceCheck source credibility+0.15
detect_biasDetect bias and one-sided reporting+0.12
verify_claimVerify key claims in article+0.12
final_realFinal decision: Article is REALยฑ0.50
final_fakeFinal decision: Article is FAKEยฑ0.50

Reward System

Key Design Principles:

  • โ€”Base rewards for investigation actions (+0.10 to +0.15)
  • โ€”Bonuses for finding meaningful evidence
  • โ€”Heavy rewards for CORRECT final answers (+0.50)
  • โ€”Heavy penalties for WRONG final answers (-0.50)
  • โ€”Penalties for repetition (-0.10) and inefficiency (-0.05/step)
  • โ€”All rewards normalized to [0.0, 1.0]

Reward Shaping Strategy:

  1. 1.Investigation actions provide consistent positive rewards
  2. 2.Repeated actions are penalized
  3. 3.Final answers dominate overall reward
  4. 4.Efficiency bonus for fewer steps
  5. 5.Thoroughness bonus for using multiple investigation methods

Grading System

Episodes are graded on 4 dimensions:

1. Correctness (Weight: 70%)

  • โ€”1.0 if final answer matches ground truth
  • โ€”0.0 if incorrect
  • โ€”This is the primary metric

2. Efficiency (Weight: 10%)

  • โ€”Based on steps taken vs. optimal (3-4 steps)
  • โ€”Formula: 1.0 - ((steps - optimal) / max_steps)
  • โ€”Rewards faster conclusions

3. Action Quality (Weight: 10%)

  • โ€”Rewards diverse, meaningful actions
  • โ€”Penalizes repetition
  • โ€”Bonus for using all 4 investigation methods

4. Thoroughness (Weight: 10%)

  • โ€”Percentage of investigation methods used
  • โ€”Encourages multiple analysis angles
  • โ€”Ensures multi-step reasoning

Final Score Formula:

if correct:
    score = 0.5 ร— correctness + 0.2 ร— efficiency + 0.15 ร— quality + 0.15 ร— thoroughness
else:
    score = 0.7 ร— correctness + 0.1 ร— efficiency + 0.1 ร— quality + 0.1 ร— thoroughness

Final Score โˆˆ [0.0, 1.0]

Tasks (3 Difficulty Levels)

Easy Tasks

Example: Obvious Fake with Multiple Red Flags

  • โ€”ALL CAPS text
  • โ€”Anonymous sources
  • โ€”Conspiracy claims
  • โ€”No evidence
  • โ€”Ground Truth: FAKE

Medium Tasks

Example: Misleading Headlines

  • โ€”Correlation presented as causation
  • โ€”Small sample sizes
  • โ€”Out-of-context truths
  • โ€”Technically truthful but misleading
  • โ€”Ground Truth: FAKE

Hard Tasks

Example: Realistic Unverified Claims

  • โ€”Plausible technology announcements
  • โ€”Unverified claims
  • โ€”Expert skepticism
  • โ€”No independent verification yet
  • โ€”Realistic reporting
  • โ€”Ground Truth: REAL

Quick Start

Installation

bash
# Clone repository
cd investigation_agent

# Install dependencies
pip install -r requirements.txt

Basic Usage

python
from openenv_env.env import FakeNewsInvestigationEnv
from openenv_env.state import Action, ActionType

# Create environment
env = FakeNewsInvestigationEnv(max_steps=10)

# Reset with a task
state = env.reset(task_id="easy_001")

# Take an action
action = Action(action_type=ActionType.ANALYZE_TEXT)
state, reward, done, info = env.step(action)

# Continue investigation...
action = Action(action_type=ActionType.CHECK_SOURCE)
state, reward, done, info = env.step(action)

# Make final decision
action = Action(action_type=ActionType.FINAL_FAKE)
state, reward, done, info = env.step(action)

# Grade the episode
grade = env.grade_episode()
print(f"Final Score: {grade.final_score}")

Run Baseline Agent

bash
# Run baseline agent on all tasks
python -m openenv_env.baseline_agent

Expected Output:

======================================================================
INVESTIGATION TASK: easy_001
Difficulty: easy
Article Source: TruthCentral.EXPOSED
======================================================================

Step 1: analyze_text          โ†’ Reward: +0.10
    - Sensationalism score: 0.75
    - Emotional language: True
    - ALL CAPS usage: True

Step 2: check_source          โ†’ Reward: +0.15
    - Credibility: 0.15
    - Known unreliable: True

Step 3: detect_bias           โ†’ Reward: +0.12
    - One-sided reporting: True

Step 4: verify_claim          โ†’ Reward: +0.12
    - Unverifiable claims: 2

Step 5: final_fake            โ†’ Reward: +0.50
    - Correct!

======================================================================
INVESTIGATION RESULTS
======================================================================
Final Score: 0.89 / 1.0

Docker Usage

Build Image

bash
docker build -t fake-news-agent:latest .

Run Container

bash
docker run --rm fake-news-agent:latest

Run with Volume Mounting

bash
docker run --rm -v $(pwd)/logs:/app/logs fake-news-agent:latest

OpenEnv Compliance

This environment fully complies with OpenEnv standards:

โœ… Typed Models - All state/action/reward models use Pydantic โœ… Standard Interface - reset(), step(), state() functions โœ… Observation Space - Well-defined state with clear semantics โœ… Action Space - Discrete actions with clear descriptions โœ… Reward Space - Continuous rewards in [0.0, 1.0] โœ… Grading Function - Deterministic episode evaluation โœ… Configuration File - Complete openenv.yaml specification โœ… Documentation - Comprehensive README and inline comments

See openenv.yaml for full specification.


File Structure

investigation_agent/
โ”œโ”€โ”€ openenv_env/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ env.py                 # Main environment
โ”‚   โ”œโ”€โ”€ state.py               # Pydantic models
โ”‚   โ”œโ”€โ”€ actions.py             # Action processing
โ”‚   โ”œโ”€โ”€ baseline_agent.py      # Example agent
โ”‚   โ”œโ”€โ”€ openenv_config.py      # OpenEnv specification
โ”‚   โ”œโ”€โ”€ tasks/
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py        # Task definitions
โ”‚   โ””โ”€โ”€ graders/
โ”‚       โ””โ”€โ”€ __init__.py        # Grading system
โ”œโ”€โ”€ openenv.yaml               # Configuration file
โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ”œโ”€โ”€ Dockerfile                 # Container setup
โ””โ”€โ”€ README.md                  # This file

Implementation Details

Why This Is Not a Simple Classifier

  1. 1.Multi-Step Reasoning - Agent must gather evidence before deciding
  2. 2.State Evolution - State changes based on investigation actions
  3. 3.Dynamic Rewards - Rewards vary based on timing and thoroughness
  4. 4.Sequential Decision Making - Action N depends on state at step N-1
  5. 5.Efficiency vs Accuracy Tradeoffs - Agent must balance investigation depth with step efficiency

Reward Shaping Rationale

The reward system is carefully shaped to:

  1. 1.Encourage Investigation - Base rewards for each investigation action
  2. 2.Discourage Shortcuts - Heavy penalty for making final call without investigation
  3. 3.Reward Correctness - Dominant factor in final score
  4. 4.Incentivize Efficiency - Bonus for using optimal number of steps
  5. 5.Promote Thoroughness - Bonus for using diverse investigation methods
  6. 6.Prevent Exploitation - Penalties for repetition and inefficiency

Advancing Agent Development

Tips for Building Better Agents

  1. 1.Observe Evidence - Use state.internal_evidence to understand findings
  2. 2.Chain Investigations - Use results from one action to guide the next
  3. 3.Balance Thoroughness - Don't waste steps on repeated investigations
  4. 4.Learn Task Patterns - Different tasks may require different strategies
  5. 5.Track Efficiency - Monitor steps vs. reward tradeoff

Extending the Environment

  1. 1.Add Custom Tasks - Edit tasks/__init__.py
  2. 2.Modify Reward Function - Adjust env.py reward calculations
  3. 3.Add New Analysis Methods - Extend actions.py with new processors
  4. 4.Implement Learning Agent - Use baseline as template

Testing & Validation

bash
# Run all tests
pytest

# Run specific test
pytest openenv_env/test_env.py::test_step_function

# Check code quality
flake8 openenv_env/
mypy openenv_env/

# Check test coverage
pytest --cov=openenv_env

Performance Benchmarks

With the included baseline agent:

DifficultySuccess RateAvg StepsAvg Score
Easy100%4.20.92
Medium60%5.10.65
Hard40%6.30.48

Key Insights

  1. 1.Multi-step reasoning is crucial - Agents that investigate thoroughly score higher
  2. 2.Efficiency matters - But not at the cost of accuracy
  3. 3.Diversity in investigation - Using multiple methods improves scores
  4. 4.Source credibility - Often the strongest signal for fake news
  5. 5.Pattern matching - Sensationalism and emotional language are reliable indicators

References

  • โ€”OpenEnv Specification: openenv.yaml
  • โ€”Baseline Agent: baseline_agent.py
  • โ€”Environment Source: env.py
  • โ€”State Models: state.py

License

This project is provided as-is for research and educational purposes.


Support

For issues or questions, refer to:

  • โ€”openenv.yaml for environment specification
  • โ€”openenv_env/env.py for implementation details
  • โ€”openenv_env/baseline_agent.py for usage examples
  • โ€”Inline code comments for technical details

Build Date: April 2026 Version: 1.0.0 Status: Production Ready โœ