Somuai12 commited on
Commit
ef5751d
·
1 Parent(s): 6aa8acb

final: polish README (RLVR specs) and cleanup scratch scripts

Browse files
Files changed (2) hide show
  1. README.md +19 -6
  2. verify_repetition.py +0 -39
README.md CHANGED
@@ -6,11 +6,24 @@ sdk: docker
6
  app_port: 7860
7
  base_path: /dashboard/
8
  ---
9
- # PolicyEvolverEnv
10
 
11
- **PolicyEvolverEnv** is an OpenEnv-compliant reinforcement learning environment designed for the Meta × PyTorch × Scaler Hackathon.
12
 
13
- ## Environment Description & Motivation
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  PolicyEvolverEnv is a real-world governance sandbox where an AI agent learns to **design and evolve governance policies** through meta-reasoning over real-world operational data. In modern platforms (social media, enterprise HR, e-commerce), static policies quickly become outdated or vaguely applied, leading to inconsistent enforcement, false-positive moderation, and unrecognized fraud.
15
 
16
  This environment simulates this challenge by presenting the agent with a corpus of operational data alongside an existing policy framework. The agent's goal is to analyze the outcomes, identify systemic flaws or ambiguities, and act directly on the policies to optimize governance outcomes. This directly tackles live production problems faced by platforms like Meta.
@@ -28,12 +41,12 @@ The environment represents the **Reinforcement Learning from Verifiable Rewards
28
  ### 2. The Gradio "Judge Console": How it Works
29
  The dashboard we built (`server/app.py`) is the human-readable window into this environment. It’s designed as a **Command & Control** center for a "Policy Judge."
30
 
31
- #### 📈 The Left Panel: Scenario Metrics
32
  * **Environment Best Score**: This tracks the highest score achieved in this session. It represents the "Gold Standard" the agent is aiming for.
33
  * **Remaining Execution Steps**: Each "Episode" has a limit (5 steps). The agent must improve the policy within this budget. This forces **Strategic Efficiency**.
34
  * **Latest Strategic Reward**: Every time you click "Execute," the Grader (`server/grader.py`) analyzes your proposal. If it’s vague, you get a low reward (0.1–0.3). If it’s specific and measurable, you get a high reward (0.8–0.9).
35
 
36
- #### 📋 The Right Panel: Observations
37
  * **Data Corpus (Tabular View)**: These are the "Facts on the Ground." These are real-world incidents (e.g., a post flagged for 'harassment' vs one that wasn't).
38
  * **Active Framework**: This shows the current "Code of Law."
39
  * **The Workflow**: Your goal is to find an incident in the Corpus that doesn't fit correctly into the Framework, then use the bottom console to fix it.
@@ -142,7 +155,7 @@ The following baseline scores were achieved using the reference agent (Gemini 2.
142
  ## 📈 Strategic Reward Evolution & RLVR
143
  PolicyEvolverEnv serves as the **Strategic Sandbox** for the **Reinforcement Finetuning (RLVR)** stage of the modern LLM training pipeline. Unlike static evaluation, this environment enables agents to refine their strategies iteratively based on high-quality, verifiable feedback.
144
 
145
- ![Strategic Reward Progression](reward_progression.png)
146
 
147
  ### 🧠 How It Works: The Iterative Learning Process
148
  1. **Refinement Hub**: The baseline agent tracks its previous rewards and actions through the observation's metadata (`info`).
 
6
  app_port: 7860
7
  base_path: /dashboard/
8
  ---
9
+ # PolicyEvolverEnv — Multi-Modal Strategic Governance Sandbox
10
 
11
+ **PolicyEvolverEnv** is an OpenEnv-compliant reinforcement learning environment designed for the **Meta × PyTorch × Scaler Hackathon**. It serves as a production-grade benchmark for **Reinforcement Learning from Verifiable Rewards (RLVR)**.
12
 
13
+ ---
14
+
15
+ ### 🧪 Advanced Reward Shaping (RLVR Integration)
16
+ Unlike standard environments with static rewards, **PolicyEvolverEnv v2.0** implements a sophisticated, deterministic grading engine designed to harden LLM strategic reasoning:
17
+
18
+ * **Tiered CoT Bonus**: Rewards analytical reasoning (up to +0.20) based on keyword density and length.
19
+ * **Clarity Coherence**: Penalizes "vague" or "subjective" (e.g., *maybe, perhaps*) policy definitions in Easy tasks.
20
+ * **Tradeoff Realism**: Detects and caps "hallucinated" outcomes in Hard tasks (e.g., claiming to simultaneously maximize fraud-prevention and revenue).
21
+ * **Step-Delta Shaping**: Provides an `improvement_bonus` for iterative actions that significantly outperform the episode's best score.
22
+ * **Anti-Repetition Penalty**: Encounters a -0.30 penalty for exact repeated actions, forcing the agent toward continuous evolution.
23
+
24
+ ---
25
+
26
+ ## Environment Description & Motivation
27
  PolicyEvolverEnv is a real-world governance sandbox where an AI agent learns to **design and evolve governance policies** through meta-reasoning over real-world operational data. In modern platforms (social media, enterprise HR, e-commerce), static policies quickly become outdated or vaguely applied, leading to inconsistent enforcement, false-positive moderation, and unrecognized fraud.
28
 
29
  This environment simulates this challenge by presenting the agent with a corpus of operational data alongside an existing policy framework. The agent's goal is to analyze the outcomes, identify systemic flaws or ambiguities, and act directly on the policies to optimize governance outcomes. This directly tackles live production problems faced by platforms like Meta.
 
41
  ### 2. The Gradio "Judge Console": How it Works
42
  The dashboard we built (`server/app.py`) is the human-readable window into this environment. It’s designed as a **Command & Control** center for a "Policy Judge."
43
 
44
+ #### The Left Panel: Scenario Metrics
45
  * **Environment Best Score**: This tracks the highest score achieved in this session. It represents the "Gold Standard" the agent is aiming for.
46
  * **Remaining Execution Steps**: Each "Episode" has a limit (5 steps). The agent must improve the policy within this budget. This forces **Strategic Efficiency**.
47
  * **Latest Strategic Reward**: Every time you click "Execute," the Grader (`server/grader.py`) analyzes your proposal. If it’s vague, you get a low reward (0.1–0.3). If it’s specific and measurable, you get a high reward (0.8–0.9).
48
 
49
+ #### The Right Panel: Observations
50
  * **Data Corpus (Tabular View)**: These are the "Facts on the Ground." These are real-world incidents (e.g., a post flagged for 'harassment' vs one that wasn't).
51
  * **Active Framework**: This shows the current "Code of Law."
52
  * **The Workflow**: Your goal is to find an incident in the Corpus that doesn't fit correctly into the Framework, then use the bottom console to fix it.
 
155
  ## 📈 Strategic Reward Evolution & RLVR
156
  PolicyEvolverEnv serves as the **Strategic Sandbox** for the **Reinforcement Finetuning (RLVR)** stage of the modern LLM training pipeline. Unlike static evaluation, this environment enables agents to refine their strategies iteratively based on high-quality, verifiable feedback.
157
 
158
+ ![Reward Progression](https://raw.githubusercontent.com/Luciferai04/PolicyEvolverEnv/master/reward_progression.png)
159
 
160
  ### 🧠 How It Works: The Iterative Learning Process
161
  1. **Refinement Hub**: The baseline agent tracks its previous rewards and actions through the observation's metadata (`info`).
verify_repetition.py DELETED
@@ -1,39 +0,0 @@
1
- import asyncio
2
- import os
3
- import sys
4
-
5
- # Add current directory to path so we can import everything correctly
6
- sys.path.insert(0, os.getcwd())
7
-
8
- from server.environment import PolicyEvolverEnvironment
9
- from models import Action
10
-
11
- async def verify_repetition():
12
- env = PolicyEvolverEnvironment()
13
- # Reset to start fresh
14
- obs1 = env.reset(task_id="task_easy")
15
-
16
- same_action = {
17
- "action_type": "propose_clarification",
18
- "ambiguous_term": "appropriate",
19
- "suggested_definition": "Behavior is defined as appropriate when it specifically follows the community guidelines, meaning it does not include excessive slurs and meets the 5% threshold for verified user reports.",
20
- "justification": "The current policy leads to inconsistent and subjective moderation because it is unclear and varies between interpreters.",
21
- "think": ""
22
- }
23
-
24
- # First step
25
- print("\n--- Step 1 ---")
26
- res1 = env.step(same_action)
27
- print(f"Step 1 Reward: {res1.reward}")
28
-
29
- # Second step with identical action
30
- print("\n--- Step 2 (Repeat) ---")
31
- res2 = env.step(same_action)
32
- print(f"Step 2 Reward: {res2.reward}")
33
-
34
- # Assert
35
- assert res2.reward < res1.reward, f"Repeated action should score lower! res2={res2.reward}, res1={res1.reward}"
36
- print("\n✅ Anti-repetition test passed! Reward was penalized as expected.")
37
-
38
- if __name__ == "__main__":
39
- asyncio.run(verify_repetition())