Overview

Loop is a Cargo workspace. The default path is a terminal TUI (loop-cli) or, separately, a GPUI desktop beta (loop-desktop). Both sit on loop-app-core. MCP is in the default build. Orchestration and telemetry are crates you opt into with Cargo features.

High-Level Architecture

Dependency flow: loop-cli / loop-desktop → loop-app-core → loop-agent → loop-ai. loop-mcp is linked by default. loop-orchestration and loop-telemetry are optional and are not linked unless the matching feature is on.

Request Flow

A typical agent turn follows this flow:
Workflows use start_workflow / start_workflow_from_goal instead of prompt(), with an optional progress channel for live WorkflowProgressEvents (task started / completed / failed).

Design Principles

Separation of Concerns

Each crate owns a distinct layer:
  • loop-ai knows nothing about tools, sessions, or UI
  • loop-agent knows nothing about TUI or desktop rendering
  • loop-app-core shares bootstrap/config between surfaces
  • loop-cli / loop-desktop are the only crates with UI code
  • loop-orchestration is fully optional (feature-gated)

Trait-Based Abstraction

Key extension points use traits:

Event Sourcing (Orchestration)

The orchestration layer uses event sourcing for all state transitions:
  • Every action is recorded as an event
  • State can be rebuilt by replaying events
  • subscribe() broadcasts live events; harness progress channel feeds UI cards
  • Enables debugging, forking, and recovery

Streaming Throughout

From LLM response to UI rendering, everything streams:
  • AssistantMessageEvent protocol carries streaming chunks
  • TUI / desktop render markdown incrementally
  • Tool and workflow task cards update in real-time

Session Data Model

Sessions form a tree structure:
Each message has a parent pointer, enabling:
  • Branching at any point
  • Multiple continuations from the same message
  • Tree navigation with /tree
  • Session forking with /fork

Feature Flags

  • sqlite — SQLite sessions (on by default in loop-agent)
  • proxy — HTTP client for model calls (on by default in loop-agent)
  • mcp — MCP client and --serve-mcp (on by default in loop-cli)
  • orchestration — /workflow (off)
  • telemetry — /tracing and --trace-* (off)

Build Targets

Loop builds as a single optimized binary: Release builds use LTO, single codegen unit, and symbol stripping for minimum binary size.