Skip to main content

Loom Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Loom Orchestrator                          β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚   Scorer     β”‚  β”‚  Hook Engine β”‚  β”‚  Retros      β”‚          β”‚
β”‚  β”‚  (Priority)  β”‚  β”‚  (Lifecycle) β”‚  β”‚  (Learning)  β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚  Coordinator β”‚  β”‚  Memory Mgr  β”‚  β”‚  Safety      β”‚          β”‚
β”‚  β”‚  (Multi-Agt) β”‚  β”‚  (Compact)   β”‚  β”‚  (Guards)    β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Beads (bd) Layer                             β”‚
β”‚                                                                  β”‚
β”‚   bd ready, create, update, close, dep, show, compact...        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           v
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Dolt Database                                β”‚
β”‚                    (.beads/dolt/)                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

1. Orchestrator

The main loop that drives the orchestration:
  1. Gets ready tasks from Beads
  2. Scores and ranks them
  3. Claims the top task
  4. Delegates work to agents
  5. Closes completed tasks
  6. Repeats until interrupted
Location: internal/orchestrator/orchestrator.go

2. Task Scorer

Implements AI-driven task prioritization:
Score = (blocking_count Γ— 3) + (priority_boost Γ— 2) + staleness_bonus - failure_penalty
Factors considered:
  • Blocking impact: Tasks that unblock others
  • Priority level: P0/P1 tasks get boosted
  • Staleness: Tasks open too long
  • Failure history: Previously failed tasks penalized
Location: internal/scorer/scorer.go

3. Hook Engine

Manages lifecycle hooks that inject behavior at key points:
HookWhen
pre-promptBefore LLM processes prompt
pre-tool-callBefore tool execution
post-tool-callAfter tool execution
post-responseAfter agent response
on-errorOn task failure
on-claimOn task claim
pre-closeBefore task close
on-blockWhen task becomes blocked
Location: internal/hooks/engine.go

4. Multi-Agent Coordinator

Enables safe parallel work:
  • File-level locking
  • Conflict detection
  • Lock expiration
  • Automatic cleanup
Location: internal/coordinator/coordinator.go

5. Retrospective Store

Captures learning from sessions:
  • Task completion/failure tracking
  • Pattern extraction
  • Global knowledge sharing
  • Failure history for scoring
Location: internal/retrospective/store.go

6. Memory Manager

Intelligent context management:
  • Tracks context usage
  • Triggers compaction at threshold
  • Importance-weighted retention
  • Preserves critical context
Location: internal/memory/manager.go

7. Safety Guard

Protects against dangerous operations:
  • Blocks destructive commands (rm -rf, git push β€”force)
  • Requires confirmation for risky operations
  • Maintains approval cache
  • Configurable patterns
Location: internal/safety/guard.go

8. Beads Client

CLI wrapper for Beads commands:
  • bd ready --json - Get ready tasks
  • bd show <id> --json - Get task details
  • bd update <id> --claim - Claim task
  • bd close <id> - Close task
  • bd compact - Run compaction
Location: internal/beadsclient/client.go

Data Flow

1. Get Ready Tasks
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ bd ready     β”‚
   β”‚ --json       β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          v
2. Score & Rank
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ TaskScorer   β”‚
   β”‚ .Rank()      β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          v
3. Execute Hooks
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ pre-prompt   β”‚
   β”‚ on-claim     β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          v
4. Claim Task
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ bd update    β”‚
   β”‚ --claim      β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          v
5. Execute Work
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ (Agent)      β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          v
6. Close Task
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ pre-close    β”‚
   β”‚ bd close     β”‚
   β”‚ post-responseβ”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Package Structure

loom/
β”œβ”€β”€ cmd/loom/           # CLI entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ orchestrator/   # Core loop
β”‚   β”œβ”€β”€ scorer/         # Task prioritization
β”‚   β”œβ”€β”€ hooks/          # Lifecycle hooks
β”‚   β”œβ”€β”€ coordinator/    # Multi-agent coordination
β”‚   β”œβ”€β”€ retrospective/  # Learning system
β”‚   β”œβ”€β”€ memory/         # Context management
β”‚   β”œβ”€β”€ safety/         # Safety guards
β”‚   β”œβ”€β”€ beadsclient/    # Beads CLI wrapper
β”‚   └── config/         # Configuration
β”œβ”€β”€ pkg/api/            # Public API
└── docs/               # Documentation

Extension Points

Adding Custom Hooks

orch.RegisterHook(hooks.EventPreToolCall, func(ctx context.Context, hc *hooks.Context) (*hooks.Result, error) {
    // Custom validation logic
    if isDangerous(hc.ToolCall.Command) {
        return &hooks.Result{Block: true, Reason: "dangerous command"}, nil
    }
    return &hooks.Result{}, nil
})

Custom Scoring Factors

type CustomScorer struct {
    *scorer.Scorer
}

func (s *CustomScorer) ScoreTask(ctx context.Context, issue *beadsclient.Issue) (int, error) {
    score, err := s.Scorer.ScoreTask(ctx, issue)
    if err != nil {
        return 0, err
    }

    // Add custom factor
    if hasLabel(issue, "urgent") {
        score += 5
    }

    return score, nil
}

Integration with Beads

Loom requires Beads (bd) to be installed and configured:
# Install beads
go install github.com/uttufy/beads/cmd/bd@latest

# Initialize in your project
cd your-project
bd init
Loom then uses the Beads CLI for all task operations.