Spaces:
Sleeping
Sleeping
fix repo structure for HF
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- .DS_Store +0 -0
- workflowTwin/.env.example β .env.example +0 -0
- workflowTwin/.gitignore β .gitignore +0 -0
- workflowTwin/Dockerfile β Dockerfile +0 -0
- README.md +211 -8
- {workflowTwin/baseline β baseline}/policy.py +0 -0
- {workflowTwin/baselines β baselines}/heuristics.py +0 -0
- {workflowTwin/baselines β baselines}/rl_agents.py +0 -0
- {workflowTwin/env β env}/__init__.py +0 -0
- {workflowTwin/env β env}/dynamics.py +0 -0
- {workflowTwin/env β env}/entities.py +0 -0
- {workflowTwin/env β env}/environment.py +0 -0
- {workflowTwin/env β env}/graders.py +0 -0
- {workflowTwin/env β env}/models.py +0 -0
- {workflowTwin/env β env}/quantizer.py +0 -0
- {workflowTwin/env β env}/reward.py +0 -0
- {workflowTwin/env β env}/runtime_config.py +0 -0
- {workflowTwin/env β env}/tasks.py +0 -0
- {workflowTwin/experiments β experiments}/ab_quantized_memory_eval.py +0 -0
- {workflowTwin/experiments β experiments}/ab_turboquant_eval.py +0 -0
- {workflowTwin/experiments β experiments}/figures/memory_budget_vs_compliance.svg +0 -0
- workflowTwin/inference.py β inference.py +0 -0
- workflowTwin/openenv.yaml β openenv.yaml +0 -0
- workflowTwin/requirements.txt β requirements.txt +0 -0
- {workflowTwin/server β server}/app.py +0 -0
- {workflowTwin/server β server}/routes.py +0 -0
- {workflowTwin/tasks β tasks}/easy.json +0 -0
- {workflowTwin/tasks β tasks}/hard.json +0 -0
- {workflowTwin/tasks β tasks}/level1/tasks.json +0 -0
- {workflowTwin/tasks β tasks}/level2/tasks.json +0 -0
- {workflowTwin/tasks β tasks}/level3/tasks.json +0 -0
- {workflowTwin/tasks β tasks}/level4/tasks.json +0 -0
- {workflowTwin/tasks β tasks}/level5/tasks.json +0 -0
- {workflowTwin/tasks β tasks}/medium.json +0 -0
- workflowTwin/.DS_Store +0 -0
- workflowTwin/README.md +0 -215
- {workflowTwin/workflow_twin β workflow_twin}/.DS_Store +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/__init__.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/core/__init__.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/core/config.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/core/dynamics.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/core/entities.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/environment.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/levels/__init__.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/levels/level1_simple.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/levels/level2_sla.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/levels/level3_approval.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/levels/level4_stochastic.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/levels/level5_memory.py +0 -0
- {workflowTwin/workflow_twin β workflow_twin}/memory.py +0 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
workflowTwin/.env.example β .env.example
RENAMED
|
File without changes
|
workflowTwin/.gitignore β .gitignore
RENAMED
|
File without changes
|
workflowTwin/Dockerfile β Dockerfile
RENAMED
|
File without changes
|
README.md
CHANGED
|
@@ -1,12 +1,215 @@
|
|
| 1 |
---
|
| 2 |
-
title: Workflow Twin
|
| 3 |
-
emoji: π
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: gray
|
| 6 |
sdk: docker
|
| 7 |
-
|
| 8 |
-
license: mit
|
| 9 |
-
short_description: OpenEnv environment for workflow simulation under memory con
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
sdk: docker
|
| 3 |
+
app_port: 8000
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
+
# WorkflowTwin
|
| 7 |
+
|
| 8 |
+
An OpenEnv-compatible environment for training and evaluating agents under memory and resource constraints.
|
| 9 |
+
|
| 10 |
+
This environment simulates multi-step ticket resolution pipelines with:
|
| 11 |
+
- queueing, prioritization, and dependencies
|
| 12 |
+
- stochastic arrivals and agent failures
|
| 13 |
+
- strict memory budgets on agent state
|
| 14 |
+
|
| 15 |
+
We introduce a **quantized memory policy** based on:
|
| 16 |
+
- random orthogonal projection
|
| 17 |
+
- scalar vector quantization
|
| 18 |
+
- random projection residual sketching
|
| 19 |
+
|
| 20 |
+
to study how compression affects agent performance under resource constraints.
|
| 21 |
+
|
| 22 |
+
## Motivation
|
| 23 |
+
|
| 24 |
+
Real-world agents must operate under limited memory and compute.
|
| 25 |
+
|
| 26 |
+
Without compression:
|
| 27 |
+
- state grows unbounded
|
| 28 |
+
- agents violate system constraints
|
| 29 |
+
|
| 30 |
+
With quantized memory:
|
| 31 |
+
- state is compressed
|
| 32 |
+
- agents remain feasible under tight budgets
|
| 33 |
+
|
| 34 |
+
This environment enables controlled evaluation of this tradeoff.
|
| 35 |
+
|
| 36 |
+
## Key Results
|
| 37 |
+
|
| 38 |
+
We evaluate two modes:
|
| 39 |
+
- **baseline**: no compression (truncation under pressure)
|
| 40 |
+
- **quant**: rotated quantized memory compression
|
| 41 |
+
|
| 42 |
+
This establishes a clear crossover point where compression transitions from unnecessary to essential.
|
| 43 |
+
|
| 44 |
+
### Memory Budget vs Feasibility
|
| 45 |
+
|
| 46 |
+

|
| 47 |
+
|
| 48 |
+
### Key Findings
|
| 49 |
+
|
| 50 |
+
- **Feasibility threshold shift:**
|
| 51 |
+
Baseline requires ~6000 memory, while quantized memory achieves full compliance at ~3000.
|
| 52 |
+
|
| 53 |
+
- **2Γ efficiency gain:**
|
| 54 |
+
Compression halves the memory required for feasible operation.
|
| 55 |
+
|
| 56 |
+
- **No-regret behavior:**
|
| 57 |
+
Under no memory pressure, both methods perform identically.
|
| 58 |
+
|
| 59 |
+
- **Constraint robustness:**
|
| 60 |
+
Under tight budgets, baseline fails (0% compliance) while quantized memory remains fully feasible (100%).
|
| 61 |
+
|
| 62 |
+
**Conclusion:** Compression extends the feasible operating regime without degrading task performance.
|
| 63 |
+
|
| 64 |
+
## Structure
|
| 65 |
+
|
| 66 |
+
- `env/`: core environment logic, models, scoring, reward
|
| 67 |
+
- includes `quantizer.py` with rotated vector quantization primitives
|
| 68 |
+
- `server/`: FastAPI app exposing `reset`, `step`, `state`
|
| 69 |
+
- `tasks/`: JSON task definitions by difficulty
|
| 70 |
+
- `baseline/`: non-LLM heuristic policy
|
| 71 |
+
- `baselines/`: research evaluation baselines for `workflow_twin`
|
| 72 |
+
- `inference.py`: local rollout entrypoint
|
| 73 |
+
- `openenv.yaml`: environment spec
|
| 74 |
+
|
| 75 |
+
## Quickstart
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
python -m venv .venv
|
| 79 |
+
source .venv/bin/activate
|
| 80 |
+
pip install -r requirements.txt
|
| 81 |
+
uvicorn server.app:app --reload
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
Server endpoints:
|
| 85 |
+
|
| 86 |
+
- `POST /reset`
|
| 87 |
+
- `POST /step` with body `{ "action_type": "triage|respond|resolve|escalate", "note": "..." }`
|
| 88 |
+
- `GET /state`
|
| 89 |
+
- `GET /config` (resolved runtime config loaded from env vars)
|
| 90 |
+
|
| 91 |
+
Run baseline inference:
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
python inference.py
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
Inference environment variables:
|
| 98 |
+
|
| 99 |
+
- `API_BASE_URL`: OpenAI-compatible endpoint base URL
|
| 100 |
+
- `HF_TOKEN`: API token (used as `api_key`)
|
| 101 |
+
- `MODEL_NAME`: chat model name (default: `gpt-4o-mini`)
|
| 102 |
+
|
| 103 |
+
If `API_BASE_URL` or `HF_TOKEN` is missing, inference automatically falls back to heuristic policy.
|
| 104 |
+
|
| 105 |
+
`inference.py` result fields:
|
| 106 |
+
|
| 107 |
+
- `score`: final reported score (`env_score` when available, otherwise `partial_score`)
|
| 108 |
+
- `env_score`: environment-provided score from `env.state()`
|
| 109 |
+
- `partial_score`: fallback score from normalized accumulated reward
|
| 110 |
+
- `openai_client_configured`: `true` when both `API_BASE_URL` and `HF_TOKEN` are present
|
| 111 |
+
|
| 112 |
+
## Method: Quantized Memory Policy
|
| 113 |
+
|
| 114 |
+
We implement a rotated vector quantization pipeline:
|
| 115 |
+
|
| 116 |
+
1. **Random Orthogonal Projection**
|
| 117 |
+
- decorrelates embedding dimensions
|
| 118 |
+
|
| 119 |
+
2. **Scalar Quantization**
|
| 120 |
+
- coordinate-wise discretization
|
| 121 |
+
|
| 122 |
+
3. **Residual Random Projection Sketch**
|
| 123 |
+
- preserves inner-product structure
|
| 124 |
+
|
| 125 |
+
Reward shaping includes:
|
| 126 |
+
- distortion penalty (MSE)
|
| 127 |
+
- inner-product preservation penalty
|
| 128 |
+
|
| 129 |
+
## Research-Grade WorkflowTwin (L1-L5)
|
| 130 |
+
|
| 131 |
+
A new package `workflow_twin/` is now implemented to evolve the simulator from single-ticket MVP to multi-ticket workflow research environment.
|
| 132 |
+
|
| 133 |
+
### Included
|
| 134 |
+
|
| 135 |
+
- `workflow_twin/core/entities.py`: multi-ticket state, agents, time, SLA/resource fields
|
| 136 |
+
- `workflow_twin/core/dynamics.py`: queue logic, SLA penalties, dependencies, stochastic arrivals/failures
|
| 137 |
+
- `workflow_twin/core/config.py`: level configs (L1-L5)
|
| 138 |
+
- `workflow_twin/environment.py`: main level-aware environment (`WorkflowTwinEnv`)
|
| 139 |
+
- `workflow_twin/memory.py`: `MemoryBoundedEnv` wrapper using rotated quantized memory compression
|
| 140 |
+
- `workflow_twin/levels/`: level hooks for L1 simple β L5 memory pressure
|
| 141 |
+
- `baselines/heuristics.py`: simple queue baseline policy
|
| 142 |
+
- `tasks/level1..level5/`: task scaffolding per level
|
| 143 |
+
|
| 144 |
+
### Quick Example
|
| 145 |
+
|
| 146 |
+
```bash
|
| 147 |
+
python - <<'PY'
|
| 148 |
+
from workflow_twin.environment import WorkflowTwinEnv
|
| 149 |
+
from baselines.heuristics import greedy_queue_policy
|
| 150 |
+
|
| 151 |
+
env = WorkflowTwinEnv(level=3, seed=42)
|
| 152 |
+
obs = env.reset()
|
| 153 |
+
|
| 154 |
+
for _ in range(10):
|
| 155 |
+
action = greedy_queue_policy(obs)
|
| 156 |
+
obs, reward, done, info = env.step(action)
|
| 157 |
+
print(info["step_count"], reward, info["queue"])
|
| 158 |
+
if done:
|
| 159 |
+
break
|
| 160 |
+
PY
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
### Memory-Bounded Wrapper Example (L5)
|
| 164 |
+
|
| 165 |
+
```bash
|
| 166 |
+
python - <<'PY'
|
| 167 |
+
from workflow_twin.environment import WorkflowTwinEnv
|
| 168 |
+
from workflow_twin.memory import MemoryBoundedEnv
|
| 169 |
+
|
| 170 |
+
base_env = WorkflowTwinEnv(level=5, seed=42)
|
| 171 |
+
env = MemoryBoundedEnv(base_env, memory_budget=3500, bits=3)
|
| 172 |
+
obs = env.reset()
|
| 173 |
+
obs, reward, done, info = env.step({"action_type": "triage", "note": "memory-check"})
|
| 174 |
+
print(info["memory"])
|
| 175 |
+
PY
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
## Docker
|
| 179 |
+
|
| 180 |
+
```bash
|
| 181 |
+
docker build -t workflowtwin .
|
| 182 |
+
docker run -p 8000:8000 workflowtwin
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
## Controlled A/B Quantized Memory Evaluation
|
| 186 |
+
|
| 187 |
+
Run the controlled experiment suite:
|
| 188 |
+
|
| 189 |
+
```bash
|
| 190 |
+
python -m experiments.ab_quantized_memory_eval
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
This executes two tests with shared metrics:
|
| 194 |
+
|
| 195 |
+
- control_no_memory_pressure (Level 1, large memory budget)
|
| 196 |
+
- critical_memory_constrained_long_horizon (Level 5, tight memory budget)
|
| 197 |
+
- memory_budget_sweep (budgets: 2000, 3000, 4000, 6000)
|
| 198 |
+
|
| 199 |
+
Modes compared:
|
| 200 |
+
|
| 201 |
+
- baseline: no compression, truncation under pressure
|
| 202 |
+
- quant: rotated quantized memory compression under pressure
|
| 203 |
+
|
| 204 |
+
Reported metrics:
|
| 205 |
+
|
| 206 |
+
- avg_reward
|
| 207 |
+
- success_rate (resolved/total)
|
| 208 |
+
- avg_sla_violations
|
| 209 |
+
- avg_memory_used vs avg_memory_budget
|
| 210 |
+
- memory_compliance_rate
|
| 211 |
+
- steps_per_sec
|
| 212 |
+
|
| 213 |
+
Figure (generated by the experiment runner):
|
| 214 |
+
|
| 215 |
+

|
{workflowTwin/baseline β baseline}/policy.py
RENAMED
|
File without changes
|
{workflowTwin/baselines β baselines}/heuristics.py
RENAMED
|
File without changes
|
{workflowTwin/baselines β baselines}/rl_agents.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/__init__.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/dynamics.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/entities.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/environment.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/graders.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/models.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/quantizer.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/reward.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/runtime_config.py
RENAMED
|
File without changes
|
{workflowTwin/env β env}/tasks.py
RENAMED
|
File without changes
|
{workflowTwin/experiments β experiments}/ab_quantized_memory_eval.py
RENAMED
|
File without changes
|
{workflowTwin/experiments β experiments}/ab_turboquant_eval.py
RENAMED
|
File without changes
|
{workflowTwin/experiments β experiments}/figures/memory_budget_vs_compliance.svg
RENAMED
|
File without changes
|
workflowTwin/inference.py β inference.py
RENAMED
|
File without changes
|
workflowTwin/openenv.yaml β openenv.yaml
RENAMED
|
File without changes
|
workflowTwin/requirements.txt β requirements.txt
RENAMED
|
File without changes
|
{workflowTwin/server β server}/app.py
RENAMED
|
File without changes
|
{workflowTwin/server β server}/routes.py
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/easy.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/hard.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/level1/tasks.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/level2/tasks.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/level3/tasks.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/level4/tasks.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/level5/tasks.json
RENAMED
|
File without changes
|
{workflowTwin/tasks β tasks}/medium.json
RENAMED
|
File without changes
|
workflowTwin/.DS_Store
DELETED
|
Binary file (10.2 kB)
|
|
|
workflowTwin/README.md
DELETED
|
@@ -1,215 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
sdk: docker
|
| 3 |
-
app_port: 8000
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
# WorkflowTwin
|
| 7 |
-
|
| 8 |
-
An OpenEnv-compatible environment for training and evaluating agents under memory and resource constraints.
|
| 9 |
-
|
| 10 |
-
This environment simulates multi-step ticket resolution pipelines with:
|
| 11 |
-
- queueing, prioritization, and dependencies
|
| 12 |
-
- stochastic arrivals and agent failures
|
| 13 |
-
- strict memory budgets on agent state
|
| 14 |
-
|
| 15 |
-
We introduce a **quantized memory policy** based on:
|
| 16 |
-
- random orthogonal projection
|
| 17 |
-
- scalar vector quantization
|
| 18 |
-
- random projection residual sketching
|
| 19 |
-
|
| 20 |
-
to study how compression affects agent performance under resource constraints.
|
| 21 |
-
|
| 22 |
-
## Motivation
|
| 23 |
-
|
| 24 |
-
Real-world agents must operate under limited memory and compute.
|
| 25 |
-
|
| 26 |
-
Without compression:
|
| 27 |
-
- state grows unbounded
|
| 28 |
-
- agents violate system constraints
|
| 29 |
-
|
| 30 |
-
With quantized memory:
|
| 31 |
-
- state is compressed
|
| 32 |
-
- agents remain feasible under tight budgets
|
| 33 |
-
|
| 34 |
-
This environment enables controlled evaluation of this tradeoff.
|
| 35 |
-
|
| 36 |
-
## Key Results
|
| 37 |
-
|
| 38 |
-
We evaluate two modes:
|
| 39 |
-
- **baseline**: no compression (truncation under pressure)
|
| 40 |
-
- **quant**: rotated quantized memory compression
|
| 41 |
-
|
| 42 |
-
This establishes a clear crossover point where compression transitions from unnecessary to essential.
|
| 43 |
-
|
| 44 |
-
### Memory Budget vs Feasibility
|
| 45 |
-
|
| 46 |
-

|
| 47 |
-
|
| 48 |
-
### Key Findings
|
| 49 |
-
|
| 50 |
-
- **Feasibility threshold shift:**
|
| 51 |
-
Baseline requires ~6000 memory, while quantized memory achieves full compliance at ~3000.
|
| 52 |
-
|
| 53 |
-
- **2Γ efficiency gain:**
|
| 54 |
-
Compression halves the memory required for feasible operation.
|
| 55 |
-
|
| 56 |
-
- **No-regret behavior:**
|
| 57 |
-
Under no memory pressure, both methods perform identically.
|
| 58 |
-
|
| 59 |
-
- **Constraint robustness:**
|
| 60 |
-
Under tight budgets, baseline fails (0% compliance) while quantized memory remains fully feasible (100%).
|
| 61 |
-
|
| 62 |
-
**Conclusion:** Compression extends the feasible operating regime without degrading task performance.
|
| 63 |
-
|
| 64 |
-
## Structure
|
| 65 |
-
|
| 66 |
-
- `env/`: core environment logic, models, scoring, reward
|
| 67 |
-
- includes `quantizer.py` with rotated vector quantization primitives
|
| 68 |
-
- `server/`: FastAPI app exposing `reset`, `step`, `state`
|
| 69 |
-
- `tasks/`: JSON task definitions by difficulty
|
| 70 |
-
- `baseline/`: non-LLM heuristic policy
|
| 71 |
-
- `baselines/`: research evaluation baselines for `workflow_twin`
|
| 72 |
-
- `inference.py`: local rollout entrypoint
|
| 73 |
-
- `openenv.yaml`: environment spec
|
| 74 |
-
|
| 75 |
-
## Quickstart
|
| 76 |
-
|
| 77 |
-
```bash
|
| 78 |
-
python -m venv .venv
|
| 79 |
-
source .venv/bin/activate
|
| 80 |
-
pip install -r requirements.txt
|
| 81 |
-
uvicorn server.app:app --reload
|
| 82 |
-
```
|
| 83 |
-
|
| 84 |
-
Server endpoints:
|
| 85 |
-
|
| 86 |
-
- `POST /reset`
|
| 87 |
-
- `POST /step` with body `{ "action_type": "triage|respond|resolve|escalate", "note": "..." }`
|
| 88 |
-
- `GET /state`
|
| 89 |
-
- `GET /config` (resolved runtime config loaded from env vars)
|
| 90 |
-
|
| 91 |
-
Run baseline inference:
|
| 92 |
-
|
| 93 |
-
```bash
|
| 94 |
-
python inference.py
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
Inference environment variables:
|
| 98 |
-
|
| 99 |
-
- `API_BASE_URL`: OpenAI-compatible endpoint base URL
|
| 100 |
-
- `HF_TOKEN`: API token (used as `api_key`)
|
| 101 |
-
- `MODEL_NAME`: chat model name (default: `gpt-4o-mini`)
|
| 102 |
-
|
| 103 |
-
If `API_BASE_URL` or `HF_TOKEN` is missing, inference automatically falls back to heuristic policy.
|
| 104 |
-
|
| 105 |
-
`inference.py` result fields:
|
| 106 |
-
|
| 107 |
-
- `score`: final reported score (`env_score` when available, otherwise `partial_score`)
|
| 108 |
-
- `env_score`: environment-provided score from `env.state()`
|
| 109 |
-
- `partial_score`: fallback score from normalized accumulated reward
|
| 110 |
-
- `openai_client_configured`: `true` when both `API_BASE_URL` and `HF_TOKEN` are present
|
| 111 |
-
|
| 112 |
-
## Method: Quantized Memory Policy
|
| 113 |
-
|
| 114 |
-
We implement a rotated vector quantization pipeline:
|
| 115 |
-
|
| 116 |
-
1. **Random Orthogonal Projection**
|
| 117 |
-
- decorrelates embedding dimensions
|
| 118 |
-
|
| 119 |
-
2. **Scalar Quantization**
|
| 120 |
-
- coordinate-wise discretization
|
| 121 |
-
|
| 122 |
-
3. **Residual Random Projection Sketch**
|
| 123 |
-
- preserves inner-product structure
|
| 124 |
-
|
| 125 |
-
Reward shaping includes:
|
| 126 |
-
- distortion penalty (MSE)
|
| 127 |
-
- inner-product preservation penalty
|
| 128 |
-
|
| 129 |
-
## Research-Grade WorkflowTwin (L1-L5)
|
| 130 |
-
|
| 131 |
-
A new package `workflow_twin/` is now implemented to evolve the simulator from single-ticket MVP to multi-ticket workflow research environment.
|
| 132 |
-
|
| 133 |
-
### Included
|
| 134 |
-
|
| 135 |
-
- `workflow_twin/core/entities.py`: multi-ticket state, agents, time, SLA/resource fields
|
| 136 |
-
- `workflow_twin/core/dynamics.py`: queue logic, SLA penalties, dependencies, stochastic arrivals/failures
|
| 137 |
-
- `workflow_twin/core/config.py`: level configs (L1-L5)
|
| 138 |
-
- `workflow_twin/environment.py`: main level-aware environment (`WorkflowTwinEnv`)
|
| 139 |
-
- `workflow_twin/memory.py`: `MemoryBoundedEnv` wrapper using rotated quantized memory compression
|
| 140 |
-
- `workflow_twin/levels/`: level hooks for L1 simple β L5 memory pressure
|
| 141 |
-
- `baselines/heuristics.py`: simple queue baseline policy
|
| 142 |
-
- `tasks/level1..level5/`: task scaffolding per level
|
| 143 |
-
|
| 144 |
-
### Quick Example
|
| 145 |
-
|
| 146 |
-
```bash
|
| 147 |
-
python - <<'PY'
|
| 148 |
-
from workflow_twin.environment import WorkflowTwinEnv
|
| 149 |
-
from baselines.heuristics import greedy_queue_policy
|
| 150 |
-
|
| 151 |
-
env = WorkflowTwinEnv(level=3, seed=42)
|
| 152 |
-
obs = env.reset()
|
| 153 |
-
|
| 154 |
-
for _ in range(10):
|
| 155 |
-
action = greedy_queue_policy(obs)
|
| 156 |
-
obs, reward, done, info = env.step(action)
|
| 157 |
-
print(info["step_count"], reward, info["queue"])
|
| 158 |
-
if done:
|
| 159 |
-
break
|
| 160 |
-
PY
|
| 161 |
-
```
|
| 162 |
-
|
| 163 |
-
### Memory-Bounded Wrapper Example (L5)
|
| 164 |
-
|
| 165 |
-
```bash
|
| 166 |
-
python - <<'PY'
|
| 167 |
-
from workflow_twin.environment import WorkflowTwinEnv
|
| 168 |
-
from workflow_twin.memory import MemoryBoundedEnv
|
| 169 |
-
|
| 170 |
-
base_env = WorkflowTwinEnv(level=5, seed=42)
|
| 171 |
-
env = MemoryBoundedEnv(base_env, memory_budget=3500, bits=3)
|
| 172 |
-
obs = env.reset()
|
| 173 |
-
obs, reward, done, info = env.step({"action_type": "triage", "note": "memory-check"})
|
| 174 |
-
print(info["memory"])
|
| 175 |
-
PY
|
| 176 |
-
```
|
| 177 |
-
|
| 178 |
-
## Docker
|
| 179 |
-
|
| 180 |
-
```bash
|
| 181 |
-
docker build -t workflowtwin .
|
| 182 |
-
docker run -p 8000:8000 workflowtwin
|
| 183 |
-
```
|
| 184 |
-
|
| 185 |
-
## Controlled A/B Quantized Memory Evaluation
|
| 186 |
-
|
| 187 |
-
Run the controlled experiment suite:
|
| 188 |
-
|
| 189 |
-
```bash
|
| 190 |
-
python -m experiments.ab_quantized_memory_eval
|
| 191 |
-
```
|
| 192 |
-
|
| 193 |
-
This executes two tests with shared metrics:
|
| 194 |
-
|
| 195 |
-
- control_no_memory_pressure (Level 1, large memory budget)
|
| 196 |
-
- critical_memory_constrained_long_horizon (Level 5, tight memory budget)
|
| 197 |
-
- memory_budget_sweep (budgets: 2000, 3000, 4000, 6000)
|
| 198 |
-
|
| 199 |
-
Modes compared:
|
| 200 |
-
|
| 201 |
-
- baseline: no compression, truncation under pressure
|
| 202 |
-
- quant: rotated quantized memory compression under pressure
|
| 203 |
-
|
| 204 |
-
Reported metrics:
|
| 205 |
-
|
| 206 |
-
- avg_reward
|
| 207 |
-
- success_rate (resolved/total)
|
| 208 |
-
- avg_sla_violations
|
| 209 |
-
- avg_memory_used vs avg_memory_budget
|
| 210 |
-
- memory_compliance_rate
|
| 211 |
-
- steps_per_sec
|
| 212 |
-
|
| 213 |
-
Figure (generated by the experiment runner):
|
| 214 |
-
|
| 215 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{workflowTwin/workflow_twin β workflow_twin}/.DS_Store
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/__init__.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/core/__init__.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/core/config.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/core/dynamics.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/core/entities.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/environment.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/levels/__init__.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/levels/level1_simple.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/levels/level2_sla.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/levels/level3_approval.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/levels/level4_stochastic.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/levels/level5_memory.py
RENAMED
|
File without changes
|
{workflowTwin/workflow_twin β workflow_twin}/memory.py
RENAMED
|
File without changes
|