snehagupt/news_investigation_agent
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 implementationState Space
The agent observes:
{
"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:
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:
- Investigation actions provide consistent positive rewards
- Repeated actions are penalized
- Final answers dominate overall reward
- Efficiency bonus for fewer steps
- 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
# Clone repository
cd investigation_agent
# Install dependencies
pip install -r requirements.txtBasic Usage
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
# Run baseline agent on all tasks
python -m openenv_env.baseline_agentExpected 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.0Docker Usage
Build Image
docker build -t fake-news-agent:latest .Run Container
docker run --rm fake-news-agent:latestRun with Volume Mounting
docker run --rm -v $(pwd)/logs:/app/logs fake-news-agent:latestOpenEnv 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 fileImplementation Details
Why This Is Not a Simple Classifier
- Multi-Step Reasoning - Agent must gather evidence before deciding
- State Evolution - State changes based on investigation actions
- Dynamic Rewards - Rewards vary based on timing and thoroughness
- Sequential Decision Making - Action N depends on state at step N-1
- Efficiency vs Accuracy Tradeoffs - Agent must balance investigation depth with step efficiency
Reward Shaping Rationale
The reward system is carefully shaped to:
- Encourage Investigation - Base rewards for each investigation action
- Discourage Shortcuts - Heavy penalty for making final call without investigation
- Reward Correctness - Dominant factor in final score
- Incentivize Efficiency - Bonus for using optimal number of steps
- Promote Thoroughness - Bonus for using diverse investigation methods
- Prevent Exploitation - Penalties for repetition and inefficiency
Advancing Agent Development
Tips for Building Better Agents
- Observe Evidence - Use
state.internal_evidenceto understand findings - Chain Investigations - Use results from one action to guide the next
- Balance Thoroughness - Don't waste steps on repeated investigations
- Learn Task Patterns - Different tasks may require different strategies
- Track Efficiency - Monitor steps vs. reward tradeoff
Extending the Environment
- Add Custom Tasks - Edit
tasks/__init__.py - Modify Reward Function - Adjust
env.pyreward calculations - Add New Analysis Methods - Extend
actions.pywith new processors - Implement Learning Agent - Use baseline as template
Testing & Validation
# 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_envPerformance Benchmarks
With the included baseline agent:
Key Insights
- Multi-step reasoning is crucial - Agents that investigate thoroughly score higher
- Efficiency matters - But not at the cost of accuracy
- Diversity in investigation - Using multiple methods improves scores
- Source credibility - Often the strongest signal for fake news
- 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.yamlfor environment specificationopenenv_env/env.pyfor implementation detailsopenenv_env/baseline_agent.pyfor usage examples- Inline code comments for technical details
Build Date: April 2026 Version: 1.0.0 Status: Production Ready โ
