Skip to content

Commit 30d4a4a

Browse files
committed
feat: add Assistive SDK with cyberloop() wrapper and middleware system (v2.2)
Introduce a lightweight alternative to the Orchestrator that wraps existing agents with composable middleware. The SDK instruments the inner loop (budget, policy, kinematics, telemetry) while leaving outer-loop orchestration to user code. Core changes: - Agent protocols: AgentLike (opaque) and SteppableAgent (step-level) - cyberloop(agent, opts) wrapper with automatic agent type detection - Middleware system: runner, budget, telemetry, stagnation, probe, evaluator - policyMiddleware: declarative ChainPolicy wiring with decideAction() - kinematicsMiddleware: EKF/PID drift detection as middleware - Adapter decoupling: domain adapters no longer import core directly Examples: - quickstart, middleware-demo, openai-agents-demo (new) - GitHub and Wikipedia demos ported to SDK alongside legacy versions Documentation: - docs/guide/choosing-your-api.md (new — SDK vs Orchestrator guide) - ADR-0002: Assistive SDK architectural decision record - Updated README, EVOLUTION, COMPONENT_INTERACTIONS, GLOSSARY, TESTING_GUIDE, AICL, TECHNICAL_SPEC_v2.1, inner-outer-loop
1 parent aac0ec6 commit 30d4a4a

55 files changed

Lines changed: 4553 additions & 224 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ CyberLoop (Blue) dampens this oscillation through closed-loop feedback.</em>
2626

2727
In **v2.1**, we introduce **Semantic Kinematics**: giving agents a "vestibular system" (inner ear) to detect drift in vector space without needing to "think" (query an LLM). This allows agents to navigate complex knowledge graphs using **pure mathematics**—making them 100x faster and cheaper than traditional Chain-of-Thought agents.
2828

29+
In **v2.2**, we refactor the developer surface into a lightweight **Assistive SDK**. Instead of building inside the framework (`Orchestrator` + 7 interfaces), you now wrap your existing agent with `cyberloop(agent)` and progressively opt into middleware. The Orchestrator is preserved for backward compatibility.
30+
31+
---
32+
33+
## ⚡ Quick Start: The SDK (v2.2)
34+
35+
```typescript
36+
import { cyberloop } from 'cyberloop'
37+
38+
// Tier 1: Wrap any agent — get budget control for free
39+
const controlled = cyberloop(myAgent, { budget: { maxSteps: 20 } })
40+
const result = await controlled.run('your query')
41+
42+
// Tier 2: Expose step-level control for middleware
43+
const controlled = cyberloop(mySteppableAgent, {
44+
budget: { maxSteps: 50 },
45+
middleware: [telemetryMiddleware(logger), stagnationMiddleware()],
46+
})
47+
48+
// Tier 3: Advanced — add kinematics (EKF/PID drift detection)
49+
import { kinematicsMiddleware } from 'cyberloop/advanced'
50+
const controlled = cyberloop(mySteppableAgent, {
51+
middleware: [kinematicsMiddleware({ embedder, goalEmbedding, ... })],
52+
})
53+
```
54+
55+
See [examples/quickstart.ts](src/examples/quickstart.ts) for a runnable 30-line demo.
56+
2957
---
3058

3159
## 🚀 Hero Demo: Project Ariadne
@@ -41,7 +69,11 @@ Using CyberLoop v2.1, the agent navigates Wikipedia using only **Embeddings + PI
4169
yarn install
4270

4371
# 2. Run the Deep-Dive Scenario (Coffee -> French Revolution)
44-
yarn examples:wikipedia revolution
72+
# v2.2 SDK version (cyberloop wrapper + middleware):
73+
yarn examples:wikipedia:cyberloop -- --scenario revolution
74+
75+
# Legacy Orchestrator version (all benchmark modes):
76+
yarn examples:wikipedia -- --mode cyberloop --scenario revolution
4577

4678
```
4779

@@ -84,6 +116,26 @@ The strategic system that handles planning, replanning, and final evaluation.
84116
* **Trigger:** Only activated when the Inner Loop budget is exhausted or a stable state is found.
85117
* **Cost:** Expensive, but rarely invoked.
86118

119+
### 3. Developer API: Three Tiers (v2.2)
120+
121+
The SDK exposes the control loop at three levels of granularity:
122+
123+
| Tier | API | You Provide | CyberLoop Adds | Example |
124+
| --- | --- | --- | --- | --- |
125+
| **1. Opaque** | `cyberloop(agent)` | Any agent with `run()` | Budget, event hooks | [quickstart.ts](src/examples/quickstart.ts) |
126+
| **2. Steppable** | `cyberloop(steppableAgent)` | Agent with `step()`, `isDone()` | Per-step middleware (telemetry, stagnation, policy) | [middleware-demo.ts](src/examples/middleware-demo.ts) |
127+
| **3. Advanced** | `+ kinematicsMiddleware()` | Embedder + goal vector | EKF/PID drift detection | [demo-cyberloop.ts](src/examples/wikipedia/demo-cyberloop.ts) |
128+
129+
The legacy `Orchestrator` API remains available for full inner/outer loop control.
130+
131+
### 📖 Which API Should I Use?
132+
133+
**SDK (`cyberloop()`)** — You own the outer loop. CyberLoop instruments the inner loop with composable middleware (budget, policy, kinematics, telemetry). Best for adding control to existing agents or custom orchestration topologies.
134+
135+
**Orchestrator** — CyberLoop owns the full plan → explore → evaluate → replan cycle. Best for research prototyping and reproducing paper benchmarks.
136+
137+
👉 **[Full comparison and decision guide →](docs/guide/choosing-your-api.md)**
138+
87139
---
88140

89141
## 📉 Industrial Validation (Legacy)
@@ -127,29 +179,40 @@ OPENAI_API_KEY=sk-...
127179
### Available Demos
128180

129181
```bash
130-
# v2.1: Wikipedia Deep-Dive (Semantic Kinematics)
131-
# Scenarios: 'tech' (Jacquard -> CPU) or 'revolution' (Coffee -> French Revolution)
132-
yarn examples:wikipedia revolution
133-
134-
# v1.0: GitHub Search (Deterministic State Machine)
135-
# A classic example of bounded exploration using Probes & Ladders
136-
yarn examples:github
182+
# --- SDK Examples (v2.2) ---
183+
yarn examples:quickstart # Tier 1: opaque agent
184+
yarn examples:middleware # Tier 2: steppable + custom middleware
185+
yarn examples:openai-agents # OpenAI Agents SDK compatibility
186+
187+
# --- Wikipedia Navigation (v2.1 Semantic Kinematics) ---
188+
yarn examples:wikipedia:cyberloop # SDK version (cyberloop wrapper)
189+
yarn examples:wikipedia:cyberloop -- --scenario revolution
190+
yarn examples:wikipedia # Legacy Orchestrator (all modes)
191+
192+
# --- GitHub Search (v1.0 Deterministic State Machine) ---
193+
yarn examples:github:cyberloop # SDK version (steppable agent)
194+
yarn examples:github:baseline:cyberloop # SDK version (OpenAI Agent)
195+
yarn examples:github # Legacy Orchestrator
196+
yarn examples:github:baseline # Legacy baseline
137197

138198
```
139199

140200
---
141201

142202
## 📂 Documentation
143203

204+
* **Guide:** [Choosing Your API — SDK vs Orchestrator](docs/guide/choosing-your-api.md)
144205
* **Benchmarks:** [Wikipedia Navigation Results](docs/benchmarks/wikipedia/benchmark-wikipedia-navigation.md)
145206
* **Theory:** [AICL Whitepaper](docs/whitepaper/AICL.md)
207+
* **Philosophy:** [Immutable Principles](docs/whitepaper/PHILOSOPHY.md)
208+
* **Evolution:** [Why the architecture changed](docs/whitepaper/EVOLUTION.md)
146209
* **Architecture:** [Inner/Outer Loop Spec](docs/architecture/inner-outer-loop.md)
147210
* **Academic (v2.1):** Zenodo Record - [The Brain Needs a Body (Liang, 2026)](https://zenodo.org/records/18138161)
148211
* **Academic (v1.0):** Zenodo Record - [AICL Whitepaper (Liang, 2025)](https://zenodo.org/records/17835680)
149212

150213
---
151214

152-
> **Status:** 🧪 *v2.1 Research Preview*
215+
> **Status:** 🧪 *v2.2 Assistive SDK*
153216
> Uncontrolled intelligence grows powerful but fragile.
154217
> Controlled intelligence grows stable — and endures.
155218

docs/adr/0001-inner-outer-loop-architecture.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Output
2525
```
2626

2727
**Characteristics:**
28+
2829
- Multiple policies with dynamic routing
2930
- Failure classification for policy selection
3031
- Complex termination logic
@@ -98,6 +99,7 @@ Final Output
9899
### Preserved Interfaces (For Future Extension)
99100

100101
We keep but don't use:
102+
101103
- `StrategySelector` - For multi-domain agents requiring policy routing
102104
- `FailureClassifier` - For complex failure modes (distributed systems, bug triage)
103105
- `TerminationPolicy` - For multi-objective optimization
@@ -137,13 +139,15 @@ Total: ??? (hard to predict)
137139
#### 3. **Simplicity for Common Cases**
138140
139141
For single-domain tasks (GitHub search, API discovery):
142+
140143
- **No routing overhead** - Direct ProbePolicy execution
141144
- **No classification overhead** - Direct state examination
142145
- **Clear decision flow** - Plan → Explore → Evaluate
143146
144147
#### 4. **Extensibility for Complex Cases**
145148
146149
For multi-domain tasks (bug localization, distributed system triage):
150+
147151
- **Interfaces preserved** - Can add StrategySelector when needed
148152
- **Clear extension points** - Add FailureClassifier for complex diagnosis
149153
- **Documented migration path** - See unused-interfaces.md
@@ -191,6 +195,7 @@ From our GitHub search benchmark:
191195
### Current Status (v0.1.0)
192196
193197
**Implemented:**
198+
194199
- ✅ Orchestrator with inner/outer loop separation
195200
- ✅ ProbePolicy interface with initialize/decide/isStable
196201
- ✅ Planner interface with plan/evaluate/replan
@@ -199,6 +204,7 @@ From our GitHub search benchmark:
199204
- ✅ Benchmark comparing to baseline
200205
201206
**Not yet implemented:**
207+
202208
- ⚠️ Beam search (parallel candidates)
203209
- ⚠️ Query memoization and deduplication
204210
- ⚠️ Adaptive thresholds (EMA-based)
@@ -214,6 +220,7 @@ Based on feedback from GPT discussion, these optimizations will address the spee
214220
**Problem:** Sequential exploration is slow (5 API calls)
215221
216222
**Solution:** Parallel candidates with OR merging
223+
217224
```typescript
218225
// Instead of:
219226
t=0: try "node graceful shutdown"106 hits
@@ -233,6 +240,7 @@ t=0: try ["node graceful shutdown", "node AND graceful AND shutdown", "graceful
233240
**Problem:** Oscillation between same queries (106 → 7 → 106)
234241

235242
**Solution:** Cache and detect duplicates
243+
236244
```typescript
237245
// Normalize query
238246
const key = normalize({ keywords, minStars, language })
@@ -253,6 +261,7 @@ if (seenHashes.has(resultHash)) {
253261
**Problem:** Hard-coded thresholds (10-30 hits) don't work for all queries
254262

255263
**Solution:** Learn thresholds dynamically
264+
256265
```typescript
257266
// Instead of:
258267
if (hits >= 10 && hits <= 30) return stable
@@ -270,6 +279,7 @@ if (variance < threshold && hits > minAcceptable) return stable
270279
**Problem:** Inner/outer loops don't coordinate on budget
271280

272281
**Solution:** Link budgets
282+
273283
```typescript
274284
// When outer loop budget low:
275285
if (outerBudget.remaining() < 1.0) {
@@ -289,8 +299,9 @@ if (noImprovementSteps > 5) {
289299
**Problem:** Only measuring quantity (10 repos vs 3), not quality
290300

291301
**Solution:** Composite score
302+
292303
```typescript
293-
score =
304+
score =
294305
0.4 * qualityScore(stars, description) +
295306
0.3 * freshnessScore(lastUpdate) +
296307
0.2 * licenseScore(license) +
@@ -302,13 +313,15 @@ score =
302313
### Integration with Orchestrator
303314

304315
**Current:** Manual outer loop calls
316+
305317
```typescript
306318
const state = await planner.plan(input)
307319
const result = await orchestrator.exploreInnerLoop(state)
308320
const output = await planner.evaluate(result.state)
309321
```
310322

311323
**Recommended:** Integrated `runAdaptive()`
324+
312325
```typescript
313326
const result = await orchestrator.runAdaptive({
314327
userInput,
@@ -380,7 +393,7 @@ See [docs/use-cases.md](../use-cases.md) for detailed scenarios.
380393

381394
---
382395

383-
**Decision made by:** Framework authors
384-
**Date:** 2025-10-11
385-
**Supersedes:** Initial AICL routing-based design
386-
**Superseded by:** None (current)
396+
**Decision made by:** Framework authors
397+
**Date:** 2025-10-11
398+
**Supersedes:** Initial AICL routing-based design
399+
**Superseded by:** None (current; extended by [ADR-0002](0002-assistive-sdk-cyberloop-wrapper.md))

0 commit comments

Comments
 (0)