diff --git a/docs/examples/exploration-diagrams/01-method-escalation.dot b/docs/examples/exploration-diagrams/01-method-escalation.dot new file mode 100644 index 00000000..ea73b6e7 --- /dev/null +++ b/docs/examples/exploration-diagrams/01-method-escalation.dot @@ -0,0 +1,24 @@ +digraph MethodEscalation { + rankdir=LR; + bgcolor="white"; + node [shape=box, style="rounded,filled", fontname="Helvetica", fontsize=11, margin="0.18,0.10"]; + edge [fontname="Helvetica", fontsize=9, color="#555555"]; + labelloc="t"; fontsize=16; fontname="Helvetica-Bold"; + label="How the search escalated: plain question -> Cypher -> GDS -> Embeddings"; + + q [label="Plain-language\nquestion\n(\"who works with whom?\")", fillcolor="#fef3c7", color="#d97706"]; + cy [label="Rung 1: CYPHER\ngraph queries\n(co-occurrence,\ndelegation, tool profiles)", fillcolor="#dbeafe", color="#2563eb"]; + gds [label="Rung 2: NEO4J GDS\nproject.cypher + knn +\nlouvain + pageRank\n(+ APOC helpers)", fillcolor="#dcfce7", color="#16a34a"]; + neg [label="Rung 3: negative result\ntool-behaviour clusters\n!= objectives\n(machinery, not mission)", fillcolor="#ffe4e6", color="#e11d48"]; + emb [label="Rung 4: EMBEDDINGS\nOpenAI text-embedding-3-small\n(1536-d) + k-means\non 3,199 first-prompts", fillcolor="#ede9fe", color="#7c3aed"]; + disc [label="DISCOVERY\ncoherent objective clusters\n(review / implement / git / build)", shape=box, style="rounded,filled,bold", fillcolor="#fde68a", color="#b45309"]; + + q -> cy -> gds -> neg -> emb -> disc; + + steer1 [label="steering:\n\"any root/forked/sub session\"", shape=note, fillcolor="#f1f5f9", color="#94a3b8", fontsize=9]; + steer2 [label="steering:\n\"neo4j community, GDS free\"\n+ \"use the private destination\"", shape=note, fillcolor="#f1f5f9", color="#94a3b8", fontsize=9]; + steer3 [label="steering:\n\"read the inline prompts;\nuse OpenAI models\"", shape=note, fillcolor="#f1f5f9", color="#94a3b8", fontsize=9]; + steer1 -> cy [style=dashed, arrowhead=none, color="#94a3b8"]; + steer2 -> gds [style=dashed, arrowhead=none, color="#94a3b8"]; + steer3 -> emb [style=dashed, arrowhead=none, color="#94a3b8"]; +} diff --git a/docs/examples/exploration-diagrams/01-method-escalation.png b/docs/examples/exploration-diagrams/01-method-escalation.png new file mode 100644 index 00000000..bcc7620a Binary files /dev/null and b/docs/examples/exploration-diagrams/01-method-escalation.png differ diff --git a/docs/examples/exploration-diagrams/02-agent-cooccurrence.dot b/docs/examples/exploration-diagrams/02-agent-cooccurrence.dot new file mode 100644 index 00000000..93704164 --- /dev/null +++ b/docs/examples/exploration-diagrams/02-agent-cooccurrence.dot @@ -0,0 +1,52 @@ +digraph AgentCooccurrence { + rankdir=TB; bgcolor="white"; nodesep=0.35; ranksep=0.7; splines=true; + node [shape=box, style="filled,rounded", fontname="Helvetica", fontsize=11, penwidth=1.2]; + edge [fontname="Helvetica", fontsize=8, dir=none]; + labelloc="t"; fontsize=15; fontname="Helvetica-Bold"; + label="Agent co-occurrence -> GDS Louvain communities + PageRank hubs (private, 43 agents)"; + + // hubs (top rank) -- connective glue, top PageRank + { rank=same; + gitops [label="git-ops\nPageRank 5.55", fillcolor="#f59e0b", fontsize=13]; + explorer [label="explorer\nPageRank 5.50", fillcolor="#f59e0b", fontsize=13]; + builder [label="modular-builder\nPageRank 3.11", fillcolor="#fbbf24", fontsize=12]; + } + + subgraph cluster_c3 { + label="Community 3 — foundation build/investigate core (19)"; fontsize=10; + style="rounded,filled"; fillcolor="#f0fdf4"; color="#86efac"; + zen [label="zen-architect", fillcolor="#bbf7d0"]; + bughunt [label="bug-hunter", fillcolor="#bbf7d0"]; + ganalyst [label="graph-analyst", fillcolor="#bbf7d0"]; + dtu [label="dtu-profile-builder", fillcolor="#bbf7d0"]; + sessan [label="session-analyst", fillcolor="#bbf7d0"]; + } + subgraph cluster_c11 { + label="Community 11 — superpowers TDD pipeline (14)"; fontsize=10; + style="rounded,filled"; fillcolor="#eff6ff"; color="#93c5fd"; + impl [label="implementer", fillcolor="#bfdbfe"]; + plan [label="plan-writer", fillcolor="#bfdbfe"]; + crev [label="code-reviewer", fillcolor="#bfdbfe"]; + fileops [label="file-ops", fillcolor="#bfdbfe"]; + } + subgraph cluster_c23 { + label="Community 23 — research / expert consult (6)"; fontsize=10; + style="rounded,filled"; fillcolor="#faf5ff"; color="#d8b4fe"; + webres [label="web-research", fillcolor="#e9d5ff"]; + setupdtu [label="setup-digital-twin", fillcolor="#e9d5ff"]; + secg [label="security-guardian", fillcolor="#e9d5ff"]; + } + + // top co-occurring edges (weights = sessions together) + explorer -> gitops [label="69", penwidth=4.0, color="#334155"]; + gitops -> builder [label="34", penwidth=2.6, color="#334155"]; + explorer -> builder [label="32", penwidth=2.5, color="#334155"]; + bughunt -> gitops [label="21", penwidth=1.8, color="#64748b"]; + setupdtu -> gitops [label="17", penwidth=1.6, color="#64748b"]; + ganalyst -> explorer[label="14", penwidth=1.4, color="#64748b"]; + + gitops -> zen [color="#a7f3d0"]; gitops -> sessan [color="#a7f3d0"]; explorer -> dtu [color="#a7f3d0"]; + impl -> plan [color="#bfdbfe"]; impl -> crev [color="#bfdbfe"]; impl -> fileops [color="#bfdbfe"]; + webres -> secg [color="#e9d5ff"]; + builder -> impl [style=dashed, color="#cbd5e1"]; +} diff --git a/docs/examples/exploration-diagrams/02-agent-cooccurrence.png b/docs/examples/exploration-diagrams/02-agent-cooccurrence.png new file mode 100644 index 00000000..ff5b07bb Binary files /dev/null and b/docs/examples/exploration-diagrams/02-agent-cooccurrence.png differ diff --git a/docs/examples/exploration-diagrams/03-delegation-star.dot b/docs/examples/exploration-diagrams/03-delegation-star.dot new file mode 100644 index 00000000..fa2365e3 --- /dev/null +++ b/docs/examples/exploration-diagrams/03-delegation-star.dot @@ -0,0 +1,34 @@ +digraph DelegationStar { + rankdir=LR; bgcolor="white"; nodesep=0.25; ranksep=1.3; splines=true; + node [shape=box, style="filled,rounded", fontname="Helvetica", fontsize=11]; + edge [color="#94a3b8", fontname="Helvetica", fontsize=9]; + labelloc="t"; fontsize=15; fontname="Helvetica-Bold"; + label="Delegation topology: a STAR from root sessions (94%) -> most-delegated-to agents (PageRank)"; + + root [label="ROOT / MAIN sessions\n(agent = NULL)\n94.2% of all\n2,598 delegations", shape=box, style="filled,bold,rounded", fillcolor="#fca5a5", color="#b91c1c", fontsize=13, width=2.0]; + + { rank=same; + gitops [label="git-ops\nin-deg 479 | PR 6.91", fillcolor="#f59e0b", fontsize=12]; + explorer [label="explorer\nin-deg 228 | PR 4.35", fillcolor="#fbbf24", fontsize=12]; + builder [label="modular-builder\nin-deg 174 | PR 1.29", fillcolor="#fde68a"]; + ganalyst [label="graph-analyst\nin-deg 71 | PR 1.26", fillcolor="#fde68a"]; + impl [label="implementer\nin-deg 59", fillcolor="#fef3c7"]; + deploy [label="deployment-guide\nin-deg 47", fillcolor="#fef3c7"]; + bughunt [label="bug-hunter\nin-deg 36", fillcolor="#fef3c7"]; + } + + root -> gitops [penwidth=5.0, color="#475569"]; + root -> explorer [penwidth=3.2, color="#475569"]; + root -> builder [penwidth=2.6]; + root -> ganalyst [penwidth=1.6]; + root -> impl [penwidth=1.4]; + root -> deploy [penwidth=1.2]; + root -> bughunt [penwidth=1.2]; + + // the rare agent->agent sub-delegation + PageRank-inheritance finding + navi [label="session-navigator\nin-deg only 6\nyet PageRank RANK #5", fillcolor="#ddd6fe", color="#7c3aed", fontsize=10]; + ganalyst -> navi [label="rare agent->agent;\nPageRank inherited\nfrom a central node", style=dashed, color="#7c3aed", fontsize=8]; + + note [label="Named agents almost never delegate onward\n(11 total): a shallow star, not a deep chain.", shape=note, fillcolor="#f1f5f9", color="#94a3b8", fontsize=9]; + { rank=same; root; note; } +} diff --git a/docs/examples/exploration-diagrams/03-delegation-star.png b/docs/examples/exploration-diagrams/03-delegation-star.png new file mode 100644 index 00000000..b2236584 Binary files /dev/null and b/docs/examples/exploration-diagrams/03-delegation-star.png differ diff --git a/docs/examples/exploration-diagrams/04-gds-session-clustering.dot b/docs/examples/exploration-diagrams/04-gds-session-clustering.dot new file mode 100644 index 00000000..95eaa69a --- /dev/null +++ b/docs/examples/exploration-diagrams/04-gds-session-clustering.dot @@ -0,0 +1,42 @@ +digraph GdsSessionClustering { + rankdir=LR; bgcolor="white"; nodesep=0.35; ranksep=0.9; + node [fontname="Helvetica", fontsize=10]; + edge [color="#64748b", fontname="Helvetica", fontsize=9]; + labelloc="t"; fontsize=15; fontname="Helvetica-Bold"; + label="GDS transformation: sessions -> TF-IDF tool-vectors -> kNN -> Louvain (19 communities, Q=0.862)"; + + // stage 1: raw graph (bipartite session-tool) + subgraph cluster_raw { + label="1. graph (read-only)"; style="rounded,filled"; fillcolor="#f8fafc"; color="#cbd5e1"; fontsize=10; + s1 [label="Session", shape=ellipse, style=filled, fillcolor="#e0e7ff"]; + s2 [label="Session", shape=ellipse, style=filled, fillcolor="#e0e7ff"]; + s3 [label="Session", shape=ellipse, style=filled, fillcolor="#e0e7ff"]; + tb [label="bash", shape=box, style="filled,rounded", fillcolor="#fee2e2"]; + tr [label="read_file", shape=box, style="filled,rounded", fillcolor="#fef9c3"]; + tg [label="graph_query",shape=box, style="filled,rounded", fillcolor="#dcfce7"]; + s1 -> tb [label="USES", fontsize=7]; s1 -> tr [fontsize=7]; + s2 -> tb [fontsize=7]; s2 -> tg [fontsize=7]; + s3 -> tr [fontsize=7]; s3 -> tb [fontsize=7]; + } + + // stage 2: TF-IDF vectors + vec [label="2. per-session\nTF-IDF tool vector\n(32 dims)\ndown-weights ubiquitous\nbash / read_file / todo", shape=box, style="filled,rounded", fillcolor="#ede9fe", color="#7c3aed"]; + + // stage 3: knn similarity graph + knn [label="3. gds.knn (cosine)\n2,030 nodes\n20,300 SIMILAR edges", shape=box, style="filled,rounded", fillcolor="#dbeafe", color="#2563eb"]; + + // stage 4: louvain communities + subgraph cluster_comm { + label="4. gds.louvain -> 19 workload communities"; style="rounded,filled"; fillcolor="#f0fdf4"; color="#86efac"; fontsize=10; + c1 [label="pure shell/ops\n344", shape=box, style="filled,rounded", fillcolor="#fecaca"]; + c2 [label="edit+python\nimpl 158", shape=box, style="filled,rounded", fillcolor="#bfdbfe"]; + c3 [label="grep/read\nrecon 165", shape=box, style="filled,rounded", fillcolor="#fde68a"]; + c4 [label="delegate/todo\norchestration 156", shape=box, style="filled,rounded", fillcolor="#ddd6fe"]; + c5 [label="graph_query\nanalysis 49", shape=box, style="filled,rounded", fillcolor="#bbf7d0"]; + c6 [label="web research\n89", shape=box, style="filled,rounded", fillcolor="#fbcfe8"]; + } + + s1 -> vec [ltail=cluster_raw, style=bold]; + vec -> knn [style=bold]; + knn -> c1 [lhead=cluster_comm, style=bold]; +} diff --git a/docs/examples/exploration-diagrams/04-gds-session-clustering.png b/docs/examples/exploration-diagrams/04-gds-session-clustering.png new file mode 100644 index 00000000..69138ef3 Binary files /dev/null and b/docs/examples/exploration-diagrams/04-gds-session-clustering.png differ diff --git a/docs/examples/exploration-diagrams/05-machinery-vs-mission.dot b/docs/examples/exploration-diagrams/05-machinery-vs-mission.dot new file mode 100644 index 00000000..fdb271e6 --- /dev/null +++ b/docs/examples/exploration-diagrams/05-machinery-vs-mission.dot @@ -0,0 +1,44 @@ +digraph MachineryVsMission { + rankdir=LR; bgcolor="white"; nodesep=0.25; ranksep=1.4; + node [fontname="Helvetica", fontsize=10, shape=box, style="filled,rounded"]; + edge [fontname="Helvetica", fontsize=8]; + labelloc="t"; fontsize=15; fontname="Helvetica-Bold"; + label="The key discovery: tool-behaviour clusters the MACHINERY, prompt-embeddings cluster the MISSION (near-orthogonal)"; + + // center: the same sessions + sessions [label="the SAME\nsessions\n(3,199)", shape=cylinder, fillcolor="#e0e7ff", color="#4338ca", fontsize=12, width=1.4]; + + // LEFT lens: tool-behaviour (GDS) -> role/step + subgraph cluster_tools { + label="LENS A — tool-vectors -> GDS Louvain (19 comm, Q=0.862)\n= workflow ROLE / STEP"; fontsize=10; + style="rounded,filled"; fillcolor="#f0fdf4"; color="#86efac"; + b1 [label="shell/ops step", fillcolor="#fecaca"]; + b2 [label="implement step", fillcolor="#bfdbfe"]; + b3 [label="review step", fillcolor="#fde68a"]; + b4 [label="commit step", fillcolor="#e9d5ff"]; + } + + // RIGHT lens: embeddings -> objective + subgraph cluster_obj { + label="LENS B — prompt-embeddings -> k-means\n= human MISSION / OBJECTIVE"; fontsize=10; + style="rounded,filled"; fillcolor="#faf5ff"; color="#d8b4fe"; + o1 [label="spec / code review", fillcolor="#fbcfe8"]; + o2 [label="council persona review\n(~900 sessions)", fillcolor="#fbcfe8"]; + o3 [label="implement one task", fillcolor="#bfdbfe"]; + o4 [label="git / submodule / PR ops", fillcolor="#fed7aa"]; + o5 [label="CI-server / dashboard build", fillcolor="#bbf7d0"]; + } + + sessions -> b1 [color="#16a34a"]; sessions -> b2 [color="#16a34a"]; + sessions -> b3 [color="#16a34a"]; sessions -> b4 [color="#16a34a"]; + sessions -> o1 [color="#9333ea"]; sessions -> o2 [color="#9333ea"]; + sessions -> o3 [color="#9333ea"]; sessions -> o4 [color="#9333ea"]; sessions -> o5 [color="#9333ea"]; + + // the orthogonality: ONE objective (git ops) is spread across ~all behaviour steps + o4 -> b1 [label="git-ops objective\nlands in 18 of 19\nbehaviour clusters", style=dashed, color="#dc2626", constraint=false, fontsize=8]; + o4 -> b2 [style=dashed, color="#dc2626", constraint=false]; + o4 -> b3 [style=dashed, color="#dc2626", constraint=false]; + o4 -> b4 [style=dashed, color="#dc2626", constraint=false]; + + note [label="same goal -> many tool-fingerprints;\nsame tool-fingerprint -> many goals.\nYou need BOTH lenses.", shape=note, fillcolor="#fff7ed", color="#ea580c", fontsize=9]; +} diff --git a/docs/examples/exploration-diagrams/05-machinery-vs-mission.png b/docs/examples/exploration-diagrams/05-machinery-vs-mission.png new file mode 100644 index 00000000..cf8b53b6 Binary files /dev/null and b/docs/examples/exploration-diagrams/05-machinery-vs-mission.png differ diff --git a/docs/examples/graph-exploration-walkthrough.md b/docs/examples/graph-exploration-walkthrough.md new file mode 100644 index 00000000..668bafe7 --- /dev/null +++ b/docs/examples/graph-exploration-walkthrough.md @@ -0,0 +1,250 @@ +# Example: Mining "how do we actually work?" from the Context-Intelligence graph + +> **What this is.** A worked, end-to-end example of using **context-intelligence** as an +> analytics substrate over your own Amplifier history — starting from a plain-language +> question, escalating through graph queries → **Neo4j GDS** graph algorithms → **LLM +> embeddings for semantic clustering**, and ending at a discovery none of the individual +> steps could reach alone. +> +> It is meant as a template for **what to ask** and **what context-intelligence can do**. It +> pairs with the [`context-intelligence-gds`](../../skills/context-intelligence-gds) skill (the +> reusable *procedure*) and [`context-intelligence-exploration-guide.md`](../context-intelligence-exploration-guide.md) +> (the *how-to*) — this doc is the worked *narrative* that shows them in action end to end. + +--- + +## TL;DR — the discovery + +Two very different notions of "similar sessions" fall out of the same graph, and they are +**near-orthogonal**: + +- **By tool behaviour** (which tools a session calls, and in what chains) sessions cluster by + **workflow ROLE / step** — *implement-step*, *review-step*, *commit-step*. GDS Louvain found + **19 clean communities at modularity Q = 0.862**. +- **By objective** (what the opening prompt actually asks for, via embeddings) sessions cluster + by **MISSION** — *spec review*, *council review*, *git/submodule ops*, *CI-server build*. + +> **The punchline:** *tool-vectors cluster the machinery; prompt-embeddings cluster the mission.* +> In an agent-orchestrated workflow one human objective ("ship this bundle") fans out into +> implement/review/commit sub-steps whose tool fingerprints are fixed by **role**, not **goal** — +> so behaviour-similarity and objective-similarity measure different things. You need both lenses, +> and the graph carries the data for both. + +--- + +## Visualising the transformations + +Each rung reshapes the same session data into a different grouping. The DOT sources and rendered +PNGs live in [`exploration-diagrams/`](./exploration-diagrams/). + +**1. How the search escalated** — one question at a time, each needing a stronger tool than the +last; the human steering (dashed notes) is what redirected each rung. + +![Method escalation](./exploration-diagrams/01-method-escalation.png) + +**2. Agent co-occurrence → GDS communities + PageRank hubs** — who works with whom. `git-ops` and +`explorer` are connective hubs (top PageRank); Louvain splits the rest into a foundation +build/investigate core and a superpowers TDD pipeline. + +![Agent co-occurrence communities](./exploration-diagrams/02-agent-cooccurrence.png) + +**3. Delegation topology** — a shallow **star from the root session** (94% of delegations), not a +deep agent-delegates-agent chain. PageRank surfaces `session-navigator` (rank #5 on only 6 +delegations — importance inherited from a central delegator). + +![Delegation star](./exploration-diagrams/03-delegation-star.png) + +**4. The GDS session-clustering transformation** — the read-only graph is projected +(`gds.graph.project.cypher`) into per-session TF-IDF tool-vectors → `gds.knn` similarity graph → +`gds.louvain` communities (19 workloads, Q = 0.862). + +![GDS session clustering](./exploration-diagrams/04-gds-session-clustering.png) + +**5. The key discovery — machinery vs mission** — the *same* sessions clustered two ways are +near-orthogonal: tool-vectors cluster the workflow ROLE/step; prompt-embeddings cluster the human +MISSION. One objective (git-ops) scatters across 18 of 19 behaviour clusters (red dashed). + +![Machinery vs mission](./exploration-diagrams/05-machinery-vs-mission.png) + +--- + +## The corpus explored + +Two live context-intelligence servers were queried (read-only surface, `source` provenance +recorded on every result): + +| Server | Sessions | Tool calls | Distinct agents | Delegations | Notes | +|---|---:|---:|---:|---:|---| +| **team-shared** (`…azure-api.net/context-intelligence`) | ~2,065 | ~42,450 | 52 | 1,696 | multi-user; APIM-fronted; `/cypher` **read-only** | +| **private-home-server** (`localhost:8000`) | ~3,375 | 56,653 | 44 | 2,598 | single-user; Neo4j Community + **GDS free**; read-only store but **usable GDS in-memory catalog** | + +The final semantic pass embedded **3,199 first-prompts** (866 root / 2,333 delegated sub-sessions; +median prompt length ~4,150 chars). + +--- + +## How the search started, and how it escalated + +It began as a simple curiosity and deepened one question at a time. Each rung needed a stronger +tool than the last — which is the real lesson of the example. + +### Rung 1 — plain graph queries (Cypher) +**Q: "What are the most common sets of agents used together in sessions?"** +Group `Delegation` nodes by `parent_session_id`, collect the distinct agents per session, count +co-occurring pairs/triples. +- **Finding:** a **"build core" triad** — `foundation:explorer` + `foundation:git-ops` + + `foundation:modular-builder` — recurs far more than any other (the explore → implement → commit + loop). `git-ops` is the near-universal hub. + +**Q: "Which agent delegates the most in a single session?"** +- **Finding (and a schema trap):** `Delegation.agent` is the *delegated-TO* agent, not the + delegator. Joining `parent_session_id → Session.agent` shows **~94% of all delegations are + issued by the root/main session** (`agent IS NULL`), not by any named agent. The topology is a + **star from the user's root**, not a deep agent-delegates-agent chain. Top session: + `3dae554e…` — **100 delegations across 10 distinct agents** in one body of work. + +### Rung 2 — GDS graph algorithms (the "better way") +**Q: "How many sessions had very similar behaviour, and what are the workloads? Is there a +better way using GDS?"** + +First attempt on **team-shared** hit an honest wall: GDS is *installed* (v2026.05.0, 471 +procedures) but every `gds.graph.project` / write returned **HTTP 500** — the APIM `/cypher` +proxy runs in **read-only transaction mode**, and GDS projection needs a writable in-memory +catalog. *(Steering: "this is neo4j community with gds free" — correctly reframing the blocker +as the read-only endpoint, not a licence/edition limit.)* + +**Re-run against the private destination** *(steering: "try the same queries with GDS but against +the private destination")* — where GDS's in-memory catalog **does** work even though the store is +read-only. Built every graph with `gds.graph.project.cypher` (derived, **no store writes**): + +| Analysis | GDS pipeline | Result | +|---|---|---| +| **Session behaviour clustering** | per-session **TF-IDF tool-vectors** → `gds.knn` (cosine) → `gds.louvain` | **19 communities, Q = 0.862** — strong, clean workload separation | +| **Agent co-occurrence** | derived agent–agent graph → `gds.louvain` + `gds.degree`/`gds.pageRank` | two loose "teams" + `git-ops`/`explorer` as connective hubs (top PageRank 5.5–6.9) | +| **Delegation centrality** | bipartite parent→agent → `gds.pageRank` | confirmed the root-star (94%); PageRank surfaced `session-navigator` (rank 5 on only 6 delegations — inherited importance) | +| **Agent behaviour similarity** | per-agent TF-IDF tool-vectors → `gds.knn` → `gds.louvain` | **9 clusters, Q = 0.61** — shell/ops, plan-build, expert-review, read/explore, pure-reviewers; `graph-analyst` a genuine singleton outlier | + +**APOC** was used inside the Cypher projections (`apoc.map.fromPairs` to build per-session +tool-frequency maps, `apoc.coll.sort` to canonicalise agent-sets). + +**Honest GDS limits found (not worked around, reported):** `gds.nodeSimilarity` and `gds.fastRP` +require materialised `Tool` nodes for a Session→Tool bipartite — impossible against a read-only +store — so they were **not** run; TF-IDF-weighted `gds.knn` was the faithful substitute (and +TF-IDF is exactly the "down-weight ubiquitous `bash`" job fastRP would have done). Weighted +Louvain `.stats`/`.mutate` also 500'd under the read-only wrapper; `.stream` + scalar `.stats` +were used. Nothing that didn't run was reported as if it had. + +### Rung 3 — the key negative result +**Q: "But what were the similar sessions actually trying to do — similar tasks? similar +objectives?"** + +Cross-tabbing the tool-behaviour clusters against the *objective* (workspace + first prompt) +showed behaviour-similarity **does not** track objective: +- The same project (`session-preparer-spike`) is a top workspace in **13 of 19** behaviour clusters. +- The same objective scatters: **git-ops lands in 18 of 19** behaviour clusters; "SUBAGENT + IMPLEMENTATION TASK" splits across 5; "SPEC COMPLIANCE REVIEW" across 8. + +Tool behaviour was clustering *how the step was executed*, not *what it was for*. + +### Rung 4 — embeddings for semantic clustering (no embedding infra? use OpenAI) +*(Steering: "try reading the inline prompts; I don't have access to embedding models unless you +can work out how to use the models on OpenAI.")* + +The graph stores each session's first user prompt **inline** (`Prompt.prompt`) — no blob hop +needed. Pipeline: +1. Export `(session_id, workspace, is_root, agent, prompt)` for **3,199 sessions** read-only from + the graph to a JSONL file (server-side truncation + newline-strip in Cypher; nothing heavy + pulled through context). +2. Embed each prompt with **OpenAI `text-embedding-3-small`** (1536-dim, batched). +3. **k-means** cluster (root-only k=16 for human objectives; all k=20), characterise each cluster + by TF-IDF top terms, workspace mix, and the 3 prompts nearest the centroid. + +**This is the step that produced the final discovery** — coherent, human-legible **objective** +clusters that the graph-and-GDS tool analysis had scattered. + +--- + +## The objective map (what people were actually trying to do) + +From the 866 **root** sessions (human-initiated goals), the dominant missions on this corpus: + +| Objective cluster | ~Sessions | Signature prompt | +|---|---:|---| +| Implement one task (recipe subagent-impl) | ~167 | *"SUBAGENT IMPLEMENTATION TASK … implement ONE specific task"* | +| Continue CI dashboard / admin-UX build | 113 | *"Continue the Context Intelligence dashboard + admin UX design/build"* | +| Bundle hygiene analysis | 88 | *"MODE: ANALYZE … hygiene violations"* | +| Final comprehensive code review | 66 | *"FINAL COMPREHENSIVE CODE REVIEW … the ENTIRE implementation"* | +| Spec-compliance review | 63 | *"SPEC COMPLIANCE REVIEW … verify implementation matches spec"* | +| Free-form server/config debugging | 59 | *"cannot publish events to the CI server, check settings.yaml/keys.env"* | +| Git submodule / branch / push ops | 49 | *"Update the git submodule … to latest main"* | +| Code-quality review / spec-fix | 40 | *"CODE QUALITY REVIEW Stage 2 of 2"* | +| Council: convene the persona panel | 37 | *"You are the concierge. Orchestrate a panel of review lenses…"* | +| Clone repo as submodule + set up workspace | 37 | *"clone … as submodule, then update agents.md"* | +| Rewrite DOT diagram labels | 32 | *"MODE: ARCHITECT … rewriting the labels of a DOT diagram"* | +| TDD / mock-vs-real testing discipline | 28 | (tdd-depth context) | +| Review a specific PR | 26 | *"review carefully PR …/pull/48 and the comments"* | + +Across **all 3,199** sessions the single biggest activity family is **multi-persona / council +review** (per-lens "review AS THAT PERSONA" + council cross-examination rounds) — **~900+ +sessions**. Objectives cut **across** projects: the same *workflow* (review → implement → commit) +is applied to many different repos. + +**Meta-finding about this corpus:** it is almost entirely **Amplifier / context-intelligence +self-development** — building and reviewing the context-intelligence bundle and server itself, +with review work (persona/council/spec/quality) as the dominant motion. + +--- + +## The steering that shaped it (why the human-in-the-loop mattered) + +Each correction moved the analysis from "plausible" to "true": + +1. **"By session I mean any root or forked or subsession — the one that directs the most agents."** + Forced the delegator question to treat every session node equally and to prove root-vs-sub with + a delegation-target test — which is how the 94%-root-star topology surfaced honestly. +2. **"This is neo4j community with gds free."** + Reframed the GDS failure correctly: not a licence wall, a **read-only-endpoint** wall. Kept us + from filing a wrong conclusion. +3. **"Try the same queries with GDS but against the private destination."** + Pointed at the one server whose GDS in-memory catalog is usable — turning "GDS would be better" + into an actual Q = 0.862 result. +4. **"Try reading the inline prompts; use OpenAI models if you can."** + The decisive pivot from *machinery* to *mission*. Semantic embedding is what answered the + original question the tool analysis kept missing. + +--- + +## What this demonstrates context-intelligence can do + +- **Answer "how do we actually work?"** from real history — agent teaming, delegation topology, + tool-usage fingerprints — with **provenance on every result**. +- **Serve as a graph substrate for real graph algorithms** — GDS community detection, KNN, and + centrality run directly on projected views of the session graph (Community + free GDS is enough). +- **Feed semantic analysis** — inline prompts (and blobs) are the raw material for embedding-based + **objective** clustering when tool-structure alone is too coarse. +- **Stay honest under constraints** — read-only endpoints, unavailable algorithms, and schema + traps (`Delegation.agent` = delegated-TO, not delegator) were reported, not papered over. + +## Honesty caveats (part of the example) + +- **Read-only store** on both servers: GDS projections must be *derived* (`gds.graph.project.cypher`), + and `nodeSimilarity`/`fastRP` (which need writable `Tool` nodes) could not run. +- **Single-user private corpus** heavily weighted to CI/Amplifier self-development — absolute + numbers won't generalise; the *method* does. +- **Prompt truncation** to 1,500 chars (~89% of prompts were longer); objectives are usually + stated up front, but a higher cap is the first lever if edges look muddy. +- **Louvain unavailable on one projection** (500 under the read-only wrapper) → k-means substituted + on the same normalised vectors (Euclidean-on-normalised ≡ cosine), noted as a faithful stand-in. + +--- + +## Reproducing it + +1. **Ask a lens question** in plain language; let the `graph-analyst` translate to Cypher. +2. **Escalate to GDS** on a server with a usable catalog (Neo4j Community + free GDS): derive a + graph via `gds.graph.project.cypher`, then `gds.knn` + `gds.louvain` (+ `pageRank` for hubs). + Use **TF-IDF-weighted vectors** to defeat glue-tool (`bash`/`read_file`/`todo`) dominance. +3. **Go semantic** when the question is about *intent*: export inline prompts read-only, embed with + an LLM embedding model (e.g. OpenAI `text-embedding-3-small`), k-means, and characterise + clusters by top terms + nearest-centroid exemplars. +4. **Keep the human in the loop** — the steering, not the machinery, is what made the answer true.