File size: 18,668 Bytes
a6a905d
07b5b16
a6a905d
07b5b16
584929d
a6a905d
 
07b5b16
 
 
 
 
 
a6a905d
4719066
da84c63
4719066
2dfdd72
4719066
da84c63
4719066
2dfdd72
 
 
 
 
 
20dbdae
2dfdd72
a4ae42b
 
 
2dfdd72
 
 
8d77f52
 
da84c63
4719066
a4ae42b
4719066
da84c63
 
 
 
 
4719066
 
 
2dfdd72
 
 
 
 
 
 
 
 
 
da84c63
4719066
da84c63
 
2dfdd72
 
 
 
 
da84c63
4719066
da84c63
4719066
2dfdd72
1c4a544
2dfdd72
1c4a544
 
 
2dfdd72
 
 
 
1c4a544
2dfdd72
 
 
 
 
 
 
1c4a544
2dfdd72
1c4a544
2dfdd72
 
 
1c4a544
 
 
2dfdd72
 
1c4a544
2dfdd72
1c4a544
2dfdd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4719066
 
 
 
 
da84c63
 
 
 
 
 
 
 
2dfdd72
 
 
 
da84c63
4719066
2dfdd72
 
 
 
 
 
 
 
 
 
 
 
 
4719066
 
 
 
 
 
da84c63
 
 
 
 
 
 
4719066
 
 
da84c63
4719066
2dfdd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d77f52
2dfdd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c4a544
 
 
da84c63
4719066
 
da84c63
4719066
 
da84c63
4719066
 
da84c63
 
 
 
4719066
da84c63
 
 
 
 
4719066
 
da84c63
4719066
 
da84c63
 
4719066
 
 
 
 
da84c63
4719066
da84c63
 
 
 
2dfdd72
 
 
 
da84c63
 
 
 
 
 
 
2dfdd72
da84c63
 
2dfdd72
 
da84c63
 
4719066
2dfdd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
08a8230
2dfdd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fe119f
2dfdd72
 
5fe119f
2dfdd72
 
5fe119f
2dfdd72
 
 
 
da84c63
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
---
title: OrgOS Enterprise Workflow RL Environment
emoji: 🏒
colorFrom: indigo
colorTo: blue
sdk: docker
pinned: false
app_port: 8000
tags:
  - openenv
  - rl
  - enterprise
  - multi-app
---

# OrgOS β€” Enterprise Workflow RL Environment

**OrgOS** is a multi-app enterprise reinforcement learning environment where an AI agent completes real business workflows across four interconnected SaaS applications. Between episodes the environment injects **schema drift** (renamed API fields) and **policy changes** (tightened SLAs and approval thresholds), forcing agents to generalize rather than memorize.

Built for the [Meta PyTorch Γ— Scaler OpenEnv Hackathon](https://huggingface.co/) β€” targeting the **Multi-App Enterprise Workflow** sub-theme.

---

## Resources

| | |
|---|---|
| Environment Space | **[huggingface.co/spaces/srishtichugh/orgOS](https://huggingface.co/spaces/srishtichugh/orgOS)** |
| Training Space | **[huggingface.co/spaces/muskansingh1101/orgos-training](https://huggingface.co/spaces/muskansingh1101/orgos-training)** |
| HF Blog Post | **[OrgOS: Teaching Agents to Survive Enterprise API Drift](https://huggingface.co/spaces/srishtichugh/orgOS/blob/main/hf_blog_post.md)** |
| Training Notebook | **[training/grpo_orgos.ipynb](https://colab.research.google.com/drive/1BekDqh64FU0kskSnaNrFU8HEkcdexPC3?usp=sharing)** |
| Training Logs | **[training/grpo_orgos.ipynb](https://github.com/Tanvi51204/OpenEnv-Round-2/tree/main/training/orgos-training)** |
| Youtube Demo Video| **[]()** |


---

## Live Demo

πŸš€ **[HuggingFace Space β†’](https://huggingface.co/spaces/srishtichugh/orgOS)**

```bash
# Local quickstart
uvicorn server.app:app --host 0.0.0.0 --port 8000
# Open http://localhost:8000 for the live dashboard
```

---

## The Problem OrgOS Solves

Real enterprise AI agents don't fail because the model is bad β€” they fail because the environment keeps changing. SaaS APIs rename fields across versions. SLA policies tighten after incidents. Access controls shift when team structures change.

An agent trained on a static dataset will memorize field names like `priority`, `assignee`, `deal_stage`. But in production, those same fields become `severity`, `owner`, and `pipeline_stage`. The agent breaks silently β€” it still runs, but its actions fail schema validation and real work never gets done.

OrgOS simulates this exactly. Every episode, the agent faces the same four apps with **different field names** and potentially **different SLA rules**. The only path to a high score is reading the `schema_hints` observation and the `active_rules` dict before acting β€” then using the *current* field names, not the ones it saw in training.

---

## What Makes OrgOS Unique

| Feature | Description |
|---|---|
| **4 Mock SaaS Apps** | Jira, Zendesk, Salesforce, Workday β€” each with realistic CRUD operations |
| **Schema Drift** | Fields rename between episodes across 3 versioned schemas per app. Agent gets `-0.20` for stale names, `+0.10` for adapted names |
| **Policy Drift** | Every 3rd episode, SLA thresholds tighten automatically (P0: 30 min β†’ 15 min, P1: 4 h β†’ 2 h) |
| **3 Workflows** | Cross-app tasks that require correct sequencing and state carry-over between steps |
| **RBAC** | Support vs. manager roles strictly enforced; `-0.25` penalty for unauthorized actions |
| **Dense Reward** | Per-step composite signal tied to 5 measurable business outcomes |

---

## The Three Workflows

Each workflow tests a different capability: information discovery, state threading between apps, and schema-aware field usage. All three run against the same four apps but require different operation sequences and roles.

---

### Workflow A β€” Customer Bug Fix
**Role:** `support` | **Steps:** 5 | **Step budget:** 15

A P1 bug has been escalated through the support queue. The agent must move it end-to-end: from acknowledging the ticket in Zendesk, through creating and assigning a Jira issue, to verifying account health in Salesforce and logging SLA compliance in Workday.

| Step | App | Operation | What Must Happen |
|---|---|---|---|
| A1 | Zendesk | `acknowledge_ticket` | Find and acknowledge the new P1 ticket |
| A2 | Jira | `create_issue` | Create a new issue **linked** to that Zendesk ticket |
| A3 | Salesforce | `get_account` | Verify the customer's account status |
| A4 | Jira | `assign_owner` | Assign the **same** issue created in A2 to an engineer |
| A5 | Workday | `log_sla_event` | Log SLA compliance using the ticket ID |

**Why it's hard:** Steps must happen in order β€” the Jira issue created in A2 must be the one assigned in A4. The agent can't shortcut by assigning an unrelated issue. Schema drift hits Zendesk's `urgency`/`state` fields and Jira's `priority`/`assignee` fields.

**What an untrained agent does:** Calls `list_tickets` in a loop, uses canonical field name `priority` (stale on v2/v3 schemas), gets `-0.20` schema error, never advances past A1.

**What a trained agent does:** Reads `schema_hints` first (e.g. `jira.priority β†’ severity`), calls `acknowledge_ticket` with correct args, threads the ticket ID through to Jira's `create_issue`, then `assign_owner` on the same issue ID.

---

### Workflow B β€” Employee Onboarding
**Role:** `manager` | **Steps:** 4 | **Step budget:** 20

A new hire is in Workday with `status=pending`. The manager-role agent must complete their onboarding across all four apps β€” and each step's output feeds the next. The agent must carry `employee_id` and `territory` from step B1 through to B3 and B4.

| Step | App | Operation | What Must Happen |
|---|---|---|---|
| B1 | Workday | `create_onboarding_task` | Find the pending employee and create their onboarding record |
| B2 | Workday | `provision_access` | Provision **Jira** access for that specific `employee_id` |
| B3 | Salesforce | `assign_account_owner` | Assign the new hire as owner of an account **in their own territory** |
| B4 | Jira | `assign_owner` | Assign an open Jira issue to the new hire's `employee_id` |

**Why it's hard:** This is a state-threading problem. There's only one pending employee in Workday, but the agent must discover them via `list_employees` with `status=pending`, extract their `employee_id` and `territory`, then pass those values correctly into B3 (Salesforce territory filter) and B4 (Jira assignee). Hardcoding any ID will fail β€” the data generator seeds differently each episode.

**RBAC note:** Only `manager` role has full access to all four apps. A `support` agent attempting Workday's `provision_access` or Salesforce's `assign_account_owner` incurs a `-0.25` penalty per violation.

**What an untrained agent does:** Tries to call `create_onboarding_task` directly without listing first, passes wrong `employee_id`, then attempts `assign_account_owner` on a random account (wrong territory β†’ step B3 fails completion check).

**What a trained agent does:** Calls `list_employees` with `status=pending` β†’ extracts `employee_id` + `territory` β†’ threads them correctly into all downstream steps.

---

### Workflow C β€” Churn Risk Alert
**Role:** `support` | **Steps:** 4 | **Step budget:** 18

An enterprise account is showing churn signals. The agent must identify it in Salesforce, assess the account's support history and open bugs, then assign an intervention owner. The challenge: the at-risk account's ID changes each episode and must be discovered dynamically.

| Step | App | Operation | What Must Happen |
|---|---|---|---|
| C1 | Salesforce | `flag_churn_risk` | Identify and flag the at-risk account |
| C2 | Zendesk | `get_ticket` | Query support tickets **for the churn account's ID** (from C1) |
| C3 | Jira | `list_issues` | List open bugs **with `customer_id=<churn account>`** (from C1) |
| C4 | Salesforce | `assign_account_owner` | Assign an intervention owner to the at-risk account |

**Why it's hard:** Steps C2 and C3 require passing the `account_id` discovered in C1 as a filter argument. A hardcoded ID (or no filter) fails the completion check. Salesforce's `health`/`owner`/`deal_stage` fields drift across schema versions, so the agent must use the current names when calling `flag_churn_risk`.

**Why it scores lowest for untrained agents (0.25):** Schema drift hits Salesforce hardest β€” three fields rename simultaneously between v1/v2/v3. The untrained model almost never uses the right field names on the first call, burning half its step budget on schema errors before discovering C1's output is needed in C2 and C3.

**What a trained agent does:** Reads `schema_hints` to find current Salesforce field names β†’ calls `flag_churn_risk` correctly β†’ extracts the returned `account_id` β†’ uses it as the filter in both the Zendesk query and Jira `list_issues` call.

---

## Schema Drift β€” Deep Dive

Each episode, the schema drift engine samples an independent schema version (v1/v2/v3) for each app. v1 uses canonical field names (no drift). v2 and v3 rename fields.

| App | Canonical | v2 | v3 |
|---|---|---|---|
| **Jira** | `priority` | `severity` | `urgency_level` |
| **Jira** | `assignee` | `owner` | `assigned_to` |
| **Jira** | `status` | `state` | `current_state` |
| **Zendesk** | `urgency` | `priority` | `impact_level` |
| **Zendesk** | `agent_email` | `handler` | `assigned_agent` |
| **Salesforce** | `deal_stage` | `pipeline_stage` | `stage` |
| **Salesforce** | `health` | `account_health` | `risk_score` |
| **Salesforce** | `owner` | `account_owner` | `rep_email` |
| **Workday** | `level` | `job_level` | `seniority` |
| **Workday** | `manager_id` | `reports_to` | `direct_manager` |

The observation includes **one schema hint** per episode (e.g. `{"jira.priority": "severity"}`). The agent must use `get_*` and `list_*` operations to discover the rest of the drift by reading what the app returns.

**Reward signals:**
- Using a stale canonical field name: **-0.20**
- Using the correct drifted field name: **+0.10**
- v1 schema (no drift): no penalty, no credit

---

## Policy Drift

Every 3rd episode, SLAs tighten:

| Rule | Default | After Policy Drift |
|---|---|---|
| P0 acknowledgement | 30 min | **15 min** |
| P1 first response | 4 hours | **2 hours** |
| Budget approval threshold | $10,000 | **$5,000** |

Since each environment step simulates ~10 minutes of elapsed time, under policy drift a P0 ticket must be acknowledged within the first **step** β€” not the first few steps. The agent sees the current thresholds in `active_rules` on every observation.

---

## Reward Function

```
score = 0.30 Γ— workflow_completion
      + 0.25 Γ— rule_compliance
      + 0.20 Γ— schema_adaptation
      + 0.15 Γ— efficiency
      + 0.10 Γ— policy_drift_handling

Per-step delta = new_score βˆ’ old_score
Schema error penalty     = βˆ’0.20  (stale field name used)
RBAC violation penalty   = βˆ’0.25  (unauthorized operation)
SLA breach penalty       = βˆ’0.10 to βˆ’0.15
Terminal completion bonus = +0.20  (all workflow steps done)
```

`efficiency` only increases when a **new workflow step is completed** β€” padding with repeated `list_*` calls doesn't help. This is what makes single-step reward exploitation hard and why the multi-step reward function in training is critical.

---

## Applications & Operations

| App | Key Operations |
|---|---|
| **Jira** | `get_issue`, `create_issue`, `update_status`, `set_priority`, `assign_owner`, `link_zendesk_ticket`, `close_issue`, `list_issues` |
| **Zendesk** | `get_ticket`, `acknowledge_ticket`, `set_urgency`, `assign_agent`, `escalate_to_jira`, `resolve_ticket`, `add_note`, `list_tickets` |
| **Salesforce** | `get_account`, `list_accounts`, `update_deal_stage`, `flag_churn_risk`, `assign_account_owner`, `log_interaction`, `get_opportunity` |
| **Workday** | `get_employee`, `list_employees`, `provision_access`, `log_sla_event`, `request_budget_approval`, `create_onboarding_task`, `complete_task` |

---

## API Endpoints

| Method | Path | Description |
|---|---|---|
| `GET` | `/health` | Health check |
| `POST` | `/reset` | Start new episode (`{"workflow_id": "A"\|"B"\|"C"}`) |
| `POST` | `/step` | Take action (`{"app": ..., "operation": ..., "args": {...}}`) |
| `GET` | `/state` | Current episode metadata |
| `GET` | `/schema/apps` | All app operations catalogue |
| `GET` | `/docs` | Swagger UI |
| `GET` | `/` | Live dashboard (UI) |

---

## Training

The [`training/grpo_orgos.ipynb`](training/grpo_orgos.ipynb) notebook trains **Qwen2.5-3B-Instruct** with **Unsloth 4-bit LoRA** using **HF TRL GRPOTrainer** (150 GRPO steps, multi-step reward, checkpoints every 30 steps).

Also runnable as a live HF Space: **[muskansingh1101/orgos-training](https://huggingface.co/spaces/muskansingh1101/orgos-training)**

### What Training Teaches the Agent

The key behavioral changes GRPO induces:

1. **Schema awareness** β€” the agent learns to read `schema_hints` in the observation before constructing action args. Before training it ignores hints and uses canonical names; after training it uses the drifted names.

2. **Step sequencing** β€” the agent learns to follow `pending_steps` in order. Before training it calls operations randomly; after training it completes A1 before attempting A2, and carries state (IDs) from earlier steps forward.

3. **Discovery before action** β€” the agent learns to call `list_*` or `get_*` first to discover record IDs, rather than guessing or hardcoding them.

### Results

| Workflow | Before GRPO | After GRPO | Ξ” |
|---|---|---|---|
| A β€” Customer Bug Fix | 0.70 | ~0.82 | +0.12 |
| B β€” Employee Onboarding | 0.57 | ~0.74 | +0.17 |
| C β€” Churn Risk Alert | 0.25 | ~0.48 | +0.23 |
| **Average** | **0.50** | **~0.68** | **+0.18** |

The largest gain is on Workflow C β€” the most schema-sensitive workflow (Salesforce has 3 drifting fields simultaneously). The untrained model almost never makes it past C1; the trained model completes C1β†’C2β†’C3 reliably.

![Training Curve](training/plots/training_curve.png)
*Reward per training step β€” 150 GRPO steps on Qwen2.5-3B-Instruct*

![Baseline vs Trained](training/plots/baseline_vs_trained.png)
*Per-workflow score: untrained baseline vs. GRPO-trained agent*

![Score Distribution](training/plots/score_distribution.png)
*Distribution of episode scores before and after training*

---

## Action / Observation Format

**Action:**
```json
{"app": "zendesk", "operation": "acknowledge_ticket", "args": {"ticket_number": "ZD-001"}}
```

**Observation (key fields):**
```json
{
  "workflow_goal": "Workflow A β€” Customer Bug Fix: A P1 bug has been escalated...",
  "pending_steps": ["Assign the Jira issue you just created to an engineer", "Log the SLA compliance event in Workday"],
  "completed_steps": ["A1", "A2", "A3"],
  "schema_hints": {"jira.priority": "severity"},
  "active_rules": {"sla_p0_minutes": 15, "sla_p1_hours": 2, "approval_threshold": 5000},
  "current_score": 0.42,
  "message": "Jira issue JI-001 created and linked to ZD-001"
}
```

---

## Local Setup

```bash
# 1. Install dependencies
pip install -r requirements.txt

# 2. Start server
uvicorn server.app:app --host 0.0.0.0 --port 8000

# 3. Run baseline inference (requires LLM API)
export API_BASE_URL=https://api.openai.com/v1
export MODEL_NAME=gpt-4o-mini
python inference.py

# 4. Or use the Python client
from client import OrgOSEnvClient
client = OrgOSEnvClient("http://localhost:8000")
result = client.reset(workflow_id="A")
print(result.observation.workflow_goal)
```

## Docker

```bash
docker build -t orgos-env .
docker run -p 8000:8000 orgos-env
```

---

## Project Structure

```
openEnv/
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ app.py              # FastAPI routes (15 endpoints)
β”‚   β”œβ”€β”€ environment.py      # OrgOSEnvironment β€” reset/step/state
β”‚   β”œβ”€β”€ schema_drift.py     # Per-episode field renames (3 versions per app)
β”‚   β”œβ”€β”€ business_rules.py   # RBAC + SLA enforcement + policy drift
β”‚   β”œβ”€β”€ workflow_engine.py  # 3 cross-app workflow definitions + completion checks
β”‚   β”œβ”€β”€ data_generator.py   # Synthetic data (seed=42 + episode_num)
β”‚   └── apps/
β”‚       β”œβ”€β”€ jira.py
β”‚       β”œβ”€β”€ zendesk.py
β”‚       β”œβ”€β”€ salesforce.py
β”‚       └── workday.py
β”œβ”€β”€ models.py               # Pydantic models
β”œβ”€β”€ client.py               # OrgOSEnvClient
β”œβ”€β”€ inference.py            # Baseline inference loop
β”œβ”€β”€ ui/index.html           # Live dashboard (Tailwind + Alpine.js + Chart.js)
β”œβ”€β”€ training/
β”‚   β”œβ”€β”€ grpo_orgos.ipynb   # GRPO training notebook (Colab-ready)
β”‚   └── plots/             # Training result plots
β”œβ”€β”€ openenv.yaml            # OpenEnv manifest
└── Dockerfile
```
---
title: Orgos Training
emoji: πŸ†
colorFrom: red
colorTo: pink
sdk: docker
pinned: false
---

# OrgOS β€” GRPO Training Space (can be found deployed at HF : )

This Space trains **Qwen2.5-3B-Instruct** with **Unsloth 4-bit LoRA** using **HF TRL GRPOTrainer** on the OrgOS enterprise workflow RL environment.

---

## What Is OrgOS?

OrgOS is a multi-app enterprise RL environment where an AI agent completes real business workflows across four interconnected SaaS apps (Jira, Zendesk, Salesforce, Workday). Between episodes the environment injects **schema drift** (renamed fields) and **policy changes** (tightened SLAs), forcing agents to generalize rather than memorize.

🌐 **[Environment Space β†’](https://huggingface.co/spaces/muskansingh1101/orgos-training)**

---

## Training Setup

| Config | Value |
|---|---|
| **Model** | Qwen2.5-3B-Instruct (4-bit via Unsloth) |
| **Algorithm** | GRPO (Generalized Reward Policy Optimization) |
| **LoRA rank** | r=16 |
| **Steps** | 150 |
| **Batch size** | 1 (grad accum 2) |
| **Learning rate** | 8e-6 |
| **Reward** | Multi-step (2 steps per sample) |
| **Checkpoints** | Every 30 steps to Drive |

The reward function combines 5 components: workflow completion (0.30), rule compliance (0.25), schema adaptation (0.20), efficiency (0.15), policy drift handling (0.10).

---

## Results

| Workflow | Before GRPO | After GRPO | Ξ” |
|---|---|---|---|
| A β€” Customer Bug Fix | 0.70 | ~0.82 | +0.12 |
| B β€” Employee Onboarding | 0.57 | ~0.74 | +0.17 |
| C β€” Churn Risk Alert | 0.25 | ~0.48 | +0.23 |
| **Average** | **0.50** | **~0.68** | **+0.18** |

![Training Curve](training/plots/training_curve.png)
*Reward per training step*

![Baseline vs Trained](training/plots/baseline_vs_trained.png)
*Per-workflow score comparison*

![Score Distribution](training/plots/score_distribution.png)
*Episode score distribution before and after GRPO*

---

MIT License Β· Built for Meta PyTorch Γ— Scaler OpenEnv Hackathon Round 2