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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HCM:21 Usage Guide
|
| 2 |
+
|
| 3 |
+
How to run, explore, and demo the HCM:21 environment.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 1. Live HuggingFace Space
|
| 8 |
+
|
| 9 |
+
The environment is deployed and running at:
|
| 10 |
+
|
| 11 |
+
**https://paretooptimal-hcm21.hf.space**
|
| 12 |
+
|
| 13 |
+
No setup required β open a browser and start interacting immediately.
|
| 14 |
+
|
| 15 |
+
| Endpoint | URL | Purpose |
|
| 16 |
+
|----------|-----|---------|
|
| 17 |
+
| Web Interface | [/web](https://paretooptimal-hcm21.hf.space/web) | Interactive dashboard for manual play |
|
| 18 |
+
| API Docs | [/docs](https://paretooptimal-hcm21.hf.space/docs) | Swagger UI with all endpoints |
|
| 19 |
+
| Health Check | [/health](https://paretooptimal-hcm21.hf.space/health) | Returns `{"status":"healthy"}` |
|
| 20 |
+
| Schema | [/schema](https://paretooptimal-hcm21.hf.space/schema) | Action/Observation/State JSON schemas |
|
| 21 |
+
| Metadata | [/metadata](https://paretooptimal-hcm21.hf.space/metadata) | Environment name, version, description |
|
| 22 |
+
|
| 23 |
+
> **Note:** If the Space has been idle, it may take 30-60 seconds to wake up on first request.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## 2. Web Interface β Best Demo Experience
|
| 28 |
+
|
| 29 |
+
Open **https://paretooptimal-hcm21.hf.space/web** for the interactive dashboard.
|
| 30 |
+
|
| 31 |
+
### Layout
|
| 32 |
+
|
| 33 |
+
The interface is a split-pane design:
|
| 34 |
+
|
| 35 |
+
- **Left pane** β Action controls: buttons to Reset/Step/Get State, plus a form to build actions
|
| 36 |
+
- **Right pane** β Observations: current state, JSON observation display, and a scrollable action history log
|
| 37 |
+
|
| 38 |
+
### Recommended Demo Walkthrough
|
| 39 |
+
|
| 40 |
+
Follow this sequence to showcase all four HCM:21 phases in a single quarter:
|
| 41 |
+
|
| 42 |
+
#### Step 1: Reset the Environment
|
| 43 |
+
|
| 44 |
+
Click **Reset Environment**. You'll see the initial observation with company data β 300 employees across 5 departments, baseline HCVA/HCROI metrics, and available scanning actions.
|
| 45 |
+
|
| 46 |
+
#### Step 2: Scanning Phase (gather intelligence)
|
| 47 |
+
|
| 48 |
+
Submit these actions using the form (set **Action Type** dropdown, fill relevant fields, click **Step**):
|
| 49 |
+
|
| 50 |
+
| # | Action Type | Department | Metric Name | What You'll See |
|
| 51 |
+
|---|------------|------------|-------------|-----------------|
|
| 52 |
+
| 1 | `query_department` | Engineering | β | Headcount, avg salary, avg performance, flight risk |
|
| 53 |
+
| 2 | `query_department` | Sales | β | Same metrics for Sales |
|
| 54 |
+
| 3 | `calculate_metric` | β | hcva | Human Capital Value Added across the company |
|
| 55 |
+
| 4 | `review_financials` | β | β | Revenue, employment costs, HR budget, P&L |
|
| 56 |
+
|
| 57 |
+
> After 2+ scanning actions, `advance_phase` becomes available.
|
| 58 |
+
|
| 59 |
+
#### Step 3: Advance to Planning
|
| 60 |
+
|
| 61 |
+
| # | Action Type | Notes |
|
| 62 |
+
|---|------------|-------|
|
| 63 |
+
| 5 | `advance_phase` | Moves from Scanning β Planning |
|
| 64 |
+
|
| 65 |
+
#### Step 4: Planning Phase (set strategy)
|
| 66 |
+
|
| 67 |
+
| # | Action Type | Department | Amount/Count | What It Does |
|
| 68 |
+
|---|------------|------------|--------------|--------------|
|
| 69 |
+
| 6 | `set_hiring_target` | Engineering | count: 3 | Plan to hire 3 engineers |
|
| 70 |
+
| 7 | `set_training_budget` | Engineering | amount: 50000 | Allocate $50K for engineering L&D |
|
| 71 |
+
| 8 | `set_compensation_policy` | Sales | amount: 3.0 | 3% salary adjustment for Sales |
|
| 72 |
+
| 9 | `set_retention_program` | Engineering | amount: 20000 | $20K retention initiative |
|
| 73 |
+
|
| 74 |
+
#### Step 5: Advance to Producing
|
| 75 |
+
|
| 76 |
+
| # | Action Type |
|
| 77 |
+
|---|------------|
|
| 78 |
+
| 10 | `advance_phase` |
|
| 79 |
+
|
| 80 |
+
#### Step 6: Producing Phase (execute decisions)
|
| 81 |
+
|
| 82 |
+
| # | Action Type | Department | Amount/Count |
|
| 83 |
+
|---|------------|------------|--------------|
|
| 84 |
+
| 11 | `execute_hiring` | Engineering | count: 3 |
|
| 85 |
+
| 12 | `execute_training` | Engineering | amount: 20 (hours) |
|
| 86 |
+
|
| 87 |
+
#### Step 7: Advance to Controlling
|
| 88 |
+
|
| 89 |
+
| # | Action Type |
|
| 90 |
+
|---|------------|
|
| 91 |
+
| 13 | `advance_phase` |
|
| 92 |
+
|
| 93 |
+
#### Step 8: Controlling Phase (measure & advance)
|
| 94 |
+
|
| 95 |
+
| # | Action Type | What Happens |
|
| 96 |
+
|---|------------|--------------|
|
| 97 |
+
| 14 | `submit_report` | Quarterly HR report with metric changes |
|
| 98 |
+
| 15 | `advance_quarter` | Quarter ends, reward computed, stochastic events may fire |
|
| 99 |
+
|
| 100 |
+
**Watch the right pane** β the observation after `advance_quarter` shows:
|
| 101 |
+
- The quarterly reward (e.g., 0.2374)
|
| 102 |
+
- Any stochastic events that fired (market downturn, competitor poaching, etc.)
|
| 103 |
+
- Updated metrics and available actions for the next quarter
|
| 104 |
+
|
| 105 |
+
Repeat for all 6 quarters to complete a full episode. The final `advance_quarter` in Q6 returns the episode score (0-1).
|
| 106 |
+
|
| 107 |
+
### What to Point Out During a Demo
|
| 108 |
+
|
| 109 |
+
- **Phase enforcement**: Try submitting `execute_hiring` during Scanning β it will be rejected. The HCM:21 cycle (Scan β Plan β Produce β Control) is enforced.
|
| 110 |
+
- **Sparse rewards**: Rewards only appear at quarter boundaries via `advance_quarter`. No intermediate feedback.
|
| 111 |
+
- **Stochastic events**: Each quarter, 0-2 random events fire (market crash, exec departure, competitor poaching). Watch how they cascade.
|
| 112 |
+
- **Growing state**: Click **Get State** to see the full state object grow with metric history, active initiatives, and event logs across quarters.
|
| 113 |
+
- **Score calibration**: Random agents score ~0.15-0.25. A thoughtful human playing through the web UI should reach 0.40-0.60.
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## 3. Running Locally
|
| 118 |
+
|
| 119 |
+
### Option A: Python (development)
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
# Clone and install
|
| 123 |
+
git clone https://github.com/n8mauer/HCM-21.git
|
| 124 |
+
cd HCM-21
|
| 125 |
+
pip install -e ".[server]"
|
| 126 |
+
|
| 127 |
+
# Start the server
|
| 128 |
+
uvicorn hr_env.server.app:app --host 0.0.0.0 --port 8000
|
| 129 |
+
|
| 130 |
+
# Open the web interface
|
| 131 |
+
# β http://localhost:8000/web
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### Option B: Docker
|
| 135 |
+
|
| 136 |
+
```bash
|
| 137 |
+
docker build -t hcm21 .
|
| 138 |
+
docker run -p 8000:8000 hcm21
|
| 139 |
+
|
| 140 |
+
# β http://localhost:8000/web
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
### Option C: OpenEnv CLI
|
| 144 |
+
|
| 145 |
+
```bash
|
| 146 |
+
pip install openenv-core
|
| 147 |
+
openenv validate # Checks compliance
|
| 148 |
+
openenv push # Deploys to HF Spaces
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
## 4. CLI Agent (Autonomous Play)
|
| 154 |
+
|
| 155 |
+
Run the sample Claude-based agent for a full autonomous 6-quarter episode:
|
| 156 |
+
|
| 157 |
+
```bash
|
| 158 |
+
# Install agent dependencies
|
| 159 |
+
pip install -e ".[agent]"
|
| 160 |
+
|
| 161 |
+
# Set your API key
|
| 162 |
+
export ANTHROPIC_API_KEY=sk-ant-...
|
| 163 |
+
|
| 164 |
+
# Run against local server
|
| 165 |
+
python -m agent.run --url ws://localhost:8000 --model claude-sonnet-4-6 --seed 42
|
| 166 |
+
|
| 167 |
+
# Or run against the live HF Space
|
| 168 |
+
python -m agent.run --url wss://paretooptimal-hcm21.hf.space --model claude-sonnet-4-6 --seed 42
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
The agent will:
|
| 172 |
+
1. Scan all departments and calculate baseline metrics
|
| 173 |
+
2. Formulate a multi-quarter strategy
|
| 174 |
+
3. Execute hiring, training, compensation, and retention decisions
|
| 175 |
+
4. Adapt to stochastic events (market crashes, competitor poaching)
|
| 176 |
+
5. Summarize each quarter to manage context window limits
|
| 177 |
+
6. Print step-by-step actions, rewards, and the final episode score
|
| 178 |
+
|
| 179 |
+
Example output:
|
| 180 |
+
```
|
| 181 |
+
Q1 Scanning | query_department Engineering | headcount: 62, avg_perf: 3.4, flight_risk: 0.18
|
| 182 |
+
Q1 Planning | set_hiring_target Engineering count=5
|
| 183 |
+
Q1 Producing | execute_hiring Engineering count=5
|
| 184 |
+
Q1 Controlling | advance_quarter | Reward: 0.2374 | Event: competitor_poaching (Sales)
|
| 185 |
+
Q2 Scanning | query_department Sales | flight_risk: 0.31 (β)
|
| 186 |
+
...
|
| 187 |
+
Final Score: 0.6847 (strong strategic agent range)
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
## 5. Training Notebook (Google Colab)
|
| 193 |
+
|
| 194 |
+
Train a small LLM to play as CHCO using reinforcement learning.
|
| 195 |
+
|
| 196 |
+
### Setup
|
| 197 |
+
|
| 198 |
+
1. Open `notebooks/hcm21_trl_training.ipynb` in Google Colab
|
| 199 |
+
2. Select **Runtime β Change runtime type β T4 GPU** (free tier works)
|
| 200 |
+
3. Run all cells
|
| 201 |
+
|
| 202 |
+
### What It Does
|
| 203 |
+
|
| 204 |
+
| Component | Detail |
|
| 205 |
+
|-----------|--------|
|
| 206 |
+
| Model | Qwen3-0.6B via Unsloth (4-bit QLoRA) |
|
| 207 |
+
| Algorithm | GRPO (Group Relative Policy Optimization) from HuggingFace TRL |
|
| 208 |
+
| Environment | Connects to the live HF Space via WebSocket |
|
| 209 |
+
| Dataset | 20 episode prompts with different seeds |
|
| 210 |
+
| Training | batch_size=2, gradient_accumulation=4, ~30 min on T4 |
|
| 211 |
+
|
| 212 |
+
### Key Cells
|
| 213 |
+
|
| 214 |
+
1. **Install Dependencies** β `pip install unsloth trl openenv-core`
|
| 215 |
+
2. **Load Model** β Qwen3-0.6B with LoRA (r=16) on all attention + MLP layers
|
| 216 |
+
3. **Environment Wrapper** β `HCM21Env` class wraps `GenericEnvClient` (WebSocket) for stateful sessions
|
| 217 |
+
4. **Training Dataset** β 20 prompts describing the CHCO role with different episode seeds
|
| 218 |
+
5. **GRPO Training** β TRL's `GRPOTrainer` with `environment_factory=HCM21Env`
|
| 219 |
+
6. **Evaluation** β Runs a full 6-quarter episode with the trained model
|
| 220 |
+
|
| 221 |
+
### Output
|
| 222 |
+
|
| 223 |
+
The trained LoRA adapter is saved to `./hcm21-agent-lora/` and can be pushed to HuggingFace Hub.
|
| 224 |
+
|
| 225 |
+
---
|
| 226 |
+
|
| 227 |
+
## 6. API Reference (Custom Integrations)
|
| 228 |
+
|
| 229 |
+
### REST Endpoints (Stateless)
|
| 230 |
+
|
| 231 |
+
> **Important:** REST endpoints are stateless β each `/step` call creates a fresh environment. Use WebSocket for multi-step episodes.
|
| 232 |
+
|
| 233 |
+
```bash
|
| 234 |
+
# Health check
|
| 235 |
+
curl https://paretooptimal-hcm21.hf.space/health
|
| 236 |
+
|
| 237 |
+
# Get action/observation schemas
|
| 238 |
+
curl https://paretooptimal-hcm21.hf.space/schema
|
| 239 |
+
|
| 240 |
+
# Reset (stateless β returns initial observation)
|
| 241 |
+
curl -X POST https://paretooptimal-hcm21.hf.space/reset \
|
| 242 |
+
-H "Content-Type: application/json" \
|
| 243 |
+
-d '{"seed": 42}'
|
| 244 |
+
|
| 245 |
+
# Step (stateless β wraps action in {"action": {...}})
|
| 246 |
+
curl -X POST https://paretooptimal-hcm21.hf.space/step \
|
| 247 |
+
-H "Content-Type: application/json" \
|
| 248 |
+
-d '{"action": {"action_type": "query_department", "department": "Engineering"}}'
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
### WebSocket (Stateful Sessions)
|
| 252 |
+
|
| 253 |
+
For multi-step episodes, use the WebSocket endpoint which maintains state across calls:
|
| 254 |
+
|
| 255 |
+
```python
|
| 256 |
+
from openenv.core import GenericEnvClient, GenericAction
|
| 257 |
+
|
| 258 |
+
client = GenericEnvClient(base_url="https://paretooptimal-hcm21.hf.space")
|
| 259 |
+
client.connect()
|
| 260 |
+
|
| 261 |
+
# Reset
|
| 262 |
+
result = client.reset(seed=42)
|
| 263 |
+
print(result.observation)
|
| 264 |
+
|
| 265 |
+
# Take actions in sequence (state persists)
|
| 266 |
+
action = GenericAction(action_type="query_department", department="Engineering")
|
| 267 |
+
result = client.step(action)
|
| 268 |
+
print(result.observation)
|
| 269 |
+
|
| 270 |
+
# Continue stepping through phases and quarters...
|
| 271 |
+
client.disconnect()
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
### Python Direct (No Server)
|
| 275 |
+
|
| 276 |
+
For local testing without a server:
|
| 277 |
+
|
| 278 |
+
```python
|
| 279 |
+
from hr_env.server.environment import HRProductivityEnvironment
|
| 280 |
+
from hr_env.models import HRAction
|
| 281 |
+
|
| 282 |
+
env = HRProductivityEnvironment()
|
| 283 |
+
obs = env.reset(seed=42)
|
| 284 |
+
print(obs.message)
|
| 285 |
+
|
| 286 |
+
# Take actions directly
|
| 287 |
+
obs = env.step(HRAction(action_type="query_department", department="Engineering"))
|
| 288 |
+
print(obs.data)
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
---
|
| 292 |
+
|
| 293 |
+
## 7. Scenario Variants
|
| 294 |
+
|
| 295 |
+
Four pre-built scenarios test different strategic challenges:
|
| 296 |
+
|
| 297 |
+
| Scenario | Seed | Challenge | Target Score |
|
| 298 |
+
|----------|------|-----------|-------------|
|
| 299 |
+
| High Turnover | 42 | Engineering hemorrhaging talent | 0.65 |
|
| 300 |
+
| Budget Cuts | 123 | HR budget slashed 50% | 0.60 |
|
| 301 |
+
| Rapid Growth | 456 | Scale workforce while maintaining quality | 0.65 |
|
| 302 |
+
| Balanced Optimization | 789 | Below-average metrics across the board | 0.60 |
|
| 303 |
+
|
| 304 |
+
Use the seed when resetting to reproduce a specific scenario:
|
| 305 |
+
|
| 306 |
+
```python
|
| 307 |
+
obs = env.reset(seed=42) # High turnover scenario
|
| 308 |
+
obs = env.reset(seed=123) # Budget cuts scenario
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
---
|
| 312 |
+
|
| 313 |
+
## Quick Reference
|
| 314 |
+
|
| 315 |
+
| What You Want | How To Do It |
|
| 316 |
+
|---------------|--------------|
|
| 317 |
+
| Try it now (no setup) | Open [/web](https://paretooptimal-hcm21.hf.space/web) in your browser |
|
| 318 |
+
| Run an AI agent | `python -m agent.run --url ws://localhost:8000` |
|
| 319 |
+
| Train a model | Open `notebooks/hcm21_trl_training.ipynb` in Colab |
|
| 320 |
+
| Build a custom agent | Use `GenericEnvClient` (WebSocket) β see Section 6 |
|
| 321 |
+
| Run locally | `pip install -e ".[server]" && uvicorn hr_env.server.app:app` |
|
| 322 |
+
| View API docs | Open [/docs](https://paretooptimal-hcm21.hf.space/docs) |
|