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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Office Workflow OpenEnv Environment
|
| 2 |
+
|
| 3 |
+
`office_workflow_env` simulates three realistic office tasks humans do and exposes them via OpenEnv’s standard `reset()` / `step()` / `state()` API.
|
| 4 |
+
|
| 5 |
+
It supports deterministic grading (0.0–1.0) for:
|
| 6 |
+
|
| 7 |
+
1. `email_triage` (easy)
|
| 8 |
+
2. `data_cleaning` (medium)
|
| 9 |
+
3. `support_escalation` (hard)
|
| 10 |
+
|
| 11 |
+
At the end of each episode, the environment writes the final task score to `observation.info.final_score` and the structured breakdown to `observation.info.final_breakdown`.
|
| 12 |
+
|
| 13 |
+
## Task / Episode API
|
| 14 |
+
|
| 15 |
+
### Reset
|
| 16 |
+
Call `reset(task_id=..., seed=..., episode_id=...)`.
|
| 17 |
+
|
| 18 |
+
* `task_id`: one of `email_triage`, `data_cleaning`, `support_escalation`
|
| 19 |
+
* `seed`: integer seed for deterministic shuffling
|
| 20 |
+
|
| 21 |
+
### Step
|
| 22 |
+
Call `step(action)` where `action` is an `OfficeAction`.
|
| 23 |
+
|
| 24 |
+
The server returns:
|
| 25 |
+
* `observation`: an `OfficeObservation`
|
| 26 |
+
* `reward`: scalar float (shaped with partial progress)
|
| 27 |
+
* `done`: boolean when the task is finished or `max_steps` is reached
|
| 28 |
+
|
| 29 |
+
The `info` field is carried inside `observation.info`.
|
| 30 |
+
|
| 31 |
+
### State
|
| 32 |
+
Call `state()` to retrieve `OfficeState` (progress + action trace; no hidden ground truth answers).
|
| 33 |
+
|
| 34 |
+
## Action Space (`OfficeAction`)
|
| 35 |
+
|
| 36 |
+
Single action schema for all tasks, discriminated by `type`:
|
| 37 |
+
|
| 38 |
+
* `type="triage_email"`
|
| 39 |
+
* `email_id`: string
|
| 40 |
+
* `category`: one of `billing`, `technical`, `spam`, `other`
|
| 41 |
+
* `priority`: int in `[0, 5]`
|
| 42 |
+
|
| 43 |
+
* `type="correct_cell"`
|
| 44 |
+
* `row_id`: string
|
| 45 |
+
* `column`: one of `email`, `phone`, `date`
|
| 46 |
+
* `value`: proposed cleaned value
|
| 47 |
+
|
| 48 |
+
* `type="support_decision"`
|
| 49 |
+
* `ticket_id`: string
|
| 50 |
+
* `intent`: one of `ask_for_information`, `resolve`, `escalate`
|
| 51 |
+
* `reply`: draft reply text
|
| 52 |
+
* plus intent-specific fields:
|
| 53 |
+
* `requested_info` (when `ask_for_information`)
|
| 54 |
+
* `resolution_steps` (when `resolve`)
|
| 55 |
+
* `escalation_reason` (when `escalate`)
|
| 56 |
+
|
| 57 |
+
Optional helper actions:
|
| 58 |
+
* `type="request_status"`
|
| 59 |
+
* `type="noop"`
|
| 60 |
+
|
| 61 |
+
## Observation Space (`OfficeObservation`)
|
| 62 |
+
|
| 63 |
+
Common fields:
|
| 64 |
+
* `task_id`, `status`, `max_steps`, `step_index`
|
| 65 |
+
|
| 66 |
+
Task-specific fields:
|
| 67 |
+
* `email_triage`: `emails`, `triaged`
|
| 68 |
+
* `data_cleaning`: `dataset`, `cleaned_cells`
|
| 69 |
+
* `support_escalation`: `tickets`, `handled_tickets`
|
| 70 |
+
|
| 71 |
+
Grader-facing info:
|
| 72 |
+
* `info.objective`, `info.completion_rule` (task instructions)
|
| 73 |
+
* `info.reward_breakdown` (per-step reward component breakdown)
|
| 74 |
+
* final episode results in `info.final_score` and `info.final_breakdown`
|
| 75 |
+
|
| 76 |
+
## Reward Shaping (partial progress)
|
| 77 |
+
|
| 78 |
+
Rewards are not binary: they increase as the agent makes correct partial progress.
|
| 79 |
+
|
| 80 |
+
All tasks:
|
| 81 |
+
* progress component grows with corrected/handled items
|
| 82 |
+
* correctness component rewards correct submissions
|
| 83 |
+
* stalling/wrong actions are penalized by driving reward toward `0.0`
|
| 84 |
+
|
| 85 |
+
## Local Setup
|
| 86 |
+
|
| 87 |
+
### Step-by-step (Windows / PowerShell)
|
| 88 |
+
|
| 89 |
+
1. Open a terminal in `c:\Users\hp\Desktop\hackathon`
|
| 90 |
+
2. Install dependencies:
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
python -m pip install -U pip
|
| 94 |
+
python -m pip install "openenv-core[core]>=0.2.1" openai requests uvicorn
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
3. Validate OpenEnv structure:
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
openenv validate
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
4. Start the server:
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
uvicorn server.app:app --host 0.0.0.0 --port 8000
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
5. Confirm it responds:
|
| 110 |
+
- `http://localhost:8000/health`
|
| 111 |
+
- `http://localhost:8000/docs`
|
| 112 |
+
|
| 113 |
+
6. Run the connectivity smoke test (expected score 0.0 because it sends only `noop`):
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
python scripts/smoke_test.py
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
7. Run a “real” local demo baseline (no OpenAI key required; rule-based):
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
python scripts/baseline_inference.py
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Baseline Inference (OpenAI)
|
| 126 |
+
|
| 127 |
+
The baseline script runs a model against all 3 tasks and prints reproducible scores.
|
| 128 |
+
|
| 129 |
+
Environment variables:
|
| 130 |
+
* `OPENAI_API_KEY`
|
| 131 |
+
* `OPENAI_MODEL` (optional, default `gpt-4o-mini`)
|
| 132 |
+
* `OPENENV_BASE_URL` (optional, default `http://localhost:8000`)
|
| 133 |
+
* `BASELINE_SEED` (optional, default `123`)
|
| 134 |
+
|
| 135 |
+
Run:
|
| 136 |
+
```bash
|
| 137 |
+
python scripts/baseline_inference.py
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
## Hugging Face Spaces Deployment
|
| 141 |
+
|
| 142 |
+
This repo includes a `server/Dockerfile` suitable for Hugging Face Spaces.
|
| 143 |
+
|
| 144 |
+
When you’re ready to deploy:
|
| 145 |
+
```bash
|
| 146 |
+
openenv validate
|
| 147 |
+
openenv push --repo-id YOUR_HF_USERNAME/office-workflow-env
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
`openenv push` will package the environment and build the Docker image for Spaces.
|
| 151 |
+
|
| 152 |
+
After it deploys, validate the running Space:
|
| 153 |
+
|
| 154 |
+
```bash
|
| 155 |
+
openenv validate https://YOUR_HF_USERNAME-office-workflow-env.hf.space
|
| 156 |
+
```
|
| 157 |
+
|
client.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Any, Dict
|
| 4 |
+
|
| 5 |
+
from openenv.core.client_types import StepResult
|
| 6 |
+
from openenv.core.env_client import EnvClient
|
| 7 |
+
|
| 8 |
+
from server.models import OfficeAction, OfficeObservation, OfficeState
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class OfficeEnvClient(EnvClient[OfficeAction, OfficeObservation, OfficeState]):
|
| 12 |
+
def _step_payload(self, action: OfficeAction) -> Dict[str, Any]:
|
| 13 |
+
# The env server deserializes via Pydantic, so we send only provided fields.
|
| 14 |
+
return action.model_dump(exclude_none=True)
|
| 15 |
+
|
| 16 |
+
def _parse_result(self, payload: Dict[str, Any]) -> StepResult[OfficeObservation]:
|
| 17 |
+
obs_data = payload.get("observation", {}) or {}
|
| 18 |
+
reward = payload.get("reward", None)
|
| 19 |
+
done = bool(payload.get("done", False))
|
| 20 |
+
observation = OfficeObservation(
|
| 21 |
+
**obs_data,
|
| 22 |
+
done=done,
|
| 23 |
+
reward=reward,
|
| 24 |
+
)
|
| 25 |
+
return StepResult(observation=observation, reward=reward, done=done)
|
| 26 |
+
|
| 27 |
+
def _parse_state(self, payload: Dict[str, Any]) -> OfficeState:
|
| 28 |
+
return OfficeState.model_validate(payload)
|
| 29 |
+
|
openenv.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
spec_version: 1
|
| 2 |
+
name: office_workflow_env
|
| 3 |
+
type: space
|
| 4 |
+
runtime: fastapi
|
| 5 |
+
app: server.app:app
|
| 6 |
+
port: 8000
|
pyproject.toml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["setuptools>=45", "wheel"]
|
| 3 |
+
build-backend = "setuptools.build_meta"
|
| 4 |
+
|
| 5 |
+
[project]
|
| 6 |
+
name = "openenv-office-workflow-env"
|
| 7 |
+
version = "0.1.0"
|
| 8 |
+
description = "Real-world office workflow environment with graded tasks"
|
| 9 |
+
requires-python = ">=3.11"
|
| 10 |
+
dependencies = [
|
| 11 |
+
"openenv-core[core]>=0.2.1",
|
| 12 |
+
"openai>=2.7.2",
|
| 13 |
+
"requests>=2.31.0",
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
[project.scripts]
|
| 17 |
+
# Entry point required by `openenv validate`
|
| 18 |
+
server = "server.app:main"
|
| 19 |
+
|
| 20 |
+
[tool.setuptools]
|
| 21 |
+
include-package-data = true
|
| 22 |
+
packages = ["server"]
|
| 23 |
+
package-dir = { "server" = "server" }
|
| 24 |
+
|
uv.lock
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Placeholder lockfile for OpenEnv validation.
|
| 2 |
+
# If you run `uv lock` / `openenv build`, this will be replaced with a real lock.
|
| 3 |
+
|