Skip to content

Commit 7bb6635

Browse files
committed
feat(yerkes_dodson): v0.2.0 gstack-grade upgrade
Multi-mode (quick/standard/forensic) Yerkes-Dodson Workload diagnostic with 7 literature anchors: Yerkes-Dodson 1908, Sweller CLT 1988/1994/ 2011, Kahneman 1973 attention capacity, Hancock-Warm 1989 dynamic adaptability, Eysenck-Calvo 1992 attentional control, Hebb 1955 arousal-as-precursor, Liu et al. 2024 lost-in-the-middle. What's new ---------- - 3 pipeline modes (quick=1 call / standard=1 call / forensic=4 calls) - 10 WorkloadProfilePattern values + 'indeterminate' - CognitiveLoadAnalysis (Sweller intrinsic/extraneous/germane) - ContextSaturation (Liu et al. 2024 lost-in-the-middle, auto-derived from pressure.context_size_tokens / pressure.context_window_size) - 18 intervention types incl. chunk_context, context_compression, reduce_extraneous_load, add_intrinsic_load_step_by_step - 12 (zone, failure_mode) playbooks anchored in the literature - Composition manifest: upstream (lewin/aar/cognitive_reappraisal/ goleman_ei) + per-profile-pattern downstream + per-framework overlays (langgraph/crewai/autogen/claude-agent-sdk/openai-agents- sdk/mastra/strands) + per-intervention overlays - Baseline + drift severity (none/minor/moderate/severe) - 7 CLI subcommands (analyze/batch/replay/validate/schema/playbooks/ compose) via agentcity-yerkes entry point - Full production infra: structured logging with run_id correlation, token/cost telemetry, prompt injection detection, prompt fencing, retry with backoff, async mirror (YerkesDodsonAnalyzerAsync) - 39 tests, ruff format + ruff check clean Backward compatibility --------------------- WorkloadDetector is preserved as an alias of YerkesDodsonAnalyzer. WORKLOAD_PROMPT preserved as alias of STANDARD_WORKLOAD_PROMPT. All v0.0.x callers continue to work unchanged.
1 parent 6f54c49 commit 7bb6635

12 files changed

Lines changed: 2903 additions & 358 deletions

File tree

Lines changed: 137 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Yerkes-Dodson Optimal Workload Detector — performance-vs-pressure curve, applied to AI agents
1+
# Yerkes-Dodson Optimal Workload Detector
22

33
> *"The relation of strength of stimulus to rapidity of habit-formation is such that a definite optimum of intensity exists. Performance increases up to that optimum and decreases beyond it. The optimum varies with the difficulty of the task."*
4-
> — Robert M. Yerkes & John D. Dodson, *The Relation of Strength of Stimulus to Rapidity of Habit Formation* (Journal of Comparative Neurology and Psychology, 18, 1908)
4+
> — Robert M. Yerkes & John D. Dodson (1908)
55
6-
**Status:** 🟢 shipped
7-
**Module:** 1 (Individual) individual agent performance under pressure
8-
**Anchor framework:** Robert M. Yerkes & John D. Dodson, 1908 — the original Yerkes-Dodson Law experiments on mice running mazes under varying shock intensity. Refined by Hebb (1955) on optimal-arousal theory; modern operational treatments in performance-psychology literature.
6+
**Status:** 🟢 shipped (v0.2.0 -- gstack-grade)
7+
**Module:** 1 (Individual) -- individual agent performance under pressure
8+
**Anchor framework:** Yerkes-Dodson (1908) inverted-U + Sweller (1988/1994/2011) Cognitive Load Theory + Kahneman (1973) attention capacity + Hancock-Warm (1989) dynamic adaptability + Eysenck-Calvo (1992) Attentional Control Theory + Hebb (1955) arousal-as-precursor + Liu et al. (2024) lost-in-the-middle.
99

1010
---
1111

12-
## The OB framework
12+
## What this pattern does
1313

14-
The 1908 Yerkes-Dodson experiments established that performance on a task has an **inverted-U relationship with arousal (or pressure):**
14+
Diagnoses **where an AI agent sits on the inverted-U workload curve**: under-pressure (wandering / drifting), optimal (focused), or over-pressure (corner-cutting / freezing / hallucinating / refusing). Then proposes ranked interventions, attaches failure-mode playbooks, and hands off to downstream AgentCity patterns.
1515

1616
```
1717
performance
@@ -20,112 +20,165 @@ The 1908 Yerkes-Dodson experiments established that performance on a task has an
2020
│ ╱ ╲
2121
│ ╱ ╲
2222
│ ╱ ╲
23-
│ ╱ ╲
24-
│ ╱ ╲___
23+
│ ╱ ╲___
2524
└──────────────────▶
2625
low optimal high
2726
pressure
28-
```
29-
30-
Three zones:
31-
- **Under pressure** → performance *wanders.* Attention drifts. The actor explores tangentially, over-elaborates, fails to commit. The signal in human work: 15-page memos for 1-paragraph decisions; analysis paralysis on simple choices.
32-
- **Optimal** → performance is *focused.* Attention is concentrated on the task. The actor commits.
33-
- **Over pressure** → performance *collapses.* The actor corner-cuts, freezes, hallucinates, or refuses.
34-
35-
The 1908 paper added a critical second finding: **the optimum varies with task complexity.** Simple tasks peak at *higher* pressure (focus dominates over exploration). Complex tasks peak at *lower* pressure (need cognitive headroom for the harder problem). The Yerkes-Dodson Law gives you a different optimum for each task class.
36-
37-
## How this maps to AI agents
38-
39-
The same curve appears in agent traces with disturbing fidelity. The "pressure" inputs are the operational equivalents of the 1908 experiment's shock intensity:
40-
41-
| Pressure input | Operational analog |
42-
|---|---|
43-
| **Deadline pressure** | How tight is the wall-clock budget? |
44-
| **Budget pressure** | How tight is the token/cost budget? |
45-
| **Retry cap** | How many retries are allowed? |
46-
| **Error visibility** | How costly are errors when they happen? |
47-
| **Task complexity** | How cognitively demanding is the task? |
48-
49-
The three zones manifest in agent traces as canonical failure modes:
50-
51-
| Zone | Failure mode | What it looks like |
52-
|---|---|---|
53-
| Under pressure | **Wandering** | Agent considers 12 alternatives for a simple categorization; produces 30 pages of analysis with no recommendation |
54-
| Optimal | **Focused** | Agent commits to a path, executes, ships within budget |
55-
| Over pressure (mild) | **Corner-cutting** | Agent skim-reviews half the PR; ships unverified citations |
56-
| Over pressure (medium) | **Freezing** | Agent asks for more time / pre-summarized inputs; produces nothing |
57-
| Over pressure (severe) | **Hallucinating** | Agent confabulates citations rather than verifying; pretends a function exists |
58-
| Over pressure (severe) | **Refusing** | Agent declines, suggests re-scoping |
59-
60-
The most common production failure is **hallucinating under absurd pressure on a complex task** — the operational analog of the Yerkes-Dodson high-arousal collapse on a hard problem.
61-
62-
## What this pattern does
63-
64-
The `agentcity.yerkes_dodson` library takes an `AgentPerformanceTrace` containing:
6527
66-
- The agent's **task**
67-
- The **pressure inputs**: `deadline_pressure` / `budget_pressure` / `retry_cap` / `error_visibility` / `task_complexity`
68-
- The **observed behaviors** (concrete behavioral observations from the trace)
69-
- Outcome and success signal
70-
71-
and produces a `WorkloadDetection` with:
72-
73-
1. **Per-zone evidence** for `under_pressure`, `optimal`, `over_pressure` — each with score, explanation, evidence quotes
74-
2. **Observed zone** — the dominant zone
75-
3. **Distance from optimal** in [0.0, 1.0] — 0 = on the curve's peak; 1 = on the worst tail
76-
4. **Failure mode** — one of `wandering`, `focused`, `corner_cutting`, `freezing`, `hallucinating`, `refusing`, `unknown`
77-
5. **Concrete interventions** to push toward optimal, each with a direction (`increase_pressure` / `decrease_pressure`) and intervention_type: `tighten_deadline`, `add_budget_cap`, `loosen_deadline`, `loosen_budget`, `add_kill_criterion`, `raise_retry_cap`, `lower_retry_cap`, `explicit_focus_prompt`, `human_review`, `new_eval`
28+
(the optimum sits LOWER on the curve when tasks are complex)
29+
```
7830

79-
Single LLM pass. Interventions are skipped when the agent is in the optimal zone. Same retry / graceful-degradation infrastructure as the rest of AgentCity.
31+
## Three pipeline modes
8032

81-
The diagnostic is **bidirectional**: some agents need *more* pressure (the wandering analyst), others need *less* (the hallucinating researcher). This is the key feature that distinguishes Yerkes-Dodson from naive "give the agent more time" advice — sometimes the fix is the opposite direction.
33+
| Mode | LLM calls | Latency | Use when |
34+
| --- | --- | --- | --- |
35+
| `quick` | 1 | <2s | Triage; dashboards; tight cost budgets. Zone + top intervention. |
36+
| `standard` | 1 | ~3s | Production default. Zone evidence + ranked interventions. |
37+
| `forensic` | 4 | ~10s | Incident review. Adds Sweller CLT decomposition + Liu-2024 context-saturation analysis + 4-8 ranked interventions with composition targets. |
8238

83-
## How this differs from existing tools
39+
## Schema highlights (v0.2.0)
8440

85-
- **Pattern #08 Adam Grant Strengths-as-Weaknesses** measures personality-trait overuse independent of pressure. Yerkes-Dodson measures *pressure-dependent* failure modes. Both can fire together: an over-cautious agent under absurd pressure refuses (Grant: caution overuse; Yerkes-Dodson: over-pressure / refusing).
86-
- **Pattern #27 Bias-Stack Detector** measures cognitive biases in reasoning. Yerkes-Dodson asks whether the *level of pressure* is producing the biases. Anchoring under absurd pressure often surfaces because the agent skipped the verification step (corner_cutting) that would have updated the anchor.
87-
- **Pattern #24 SMART Goal Generator** generates the goal spec including budget/deadline. Yerkes-Dodson audits whether those budget/deadline choices are *in the optimal range for the task complexity.*
88-
- **Pattern #14 Process Gain/Loss Detector** measures outcome-level multi-agent metrics. Yerkes-Dodson explains a specific cause when an individual agent on the crew is failing: it's operating off the curve.
41+
- `WorkloadDetection.profile_pattern` -- one of 11 patterns including `context_saturation`, `extraneous_load_overload`, `intrinsic_load_overload`, plus the 3-zone × failure-mode variants.
42+
- `CognitiveLoadAnalysis` -- intrinsic / extraneous / germane decomposition (Sweller CLT). Forensic mode.
43+
- `ContextSaturation` -- saturation_ratio + lost_in_middle_risk (Liu et al. 2024). Auto-computed deterministically from `pressure.context_size_tokens` / `pressure.context_window_size`.
44+
- `WorkloadIntervention` -- 18 intervention types including `chunk_context`, `context_compression`, `reduce_extraneous_load`, `add_intrinsic_load_step_by_step`, `promote_germane_load`, `compose_pattern`. Adds effort_estimate, risk, reversibility, success_metric, composition_target_pattern, preconditions.
45+
- `BaselineComparison` -- drift severity (none / minor / moderate / severe) vs a recorded baseline.
46+
- `ComposedPatternHandoff` -- upstream + downstream pattern recommendations driven by profile pattern + framework.
8947

90-
## Design
48+
## Quick start
9149

9250
```python
9351
from agentcity.yerkes_dodson import (
94-
WorkloadDetector,
52+
YerkesDodsonAnalyzer,
9553
AgentPerformanceTrace,
9654
PressureInputs,
9755
)
98-
from agentcity.aar.clients import AnthropicClient
56+
from agentcity.aar import AnthropicClient
9957

10058
trace = AgentPerformanceTrace(
10159
agent_id="research-agent-001",
102-
task="Compile a 1-page summary with real citations.",
60+
task="Compile a 1-page summary on prompt injection defenses.",
10361
pressure=PressureInputs(
10462
deadline_pressure="absurd",
10563
budget_pressure="absurd",
10664
task_complexity="complex",
65+
context_size_tokens=80_000,
66+
context_window_size=100_000,
10767
),
10868
observed_behaviors=[
10969
"Agent cited 3 papers without verifying they exist.",
110-
"Agent skipped verification step.",
70+
"Agent shipped without running its own check.",
11171
],
112-
outcome="2 of 3 citations fabricated.",
72+
outcome="Summary contains 2 fabricated citations.",
11373
success=False,
11474
)
11575

116-
detector = WorkloadDetector(llm_client=AnthropicClient())
117-
detection = detector.run(trace)
118-
# observed_zone: over_pressure; failure_mode: hallucinating
119-
# Intervention #1: loosen_deadline (complex tasks peak at lower pressure)
76+
detection = YerkesDodsonAnalyzer(AnthropicClient(), mode="forensic").run(trace)
77+
print(detection.to_markdown())
78+
# observed_zone: over_pressure
79+
# profile_pattern: context_saturation
80+
# Composition handoff: agentcity.lewin, agentcity.johari
81+
```
82+
83+
## CLI
84+
85+
```bash
86+
# Single trace
87+
agentcity-yerkes analyze --trace trace.json --mode forensic
88+
89+
# Batch over a YAML corpus
90+
agentcity-yerkes batch --corpus corpus.yaml --out detections/ --mode standard
91+
92+
# Re-render an existing detection JSON
93+
agentcity-yerkes replay --detection detection.json
94+
95+
# Validate a trace schema
96+
agentcity-yerkes validate --trace trace.json
97+
98+
# Dump JSON schemas
99+
agentcity-yerkes schema --target trace
100+
agentcity-yerkes schema --target detection
101+
102+
# Inspect the 12 playbooks
103+
agentcity-yerkes playbooks
104+
105+
# Inspect the composition graph
106+
agentcity-yerkes compose
120107
```
121108

122-
## Files
109+
## Composition
110+
111+
**Upstream patterns** (run these before Yerkes-Dodson):
112+
- `agentcity.lewin` -- attribute the workload pressure to person/environment locus.
113+
- `agentcity.aar` -- generate the after-action review the trace comes from.
114+
- `agentcity.cognitive_reappraisal` -- detect emotion-regulation pressure on the agent.
115+
- `agentcity.goleman_ei` -- audit the agent's emotional intelligence under load.
116+
117+
**Downstream patterns** (chosen by profile_pattern):
118+
- `over_pressure_hallucinating` -> `agentcity.johari` + `agentcity.lewin`
119+
- `over_pressure_corner_cutting` -> `agentcity.devils_advocate` + `agentcity.bias_stack`
120+
- `over_pressure_freezing` -> `agentcity.cognitive_reappraisal` + `agentcity.mcgregor`
121+
- `over_pressure_refusing` -> `agentcity.cognitive_reappraisal` + `agentcity.grant_strengths`
122+
- `context_saturation` -> `agentcity.lewin`
123+
- `optimal_zone` -> `agentcity.aar` (record the baseline)
124+
125+
**Framework overlays** (added if `trace.framework` is set):
126+
- `langgraph` / `crewai` / `autogen` / `mastra` / `strands` -> `agentcity.grpi`
127+
- `claude-agent-sdk` / `openai-agents-sdk` -> `agentcity.process_gain_loss`
128+
129+
## Failure-mode playbooks
130+
131+
12 curated `(zone, failure_mode)` playbooks anchored in the literature. Inspect them with `agentcity-yerkes playbooks` or programmatically:
132+
133+
```python
134+
from agentcity.yerkes_dodson import find_playbook_for_intervention
135+
136+
pb = find_playbook_for_intervention("over_pressure", "chunk_context")
137+
print(pb.title)
138+
# "Context window saturated -- chunk + map-reduce"
139+
print(pb.anchor_citation)
140+
# "Liu et al. 2024 lost-in-the-middle; Sweller 2011 CLT update"
141+
```
142+
143+
## Literature
144+
145+
Full citations in [lib/CITATIONS.md](lib/CITATIONS.md). Seven primary anchors:
146+
147+
1. **Yerkes & Dodson (1908)** -- original inverted-U.
148+
2. **Sweller (1988/1994/2011)** -- Cognitive Load Theory (intrinsic / extraneous / germane).
149+
3. **Kahneman (1973)** -- attention as limited capacity.
150+
4. **Hancock & Warm (1989)** -- dynamic adaptability + sharp performance threshold.
151+
5. **Eysenck-Calvo (1992)** -- Attentional Control Theory (anxiety -> efficiency before effectiveness).
152+
6. **Hebb (1955)** -- arousal-as-physiological-precursor.
153+
7. **Liu et al. (2024)** -- lost-in-the-middle LLM context-saturation finding.
154+
155+
## Production infrastructure
156+
157+
Wired into the shared `agentcity.aar` infra:
158+
159+
- **Structured logging** with `run_id` correlation across all LLM calls in a detection.
160+
- **Token + cost telemetry** via `record_llm_call` to the configured sink.
161+
- **Input sanitization + fencing** for every free-text field (`task`, `outcome`, `observed_behaviors`, etc.).
162+
- **Prompt-injection detection** runs on every input; flagged in `WorkloadDetection.injection_detected`.
163+
- **Retry with backoff** on every LLM call.
164+
- **Async mirror** via `YerkesDodsonAnalyzerAsync`.
165+
166+
## Backward compatibility
167+
168+
The v0.0.x interface is preserved:
169+
170+
```python
171+
from agentcity.yerkes_dodson import WorkloadDetector # alias of YerkesDodsonAnalyzer
172+
```
173+
174+
The v0.0.x `WorkloadDetector(...)` call still works -- defaults to `mode="standard"` which keeps the 1-call cost profile.
175+
176+
## Tests
177+
178+
39 tests, run with `pytest module-1-individual/06-yerkes-dodson-workload/tests/`. Covers schema invariants, mode behavior, profile classifier, telemetry, composition, playbooks, calibration, async mirror, and markdown rendering.
179+
180+
## See also
123181

124-
- `lib/schema.py``AgentPerformanceTrace`, `PressureInputs`, `WorkloadZoneEvidence`, `WorkloadDetection`
125-
- `lib/prompts.py``WORKLOAD_PROMPT`, `YERKES_DODSON_SYSTEM_PROMPT`
126-
- `lib/generator.py``WorkloadDetector` (single-pass pipeline; skips interventions when in optimal zone)
127-
- `demo/01_self_contained_demo.py` — research agent on absurd-pressure complex task (hallucination case)
128-
- `eval/synthetic_workload_failures.yaml` — 8 hand-crafted scenarios spanning all three zones + multiple failure modes
129-
- `eval/run_benchmark.py` — scoring runner
130-
- `tests/test_yerkes_dodson.py` — pytest tests covering validation, pipeline, zone fill, fallback, threshold logic
131-
- `essay.md` — Substack-ready essay
182+
- [Pattern #01 Lewin Formula](../01-lewin-formula/README.md) -- locus attribution upstream.
183+
- [Pattern #05 Cognitive Reappraisal](../05-cognitive-reappraisal/README.md) -- emotion-regulation diagnostic upstream.
184+
- [Pattern #11 McGregor Orchestrator Mode](../11-mcgregor-orchestrator/README.md) -- orchestration overlay for over_pressure_freezing.

0 commit comments

Comments
 (0)