Skip to content
549 changes: 549 additions & 0 deletions .afk/research/chatgpt-transcript-epistemic-world-graph-2026-08-18.txt

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions .afk/research/epistemic-world-graph-research-brief.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Shared Agent State — Research Brief

*Generated 2026-08-18 from ChatGPT transcript + parallel research wave + adversarial review*

## The Problem

AFK's agents can exchange results through parent orchestration and DAG dependencies, but do not inhabit a persistent shared working state. Knowledge remains bound to individual contexts. Findings must be copied, compressed, rediscovered, or manually routed between agents.

AFK has **message passing and directed dataflow**. It does not have **environment-mediated cognition**.

The parent session is the wormhole — and it's a bad one: lossy, token-expensive, and serial. Compose's DAG executor is smarter (upstream outputs flow directly to downstream nodes), but even compose can't do shared mutable state that multiple agents read and write concurrently.

## The North Star

> "The parent is no longer the brain. AFK itself becomes the cognitive substrate. The agents are transient processes inside it."

This is a product identity claim, not an architecture proposal. AFK earns it incrementally — by building a shared workspace that starts simple and grows toward a persistent computational environment only if usage pulls it there.

---

## External Landscape: What's Real

Every project referenced in the original conversation is **confirmed real**. Nothing was hallucinated.

### Tier 1: Directly Relevant, Operational

| Project | Status | Key Insight for AFK |
|---------|--------|---------------------|
| **[ActiveGraph](https://github.com/yoheinakajima/activegraph)** | ✅ Production (v1.10.0, Apache-2.0, ~573 ⭐, ~6.8K monthly downloads) | Closest operational embodiment of the "world as substrate" thesis. Yohei Nakajima (BabyAGI). Append-only event log → graph as deterministic projection. Fork-at-any-event + diff working. [arXiv:2605.21997](https://arxiv.org/abs/2605.21997). Small community; BabyAGI was viral demo not production system — same risk applies here. |
| **[A2A v1.0](https://a2a-protocol.org)** | ✅ Production (~25.3K ⭐, 150+ orgs, Linux Foundation) | Inter-agent interop protocol. **Orthogonal, not opposed** — A2A governs between-systems protocol; a workspace governs within-system state. Different layers. Not relevant to the shared-workspace problem unless AFK becomes multi-tenant. |
| **[MCP July 2026 spec](https://blog.modelcontextprotocol.io/posts/2026-07-28/)** | ✅ Production (400M+ monthly SDK downloads) | Stateless core + Tasks extension (SEP-2663). Structureless by design — leaves the epistemic layer as an open problem AFK could fill. |

### Tier 2: Research Papers, High Signal

| Paper | Status | Key Insight for AFK |
|-------|--------|---------------------|
| **[MemIR](https://arxiv.org/abs/2605.25869)** (May 2026) | ✅ arXiv preprint, no public code | Coins "provenance-role collapse" — the failure mode where evidence, inference, and claims are merged without authorization. Three atom types: evidence, retrieval cues, truth-bearing claims. Supplies the epistemic type system. |
| **[MAP-Graph](https://arxiv.org/abs/2608.10509)** (Aug 11, 2026) | ✅ arXiv preprint, no public code | Trust/authorization layer for typed execution graphs. Permission filtering + trust propagation through ancestor traversal. Shows shared state needs authorization from day one. 94.96% task success / 2,700 synthetic tasks. |

### Tier 3: Supporting Context

| Concept | Reality Check |
|---------|---------------|
| **Blackboard architecture** | Classic (Erman 1976 / Hayes-Roth BB1 1985). The canonical answer to multi-expert coordination. Modern LLM revival via ChatDev, MetaGPT. Key insight: the **scheduler** (control shell) is what makes blackboards work, not just the shared state. |
| **Stigmergy in LLM agents** | Real research cluster. SodaMem, SEEM, MAGMA, ESR (2025-2026). Message-passing scales O(N²) in tokens; environment-mediated coordination scales O(N). |
| **Event-sourced agent graphs** | Active research cluster. No dominant runtime beyond ActiveGraph. |

### On "Convergence"

The original conversation and first draft of this brief called this "convergence from multiple angles." That overstates it. ActiveGraph, MemIR, MAP-Graph, and blackboard research are solving **different problems** that happen to use similar graph structures. A better claim:

> Several neighboring research areas have independently developed mechanisms that could **compose** into the architecture AFK needs.

That's a synthesis opportunity, not a convergent movement.

---

## AFK's Current Architecture

### What AFK Has Today

| System | Relevant Capability | Gap to Shared Workspace |
|--------|---------------------|-------------------------|
| **Witness Trace** (`src/agent/trace/`) | Append-only JSONL, 13 typed events, monotonic seq, Zod-validated. Has `claim` event with source/evidence/confidence/dissent. | Designed for forensics ("what happened?"), not state management ("what do we believe?"). No causal links between events, no queryable index. **Not automatically the substrate** — a forensic log and an operational state are different workloads. |
| **Compose DAG** (`src/agent/dag.ts`) | Kahn's algorithm, upstream outputs flow to downstream inputs. | Scheduling layer, not causal graph. Edges encode order-dependency, not semantic causation. No provenance on outputs. |
| **Memory** (SQLite FTS5) | 4 categories, evidence column (opt-in gate), supersede chain, confidence field (exists but always 1.0). | Flat facts, no inter-fact relationships, no temporal validity, no source-agent tracking. |
| **SubagentManager** (`src/agent/subagent.ts`) | Per-fork ID, parentId, resolvedAgentType, systemPromptHash. One-hop lineage via forkedFrom. | No persistent cross-session agent identity, no performance history, no trust. |
| **Farm** (`src/cli/commands/farm.ts`) | N parallel worktrees, scoring, winner selection, memory write-back. | No hypothesis variation, no cross-branch learning, no semantic comparison. |
| **Hooks** (`src/agent/hooks.ts`) | Lifecycle events (SessionStart/End, SubagentStart/Stop, PreToolUse/PostToolUse). Block/inject-context. | Fires on lifecycle, not state changes. Not stigmergy. |
| **AbortGraph** (`src/agent/abort-graph.ts`) | Lifecycle propagation tree. Parent abort cascades down; child abort notifies up. | Purely lifecycle. Cannot carry semantic content without violating its invariants. |

### Architecture Distance

```
Closest ────────────────────────────────────── Farthest

Witness Trace > Memory > Farm > DAG > Subagent ID > Hooks > AbortGraph
```

The witness trace has the most relevant structural properties but **is not automatically the substrate**. Building a world-state database on top of a forensic log because both have timestamps is architecture-by-convenience.

---

## What "Wormholes" Actually Are

The original conversation used "wormhole" as a metaphor for nonlocal information shortcuts. The first draft of this brief dismissed it as "attention routing, a solved engineering problem." That was too fast.

Ordinary retrieval:
```
query → similar chunks → context
```

What's being described:
```
failing test → affected function → decision that created function →
claim supporting decision → evidence behind claim → later contradictory evidence
```

That's **retrieval through causal topology** — not "find text similar to this" but "find information structurally relevant to why the present state exists."

This is genuinely unsolved. RAG over static corpora is solved. Dynamic causal retrieval is not.

**Naming convention:** "Wormhole" = what it feels like. **Causal context routing** (or **provenance-aware retrieval**) = what the code does.

---

## What's Novel vs. Known

| Idea | Novel? | Prior Art |
|------|--------|-----------|
| Event log as source of truth | No | ActiveGraph, event sourcing (Greg Young 2005+) |
| Typed epistemic objects | No | MemIR, epistemology of testimony |
| Trust propagation through derivation chains | No | MAP-Graph, PKI, web-of-trust |
| Causal context routing | **Partially** — the mechanism exists in knowledge graphs; applying it to agent dispatch context is less explored | Knowledge graphs + RAG, but not topology-aware agent context construction |
| Fork-at-any-event + diff futures | No | ActiveGraph, git |
| Shared typed workspace for LLM agents | **No** — blackboard architecture (1976), ChatDev, MetaGPT | But no one has done it inside a full agent harness at AFK's level |
| Combining all of these | **Yes** — the synthesis is novel | No existing system combines workspace + harness + causal routing |

---

## Recommended Reading

Before writing any code:

1. **ActiveGraph paper** — [arXiv:2605.21997](https://arxiv.org/abs/2605.21997). Runtime section: fork-at-any-event + diff.
2. **MAP-Graph paper** — [arXiv:2608.10509](https://arxiv.org/abs/2608.10509). Trust propagation section: shared state needs authorization from day one.
3. **MemIR paper** — [arXiv:2605.25869](https://arxiv.org/abs/2605.25869). "Provenance-role collapse" section: the failure mode AFK's flat memory currently risks.

---

*This document is the evidence base. The proposal lives in `shared-agent-workspace-rfc.md`.*
177 changes: 177 additions & 0 deletions .afk/research/shared-agent-workspace-rfc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# RFC: Shared Agent Workspace

*2026-08-18 — Draft*

## Problem

AFK's agents can exchange results through parent orchestration and compose DAG dependencies, but do not inhabit a persistent shared working state within a session. This causes:

1. **Repeated rediscovery** — Agent B re-reads files Agent A already analyzed
2. **Lossy knowledge transfer** — parent compresses Agent A's findings into a prompt for Agent B; nuance is lost
3. **Serial bottleneck** — the parent context window is the only channel between agents; parallel agents can't share mid-run
4. **No contradiction detection** — when Agent B discovers something that invalidates Agent A's finding, no mechanism surfaces the conflict

AFK has message passing (parent→child) and directed dataflow (compose DAG). It does not have environment-mediated cognition (shared mutable state agents read/write concurrently).

## Non-Goals (for v1)

- Replacing the witness trace or memory system
- Event sourcing, temporal forks, or deterministic replay
- Graph database, graph traversal, or causal path queries
- Agent identity, trust scores, or performance history
- Reactive behaviors (state changes waking agents)
- A2A, cross-system interop
- Any of the "six PhDs hiding in a trench coat"

## Proposal: Epistemic Workspace

A per-session typed scratchpad that any agent in the session can publish to and query from.

### Entry Types

```
Finding — "I observed X in file Y"
Evidence — "Lines 141-177 of src/auth.ts show Z"
Hypothesis — "The race condition is caused by W"
Decision — "We should use approach V because U"
Artifact — "Wrote fix to src/auth.ts:150"
Status — "Test suite passes / fails"
```

### Publish API (agent-facing)

```
workspace.publish({
type: "finding",
subject: "auth refresh",
content: "refreshSession() has a race condition between token rotation and persistence",
evidence: ["src/auth.ts:141-177"],
confidence: 0.91,
agent: "<auto-filled from session>"
})
```

### Query API (harness-facing)

When AFK forks an agent, it constructs a workspace context packet:

```
Relevant workspace state:
#12 Finding (agent: researcher-A, confidence: 0.91)
Auth refresh may race between rotation and persistence
Evidence: src/auth.ts:141-177
#18 Hypothesis (agent: researcher-B, confidence: 0.76)
Database transaction ordering, not token rotation, is the root cause
#22 Contradiction (agent: researcher-B → #12)
Test pollution may explain the failure researcher-A attributed to a race condition
```

### The Hard Problem: Routing

The publish side is simple. The query side — deciding which workspace entries are "relevant" when constructing context for a new agent — is where the real work lives. This is causal context routing: not "find similar text" but "find entries structurally relevant to this agent's task."

**v1 approach:** Dumb but honest. Include all workspace entries for the current session (sessions rarely exceed 50 entries). Filter by `subject` keyword overlap with the agent's task prompt. Prefix with recency.

**Later:** Replace keyword overlap with provenance-aware retrieval — traverse `supports`, `contradicts`, `depends_on` edges to surface structurally relevant entries even when keywords don't match.

### Storage

SQLite. Same database pattern as the memory system. Per-session table, not shared across sessions (cross-session is what memory is for).

```sql
CREATE TABLE workspace_entries (
id INTEGER PRIMARY KEY,
session_id TEXT NOT NULL,
type TEXT NOT NULL, -- finding | evidence | hypothesis | decision | artifact | status
subject TEXT,
content TEXT NOT NULL,
evidence TEXT, -- JSON array of file:line references
confidence REAL DEFAULT 1.0,
agent_id TEXT,
relates_to TEXT, -- JSON array of entry IDs this supports/contradicts/depends-on
relation_type TEXT, -- supports | contradicts | depends_on | caused | supersedes
created_at TEXT NOT NULL,
seq INTEGER NOT NULL -- monotonic within session, for ordering
);
```

### Integration Points

| System | Integration |
|--------|-------------|
| **SubagentManager** | On fork: query workspace, inject relevant entries as preamble. On child completion: auto-publish child's final findings to workspace. |
| **Compose DAG** | Node outputs auto-published as workspace entries. Downstream nodes see upstream entries via workspace, not just via `inputs`. |
| **Witness Trace** | Workspace publishes emit a trace event (new kind: `workspace_publish`). Workspace is queryable independently of trace. |
| **Memory** | Workspace entries that survive a session can be promoted to cross-session memory facts on session end. |
| **Hooks** | Future: `PostWorkspacePublish` hook for contradiction detection. Not in v1. |

## Validation: The Experiment

Run the same multi-agent task under two conditions:

### Control: Current AFK
```
parent
├── researcher A
├── researcher B
├── implementer
└── verifier
```

### Treatment: Workspace AFK
Same agents, same models, same task. Each reads/writes a shared workspace.

### Measurements
| Metric | How to Measure |
|--------|----------------|
| Duplicate file reads | Count distinct file:line reads across agents vs. total reads (from trace `tool_call` events) |
| Repeated discoveries | Manual inspection: did Agent B discover something Agent A already found? |
| Contradictory findings | Manual: did agents produce conflicting conclusions without surfacing the conflict? |
| Parent context tokens | Token count of parent's conversation history (from trace `budget` events) |
| Total tokens | Sum across all agents |
| Total tool calls | Count from trace |
| Wall-clock time | Session duration |
| Task completion | Did the task succeed? Quality of result? |
| 429 rate | Count of rate-limit errors across agents |

### Success Criteria
Workspace AFK produces:
- Less rediscovery (fewer duplicate reads)
- Less parent-context load (fewer tokens in parent)
- Better cross-agent consistency (fewer undetected contradictions)
- Equal or better task completion

If it doesn't, kill it.

### Measurement Caveat
"Duplicate reads" and "repeated discoveries" aren't automatically measurable from traces today. The experiment needs either manual inspection or a trace analysis tool that detects semantic duplication across subagent tool calls. Designing a fair experiment takes real thought — don't underestimate this.

## Build Order

1. **Shared typed workspace** — Agents publish structured findings; other agents query. Boring SQLite. Don't replace memory or witness.
2. **Automatic context routing** — When AFK forks, construct a workspace packet instead of forcing the parent to summarize. This is the first real "wormhole."
3. **Provenance links** — `Finding 18 supports Decision 27`; `Observation 31 contradicts Finding 18`.
4. **Invalidation** — If Finding 18 dies, surface Decision 27 and downstream artifacts as potentially stale. This is where shared state produces behavior you couldn't get cheaply before.
5. **Reactivity** — Only then consider state changes waking agents.
6. **Everything else** — Temporal forks, agent identity, trust, A2A. Only if usage pulls AFK there.

Let usage pull AFK toward the cognitive-substrate architecture. Don't push.

## Relationship to Existing Systems

- **This is NOT a replacement for the witness trace.** The trace is forensic ("what happened"). The workspace is operational ("what do we currently believe").
- **This is NOT a replacement for cross-session memory.** Memory is long-term. The workspace is per-session working state. Entries can be promoted to memory at session end.
- **This IS a new primitive** alongside trace, memory, and compose — filling the gap where within-session shared state should be.

## Open Questions

1. **Workspace scope:** Per root-session? Per compose DAG? Per explicit workspace ID? (Per root-session is simplest.)
2. **Auto-publish:** Should child agent findings auto-publish on completion, or should agents explicitly publish? (Start explicit, add auto-publish later.)
3. **Context budget:** If the workspace has 200 entries, how much context budget does the packet consume? Is there a compression strategy? (Start with "include all, filter by subject keyword.")
4. **Contradiction detection:** Is it the workspace's job to detect contradictions, or the agents'? (v1: agents'. v2: workspace surfaces potential contradictions.)
5. **Workspace tool:** Should agents get a `workspace_publish` / `workspace_query` tool, or should this be harness-level (invisible to the model)? (Both have tradeoffs — explicit tools let agents be intentional; harness-level reduces tool-call overhead.)

---

*Evidence base: `epistemic-world-graph-research-brief.md`*
*Origin: ChatGPT conversation (2026-08-18) → AFK research wave → adversarial review → synthesis*
Loading
Loading