File size: 9,756 Bytes
1ba65c9
 
4455094
1ba65c9
 
 
 
 
 
 
 
 
4455094
1ba65c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4455094
1ba65c9
 
 
 
 
 
4455094
1ba65c9
 
 
 
4455094
 
 
1ba65c9
 
 
 
 
4455094
1ba65c9
 
 
4455094
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
 
4455094
1ba65c9
 
4455094
 
 
1ba65c9
 
 
 
 
 
 
4455094
1ba65c9
 
 
 
 
 
4455094
 
1ba65c9
4455094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ba65c9
4455094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ba65c9
 
 
 
 
 
 
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
 
4455094
 
 
 
 
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
 
 
 
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
 
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
 
1ba65c9
4455094
 
 
 
 
1ba65c9
4455094
1ba65c9
 
4455094
 
1ba65c9
 
4455094
 
 
1ba65c9
 
4455094
 
 
 
1ba65c9
 
4455094
 
 
 
 
 
 
 
 
 
1ba65c9
4455094
 
 
1ba65c9
4455094
 
 
 
 
 
 
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
 
4455094
1ba65c9
4455094
 
 
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
 
 
1ba65c9
4455094
1ba65c9
4455094
 
 
 
 
 
 
 
 
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
 
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
 
 
 
4455094
 
 
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
 
1ba65c9
4455094
 
 
 
 
1ba65c9
 
 
 
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
 
 
1ba65c9
 
4455094
 
1ba65c9
 
4455094
 
 
1ba65c9
4455094
 
 
 
 
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
 
 
 
 
 
 
 
 
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
1ba65c9
4455094
1ba65c9
4455094
 
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
 
 
1ba65c9
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
 
 
1ba65c9
 
4455094
1ba65c9
 
4455094
1ba65c9
4455094
 
 
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# SPECTRA Execution Guide

This is the concrete runbook for the current repo. It matches the real `Makefile`, `demo.py`, `inference.py`, and test status in `/Users/madhav_189/Documents/Scalar_hackathon/Madhav_task`.

Project root:

```bash
cd /Users/madhav_189/Documents/Scalar_hackathon/Madhav_task
```

## 1. Python Environment

The repo supports two Python paths.

### Option A: create a local `.venv`

```bash
make setup-venv
```

This creates:

```text
/Users/madhav_189/Documents/Scalar_hackathon/Madhav_task/.venv
```

### Option B: reuse the older shared environment

If there is no local `.venv`, the `Makefile` falls back to:

```text
/Users/madhav_189/Documents/Scalar_hackathon/openenv/.venv/bin/python
```

### Check what the repo is using

```bash
make doctor
make which-python
```

## 2. Optional `.env`

The repo auto-loads a local `.env` file if it exists.

Create it from the template:

```bash
cp .env.example .env
```

Most useful keys:

- `HF_TOKEN`
- `INFRA_SPECIALIST_MODEL`
- `INFRA_SPECIALIST_PROVIDER`
- `LOG_SPECIALIST_MODEL`
- `LOG_SPECIALIST_PROVIDER`
- `SEC_SPECIALIST_MODEL`
- `SEC_SPECIALIST_PROVIDER`
- `COMMANDER_PROVIDER`
- `COMMANDER_MODEL`
- `COMMANDER_HF_PROVIDER`
- `API_BASE_URL`
- `OPENAI_API_KEY`

Important notes:

- `.env` is ignored by git
- hosted specialist runs need `HF_TOKEN`
- local commander runs use an OpenAI-compatible endpoint, usually Ollama at `http://127.0.0.1:11434/v1`
- the repo defaults to `SPECIALIST_MODE=hybrid` for hosted multi-agent runs and `LOCAL_MULTI_SPECIALIST_MODE=deterministic` for local smoke runs

## 3. First 5 Minutes

For a first-time user:

```bash
make doctor
./.venv/bin/python -m pytest tests -q
make scenarios
make demo SCENARIO=broken_auth_cascade
```

That verifies:

- Python environment selection
- test suite health
- scenario catalog
- council-style terminal experience

Current local test result:

- `23 passed`

## 4. The Main User Flows

Think of SPECTRA in five practical flows:

1. `make demo`: single-scenario council story
2. `make council-local`: all-scenario local council pipeline
3. `make multi-agent-local-smoke` or `make multi-agent-smoke`: trace, dataset, and hint-pack collection
4. `make hinted` and `make hinted-check`: blind versus hinted replay
5. `make train-smoke` or `make train`: replay-backed GRPO workflow

If you only remember one sequence, use this:

```bash
make doctor
./.venv/bin/python -m pytest tests -q
make demo
```

## 5. Demo Experience

### Single-scenario money demo

```bash
make demo SCENARIO=broken_auth_cascade
```

This runs the three-phase story for one scenario:

1. blind commander
2. multi-agent council
3. hinted commander

Default output root:

- `outputs/council_pipeline/single_broken_auth_cascade/`

Convenience shortcuts:

```bash
make demo-easy
make demo-medium
make demo-hard
make demo-cache
```

### Full local council pipeline

```bash
make council-local
```

Default behavior:

- `COUNCIL_SCOPE=all`
- phases: `untrained,multi_agent,hinted`
- local commander model: `qwen2.5:3b`
- local multi-agent model: `qwen2.5:3b`
- specialist mode: `deterministic`

Default output root:

- `outputs/council_pipeline/`

### Run only one scenario in the council UI

```bash
make council-local COUNCIL_SCOPE=single SCENARIO=broken_auth_cascade
```

### Run only selected phases

```bash
make council-local COUNCIL_PHASES=untrained
make council-local COUNCIL_PHASES=multi_agent
make council-local COUNCIL_PHASES=hinted
```

### Hosted council variant

```bash
make council-hf
```

This keeps the untrained and hinted phases local, but switches the multi-agent council phase to the hosted HF commander stack.

## 6. Single-Agent Baselines

### Blind local commander

This is the clean baseline: one full-state commander with no hint help.

Before running it, make sure your local OpenAI-compatible endpoint exists.

For Ollama:

```bash
ollama serve
ollama list
```

Run the blind baseline:

```bash
make untrained SCENARIO=broken_auth_cascade LOCAL_MODEL=qwen2.5:1.5b
```

Default output folder:

- `outputs/untrained/`

### Direct single-agent freeform inference

```bash
make local-free SCENARIO=broken_auth_cascade LOCAL_MODEL=qwen2.5:1.5b
```

This goes through `inference.py` in `single_agent` mode without the council wrapper.

## 7. Multi-Agent Collection

This is the core benchmark artifact flow. One run can export:

- step-level JSONL data
- episode summary JSON
- raw traces
- a trace-derived hint pack

### Local no-HF smoke run

```bash
make multi-agent-local-smoke SCENARIO=broken_auth_cascade
```

Default local settings:

- commander provider: `openai`
- commander model: `qwen2.5:3b`
- specialist mode: `deterministic`
- output dir: `outputs/multi_agent/`

### Hosted or hybrid smoke run

```bash
make multi-agent-smoke SCENARIO=broken_auth_cascade COMMANDER_MODEL=Qwen/Qwen3-4B-Instruct-2507
```

Default hosted settings:

- commander provider: `hf`
- commander model: `Qwen/Qwen3-4B-Instruct-2507`
- commander HF provider: `nscale`
- specialist mode: `hybrid`

### Larger collection run

```bash
make multi-agent EPISODES=5 COMMANDER_MODEL=Qwen/Qwen3-4B-Instruct-2507
```

### Real hosted specialist collection

```bash
make real-collect-smoke
make real-collect EPISODES=5
```

These force `SPECIALIST_MODE=llm`.

### Local model matrix

```bash
make multi-agent-local-05b-smoke SCENARIO=broken_auth_cascade
make multi-agent-local-15b-smoke SCENARIO=broken_auth_cascade
make multi-agent-local-3b-smoke SCENARIO=broken_auth_cascade
make multi-agent-local-matrix SCENARIO=broken_auth_cascade
```

### Artifacts to inspect

After a multi-agent run, look at:

- `outputs/multi_agent/data.jsonl`
- `outputs/multi_agent/data.summary.json`
- `outputs/multi_agent/traces/`
- `outputs/multi_agent/hints.json`

### Specialist mode guidance

- `deterministic`: cheapest and most reproducible
- `hybrid`: hosted first, deterministic fallback on failure
- `llm`: strict hosted specialists only

Use `hybrid` when you want the pipeline to keep moving even if provider calls are brittle.

## 8. Hinted Replay

This re-runs a full-state local commander with the exported hint pack.

### Run the hinted commander

```bash
make hinted SCENARIO=broken_auth_cascade LOCAL_MODEL=qwen2.5:1.5b
```

Default output folder:

- `outputs/hinted/`

### Compare blind versus hinted

```bash
make hinted-check SCENARIO=broken_auth_cascade
```

Alias:

```bash
make hint-effect SCENARIO=broken_auth_cascade
```

Expected output folder:

- `outputs/hint_effect/`

This is the simplest way to test whether the trace-derived cheat sheet actually improves the local commander.

## 9. Hint Building And Dataset Smoke Tests

Build a hint pack directly from deterministic heuristic collection:

```bash
make build-hints EPISODES=5
```

Minimal dataset smoke test:

```bash
make dataset-smoke
```

This is useful when you want to validate artifact wiring without burning hosted credits.

## 10. GRPO Workflow

### Smoke test the training loop

```bash
make train-smoke
```

This does two things:

1. collects a tiny deterministic dataset
2. dry-runs `training/grpo_train.py` against it

### Dry-run training on an existing dataset

```bash
make grpo-dry-run DATASET_PATH=outputs/multi_agent/data.jsonl
```

### Real training run

```bash
make train DATASET_PATH=outputs/multi_agent/data.jsonl TRAIN_STEPS=20
```

Training output root:

- `outputs/grpo_runs/`

## 11. Direct Inference Commands

Single scenario:

```bash
make inference SCENARIO=database_sqli_outage
```

Pretty terminal rendering:

```bash
make inference-pretty SCENARIO=broken_auth_cascade
```

All scenarios:

```bash
make inference-all
```

The CLI itself supports:

```bash
./.venv/bin/python inference.py --help
```

Main choices:

- runtime: `local` or `remote`
- observation mode: `multi_agent` or `single_agent`
- specialist mode: `deterministic`, `hybrid`, or `llm`
- commander type: `heuristic`, `random`, `llm`, or `single-agent`

## 12. API Server And Remote Mode

### Start the local server

Terminal 1:

```bash
make server
```

For auto-reload:

```bash
make dev
```

### Run remote inference against the server

Terminal 2:

```bash
make remote REMOTE_SCENARIO=database_sqli_outage
make remote-pretty REMOTE_SCENARIO=database_sqli_outage
```

Default base URL:

- `http://127.0.0.1:8000`

The top-level server wrapper is `server/app.py`, and the real FastAPI/OpenEnv implementation is in `environments/pomir_env/server.py`.

## 13. Docker Flow

Build the image:

```bash
make docker-build
```

Run it:

```bash
make docker-run
```

The Docker entrypoint serves:

- `uvicorn server.app:app --host 0.0.0.0 --port 8000`

## 14. Validation Commands

### Tests

```bash
./.venv/bin/python -m pytest tests -q
```

Current local result:

- `23 passed`

### OpenEnv validation

```bash
./.venv/bin/openenv validate .
```

Current local result:

- not yet ready for multi-mode deployment because `uv.lock` is missing

The repo no longer fails validation on the server wrapper shape:

- `server = "server.app:main"` exists in `pyproject.toml`
- `server/app.py` exposes a callable `main()`

To clear the remaining issue:

```bash
uv lock
```

If `uv lock` needs network access in your environment, run it outside the restricted sandbox and then re-run:

```bash
./.venv/bin/openenv validate .
```

## 15. Recommended Paths

If you want the judge-facing story:

```bash
make demo
```

If you want the full local product flow:

```bash
make council-local
```

If you want benchmark artifacts without HF credits:

```bash
make multi-agent-local-smoke
```

If you want the strongest hosted multi-agent collection:

```bash
make multi-agent-smoke COMMANDER_MODEL=Qwen/Qwen3-4B-Instruct-2507
```

If you want the shortest training sanity check:

```bash
make train-smoke
```