# Contract Context-Switch Cost Simulator

## PURPOSE
The video opens with the friction: "Lawyers, when they start drafting a document, they have to go between different systems... you add the complexity of having to do a global contract, they have to talk to different offices... internal and maybe external advisors as well. It's taking them away from where they can really add value." This project quantifies exactly that loss. It simulates a drafting workflow as a queueing system, once in the fragmented baseline and once with a single central environment, and reports how much lawyer time returns when context switching disappears.

## WHY THIS MATTERS
The claim that consolidation helps is normally asserted, never measured. Modelling lawyers as finite-capacity resources and each system hop or advisor round-trip as a stochastic delay makes the invisible cost visible — and produces the numbers a business case for ChatGPT Enterprise, Counsel Legal and HiQu actually needs.

## HOW TO BUILD
1. `pip install -r requirements.txt` (SimPy for discrete-event simulation, NumPy for reproducible randomness and statistics).
2. Model three resource pools: `drafter` (the lawyer, capacity 1), `colleague`, and `external_advisor` (each capacity 1, slow service times).
3. Baseline: every document step needs a fresh "system load" delay plus a re-orientation delay (the context switch), and advisor round-trips block the drafter.
4. Centralised: the load delay collapses to one environment; advisor requests are non-blocking because the answer arrives as a cited artefact in the same workspace.
5. Run each configuration N=200 seeded times, collect mean cycle time and drafter utilisation, and print a comparison with a 95% confidence interval.
6. Sensitivity knob: increase advisor service time to see when centralisation stops paying for itself.

```python
def draft_task(env, cfg, drafter, colleague, advisor, stats):
    t0 = env.now
    for step in range(cfg["steps_per_doc"]):
        yield env.timeout(cfg["context_switch"] + cfg["system_load"])
        with drafter.request() as me:
            yield me
            with colleague.request() as peer:
                yield peer
                yield env.timeout(rng.exponential(cfg["review_time"]))
        if step % 3 == 0:                       # advisor round-trip every 3rd step
            if cfg["blocking_advisors"]:
                with advisor.request() as ext:
                    yield ext
                    yield env.timeout(rng.exponential(cfg["advisor_time"]))
            else:
                env.process(advisor_async(env, cfg, advisor, stats))
    stats["cycle_time"].append(env.now - t0)
```

## WHEN TO USE IN PRODUCTION
Use it before committing to a consolidation programme: to size the prize, to find the bottleneck office, and to stress-test assumptions about advisor latency. Use it in capacity planning when headcount or offices change. Do NOT use it to make promises to a client — it is a decision aid, not a forecast. Skip it for small teams where a single matter rarely crosses systems.

## HOW IT HELPS STUDENTS
Students get hands-on SimPy resources, stochastic service times, experiment harnesses with seeds, and confidence intervals — the toolkit for defending a performance claim. Just as important, they learn to translate a qualitative complaint from an interview into a measurable model.

## STARTER CODE
`starter/main.py` contains the resource model, both configurations, the multi-run harness and the comparison report, with `# TODO` markers for a richer document-step graph and real timing data.
