How bunny-1432/openenv works
Purpose and Entry Points
This repository implements an OpenEnv-compatible email-triage environment for RL training and agent evaluation. Agents interact through typed MCP-style tools to inspect synthetic emails, classify/triage them, and submit replies; the environment returns observations, dense reward, and completion state.
Primary runtime entry point: server/app.py (served with Uvicorn). Python consumers use client.py; the reference model-driving loop is inference.py.
HTTP and OpenEnv Server Boundary
server/app.py constructs the FastAPI/OpenEnv application, exposing health, reset, and environment interaction endpoints (including the framework’s HTTP/WebSocket capabilities). It is the boundary between remote agents/clients and per-episode environment logic.
Deployment is container-oriented through Dockerfile; environment metadata/spec compliance is declared in openenv.yaml.
Episode Environment and Tool Dispatch
server/email_environment.py is the core MCPEnvironment implementation. It owns episode state—episode identifier, selected task, step count, active emails, submissions, accumulated scoring—and implements reset/step behavior.
Its action boundary is the six named tools: list/read email, classify, set priority/labels, submit reply, and inspect task status. Each call produces textual agent-facing feedback plus structured reward/done semantics, enforcing task step limits.
Tasks and Grading
server/tasks.py defines the three benchmark modes and deterministic grading policies:
• Single-email classification with exact/related-category credit.
• Batch inbox triage scored from ranking correlation and label accuracy.
• Reply drafting assessed through heuristic tone, coverage, length, and structure signals.
This module separates task objectives and reward evaluation from environment orchestration in server/email_environment.py, allowing a common tool lifecycle across difficulty levels.
Synthetic Data Layer
server/email_data.py supplies the fixed synthetic email corpus and task-relevant ground truth. Deterministic seeded content makes episode scoring reproducible and avoids external mailbox, identity, or email-provider dependencies.
The environment selects this data during reset, then exposes only tool-requested content to the agent, preserving the intended read-before-act workflow.
Contract Models and Client Integration
models.py contains Pydantic action/observation contracts used at the environment interface. client.py wraps the server for synchronous Python usage: reset an episode and invoke a tool with arguments.
Thus clients need not import server internals; the server remains the authoritative stateful executor and grader.
Baseline Inference and External Services
inference.py runs an autonomous baseline against the HTTP environment. It uses an OpenAI-compatible LLM API, typically the Hugging Face Router, configured by HF_TOKEN, API_BASE_URL, and MODEL_NAME; the environment URL is separately configurable.
Material runtime dependencies are Python, FastAPI/Uvicorn, OpenEnv Core, FastMCP, and Pydantic, with Docker providing the production launch envelope.
Main entry points: app.py FastAPI/OpenEnv app · email_environment.py Email environment · tasks.py Benchmark modes · inference.py Baseline inference loop
Components 12
Environment Server
Authoritative stateful OpenEnv runtime.
- FastAPI/OpenEnv app · Exposes health, reset, and environment interaction endpoints.
server/app.py - Email environment · Owns per-episode state and reset/step lifecycle.
server/email_environment.py - Six triage tools · List/read, classify, prioritize/label, reply, and status actions.
server/email_environment.py - Interface contracts · Action and observation contracts at the environment interface.
models.py
Tasks and Data
Deterministic benchmarks, grading, and synthetic inbox data.
- Benchmark modes · Classification, batch triage, and reply-drafting objectives.
server/tasks.py - Deterministic grading · Computes task-specific dense reward and completion.
server/tasks.py - Synthetic email corpus · Fixed emails and ground truth with no external mailbox dependency.
server/email_data.py
Clients and Baseline
External consumers of the HTTP environment.
- Python client · Resets episodes and invokes tools without importing server internals.
client.py - Baseline inference loop · Drives the HTTP environment with an LLM.
inference.py - OpenAI-compatible LLM API · Typically the Hugging Face Router.
Other components
- Docker launch · Production launch envelope.
Dockerfile - OpenEnv spec · Declares OpenEnv compliance metadata.
openenv.yaml
Connections 13
- Docker launch → FastAPI/OpenEnv app: launches
- OpenEnv spec → FastAPI/OpenEnv app: declares environment
- FastAPI/OpenEnv app → Email environment: routes reset and actions
- Interface contracts → FastAPI/OpenEnv app: defines request/response contracts
- Email environment → Six triage tools: dispatches actions
- Six triage tools → Synthetic email corpus: reads requested content
- Email environment → Benchmark modes: selects task on reset
- Email environment → Deterministic grading: evaluates submissions
- Benchmark modes → Deterministic grading: defines scoring objectives
- Synthetic email corpus → Benchmark modes: provides ground truth
- Python client → FastAPI/OpenEnv app: HTTP reset and tool calls
- Baseline inference loop → FastAPI/OpenEnv app: drives episode over HTTP
- Baseline inference loop → OpenAI-compatible LLM API: model completions