title: AdaptiveWorld Env
emoji: π
colorFrom: indigo
colorTo: purple
sdk: docker
app_file: server/app.py
app_port: 7860
pinned: false
AdaptiveWorld Env
Theme 3.1 (World Modeling / Professional Tasks) + Theme 5 (Wild Card)
Sub-theme: Patronus AI β Consumer Workflows with Schema Drift
Built on: ProthamD/api-debug-env (Round 1)
What This Is
An OpenEnv environment where an AI agent completes multi-step professional tasks (booking, ordering, filing claims) while the world mutates mid-episode without announcement.
API schemas change, field names shift, policies flip, and sometimes the API returns
200 OK but the meaning of the response has silently changed.
Five novel contributions (stacked)
- Non-stationary world β environment mutates mid-episode (drift mechanic)
- Dual metrics β
task_reward+belief_accuracytracked separately - Adaptive difficulty β environment auto-escalates when agent masters easy drift types
- Drift provenance hidden β agent must infer drift from evidence, not from being told
- Cross-episode persistence β agent's world model carries across episodes
No existing OpenEnv environment has any of these five properties simultaneously.
Quick Start
# Install
pip install -e .
# Run server
uvicorn server.app:app --host 0.0.0.0 --port 7860
# Health check
curl http://localhost:7860/health
# Run inference
python inference.py --difficulty easy --episodes 3
Project Structure
adaptive-world-env/
βββ server/
β βββ app.py β FastAPI entry point
β βββ adaptive_world_environment.py β Core environment logic
β βββ mock_api.py β Dynamic mock API (4 domains)
β βββ drift_injector.py β World state mutation manager
β βββ difficulty_controller.py β Adaptive difficulty escalation
βββ scenarios/
β βββ easy.py (E1: field rename, E2: endpoint version, E3: auth scheme)
β βββ medium.py (M1: double drift, M2: policy flip, M3: rate limit)
β βββ hard.py (H1: silent status, H2: response structure, H3: cascading)
β βββ expert.py (EX1: transient vs real, EX2: cross-service, EX3: red herring)
βββ graders/grader.py β grade_task + grade_belief + infer_belief
βββ models.py β AdaptiveAction, AdaptiveObservation, AdaptiveState
βββ inference.py β LLM inference loop (OpenAI-compatible)
βββ training_notebook.ipynb β Colab GRPO training notebook
βββ openenv.yaml β OpenEnv spec
Action Space
action_type |
What it does |
|---|---|
call_api |
Standard HTTP request to mock API |
probe_schema |
GET current API schema β reveals post-drift contract |
query_history |
Review last N step logs β compare pre vs post drift responses |
declare_belief |
Agent states its current world model (scored later) |
submit_result |
End episode, agent declares final belief_state |
Observation Space
All fields the agent sees. Note: drift_occurred and drift_type are intentionally absent.
The agent must infer drift from evidence.
| Field | Type | Description |
|---|---|---|
task_description |
str | What to accomplish |
domain |
str | e-commerce / hotel / flight / insurance |
prior_world_model |
dict | Agent's beliefs from previous episodes |
current_step |
int | Step number |
max_steps |
int | Episode step limit |
last_status_code |
int | HTTP status of last call |
last_response_body |
str | Response body |
step_feedback |
str | Contextual hint |
episode_history |
list | Returned by query_history |
task_reward |
float | Task completion score (on done) |
belief_accuracy |
float | Belief accuracy score (on done) |
difficulty_level |
int | Current escalation level (0-3) |
reward |
float | Combined: 0.7Γtask + 0.3Γbelief |
Drift Types
| Type | Error Signal | Example |
|---|---|---|
field_rename |
422 | qty β quantity |
endpoint_version |
404 | /book β /v2/book |
policy_change |
403 or 429 | Discount requires gold membership |
silent_semantic |
None (200 OK) | "confirmed" β "approved" |
Training Results
| Metric | Early window (dashboard) | Late window (dashboard) |
|---|---|---|
| Task reward (avg) | 0.35 | 0.49 |
| Belief accuracy (avg) | 0.16 | 0.23 |
| Combined reward (avg) | 0.30 | 0.41 |
| Correlation r (task vs belief) | 0.957 | 0.977 |
These aggregates come from the same 200-step GRPO run (Qwen2.5-3B 4-bit, 4 completions/step) after SFT (30 steps) and before/with DPO (~50 steps), matching the Training Runs dashboard export.
The correlation chart is the headline: early-window correlation is already high (~0.957) on smoothed traces; late-window correlation reaches ~0.977 β task success and belief understanding stay aligned as difficulty ramps.
Combating Reward Hacking
During development, we discovered that highly capable models (like Llama-3.3-70B) would exhibit reward hacking. The models were so efficient they would complete the task within 2 stepsβbefore the environment's original drift_trigger_step even had a chance to mutate the API!
Furthermore, when the API returned a 200 OK (even with a silent semantic drift inside the body), the environment was auto-terminating the episode. This short-circuited the agent, preventing it from investigating the response and resulting in a 0.0 belief accuracy score despite a high task reward.
How we solved it:
- Immediate Drift: We lowered
drift_trigger_step = 1for most scenarios. The world mutates immediately on the very first API call, forcing the agent to confront the non-stationary world. - Preventing Auto-Termination: We removed the environment's premature auto-termination on task completion. Instead of ending the episode immediately upon a
200 OK, the environment returns a feedback hint: "Task completed successfully. Please review the response for any silent changes, and use 'submit_result' to end the episode." This forces the agent to explicitly declare its understanding of the new API contract before scoring occurs.
HF Space Deployment
# Create new HF Space (Docker)
huggingface-cli repo create prothamd-adaptive-world-env --type space --space-sdk docker
# Push
git remote add hf https://huggingface.co/spaces/ProthamD/prothamd-adaptive-world-env
git push hf main
Space URL: https://huggingface.co/spaces/ProthamD/prothamd-adaptive-world-env
API URL: https://prothamd-adaptive-world-env.hf.space
Run Tests
pytest tests/ -v
Built on: ProthamD/api-debug-env (Round 1 submission)
Version: 2.3 β Adaptive Difficulty + Drift Provenance Hidden + Cross-Episode Persistence
Licensed under CC BY-NC 4.0 β https://creativecommons.org/licenses/by-nc/4.0/