Showcase / Multi-Agent + Knowledge

The Learning Code Pair

An AI pair programmer that gets smarter every time you use it.

learning_pair.toml

The Problem

Every coding session with an AI starts from scratch. The agent has no memory of what you built yesterday, what decisions you made, or what patterns you established. Each session wastes time re-discovering the same context.

What if your AI pair programmer remembered every architectural decision and got smarter over time?

The Config

learning_pair.toml defines a quorum — a multi-agent system with a planner that remembers and a coder that implements. The planner carries knowledge tools; the coder carries editing tools. Separation of concerns at the agent level.

Quorum configuration

[quorum]
cwd = "."
db = "/tmp/learning_pair.db"   # Persistent knowledge store
delegation = true               # Enable planner → coder delegation
verification = false
snapshot_policy = "diff"        # Track file changes via git diff
delegation_wait_policy = "all"
max_parallel_delegations = 1

Planner: the knowledge-bearing orchestrator

[planner]
provider = "anthropic"
model = "claude-sonnet-4-5-20250929"
tools = [
  "delegate",                # Send tasks to the coder

  # Knowledge lifecycle — the planner's unique capability
  "knowledge_ingest",
  "knowledge_query",
  "knowledge_consolidate",
  "knowledge_list_unconsolidated",
  "knowledge_stats",

  # Planning & exploration (read-only)
  "read_tool", "index", "search_text", "glob", "ls",

  "create_task", "todowrite", "todoread",
  "question",
]
Knowledge on the planner, not the coder

The planner is the only agent with knowledge tools. It queries past decisions before planning, then ingests new lessons after reviewing the coder's work. The coder is stateless — pure implementation. This separation keeps knowledge clean and consolidated.

Planner middleware: agent mode

[[planner.middleware]]
type = "context"
warn_at_percent = 80
compact_at_percent = 90
fallback_max_tokens = 128000

[[planner.middleware]]
type = "agent_mode"
default = "plan"
reminder = """# Plan Mode — Knowledge-Driven Orchestrator
You are the planner. You must NOT edit files.
1. Query knowledge before planning
2. Break work into concrete tasks
3. Delegate implementation to coder
4. Ingest decisions and lessons"""
Agent mode middleware

The agent_mode middleware injects a system reminder on every turn, keeping the planner in "plan" mode. It won't accidentally start writing code — that's the coder's job. Switch modes via the dashboard with Ctrl+M.

Delegation summary: cheap model for results

[quorum.delegation_summary]
provider = "anthropic"
model = "claude-haiku-4-5-20251001"  # Cheaper model

When the coder finishes a task, the result is summarized by a cheaper model before being sent back to the planner. This keeps context costs low — the planner sees a summary, not the full diff.

Coder delegate: pure implementation

[[delegates]]
id = "coder"
provider = "anthropic"
model = "claude-sonnet-4-5-20250929"
description = "Implementation specialist..."
capabilities = ["rust", "python", "typescript", "shell"]
tools = [
  "edit", "write_file", "read_tool", "index",
  "glob", "search_text", "ls",
  "shell",
  "todowrite", "todoread",
]

Coder middleware: limits + dedup check

[[delegates.middleware]]
type = "limits"
max_steps = 80
max_turns = 25

[[delegates.middleware]]
type = "context"
warn_at_percent = 80
compact_at_percent = 90

# Detect duplicate code in coder output
[[delegates.middleware]]
type = "dedup_check"
threshold = 0.85    # 85% similarity threshold
min_lines = 10     # Only check blocks >= 10 lines
Dedup check middleware

The dedup_check middleware detects when the coder is about to write code that's 85%+ similar to existing code in the project. It catches copy-paste patterns and encourages DRY implementation.

Lifecycle Over Multiple Sessions

The magic happens across sessions. Knowledge persists in SQLite. The planner gets smarter every time.

Session 1
You: "Add rate limiting to the API"

Planner queries knowledge: empty (first time)
Planner analyzes codebase via read-only tools
Planner plans: "Need middleware layer, token bucket, tests"
Planner delegates to coder → coder implements
Planner reviews and ingests: "We used a token bucket approach with Redis backend. Middleware placed before auth layer."
Session 2 (next day)
You: "Add authentication to the API"

Planner queries knowledge: finds "token bucket, Redis backend, middleware before auth" from yesterday
Planner plans informed by past decisions: "Place auth middleware after rate limiter, consistent with existing pattern"
Planner delegates → coder implements (consistent with existing architecture)
Planner ingests: "Auth uses JWT, middleware consistent with rate limiting pattern"
Session 3+
Each session adds to the knowledge graph. The planner's plans become more consistent with the project's architecture. Consolidation merges related entries: "API middleware uses a layered pattern: rate limiting → auth → routing."

The Delegation Flow

1. Knowledge query Planner checks what it already knows about this codebase and task type.
2. Plan Planner breaks the task into steps informed by past decisions.
3. Delegate Planner sends implementation to coder with full context.
4. Implement Coder writes code, runs tests, produces results.
5. Ingest lessons Planner reviews results and stores new knowledge for next time.

Key Features

  • Knowledge lifecycle — ingest, query, consolidate across sessions
  • Multi-agent quorum — planner delegates to specialized coder
  • Delegation summary — cheap model summarizes coder output for the planner
  • Agent mode middleware — keeps the planner in "plan" mode, not "build" mode
  • Dedup check — catches duplicate code before it's written
  • Context-aware delegation — past knowledge shapes current plans

Try It Yourself

# Run the learning pair
cargo run --example qmtcode --features dashboard -- \
  confs/learning_pair.toml --dashboard

# Session 1: Ask it to build something
#   "Add rate limiting to the API"

# Session 2 (restart, same db): Ask it to build something related
#   "Add authentication to the API"
#   Notice: the planner uses knowledge from session 1

# Optional: Create a consolidation schedule
#   Trigger: Interval, 3600s (hourly)
#   Prompt: "Run knowledge consolidation..."
#   Max runs: 24