# AI agent lanes

> Parallel multi-agent timeline with play controls, lane filters, interactive time scrubber, overlapping span bars and live step inspector.

- Kind: block · Category: Agents · Interactivity: script
- Install: `npx shadcn@latest add @haze/ai-agent-lanes`
- File: `src/components/haze/blocks/ai-agent-lanes.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/ai-agent-lanes

## Use when
- Visualizing concurrent sub-agent execution across overlapping search, read, thinking and write spans
- Letting operators scrub a multi-agent run to inspect exact tool calls and trace outputs at any timestamp

## Avoid when
- Displaying a single linear agent execution trace without parallel workers; use agent-run instead
- Showing only raw tool payloads without time alignment; use ai-tool-calls

## Alternatives
- [agent-orchestrator](https://hazeui.com/blocks/agent-orchestrator.md)
- [agent-run](https://hazeui.com/blocks/agent-run.md)
- [ai-tool-calls](https://hazeui.com/blocks/ai-tool-calls.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-ai-agent-lanes" | no | Unique prefix for headings and scrubber labels. |
| title | `string` | "Plan a 3-day offsite in Zurich for 14 engineers" | no | Task title displayed in the header. |
| duration | `number` | 12 | no | Total run duration in seconds for the timeline scrubber. |
| lanes | `AgentLane[]` | 4 demo lanes | no | Parallel agent lanes and their timed tool spans. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- The timeline scrubber is a native range input labeled Run time, and each horizontal span button carries an explicit lane, tool and time range label.
- Playback state, lane filter selections and scrubbed step updates announce cleanly through a polite role="status" region.
- Key Tab: Move across Play, Reset, lane filter buttons, the Run time scrubber and span bars
- Key ArrowLeft / ArrowRight: Scrub the Run time slider in 0.5 second increments while focused

## Agent prompts

### Install and use

Install the Haze UI block "AI agent lanes" with `npx shadcn@latest add @haze/ai-agent-lanes`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AiAgentLanes from "@/components/haze/blocks/ai-agent-lanes.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/ai-agent-lanes.md

### Customize with real content

Adapt the Haze ai-agent-lanes block for our product. Replace the demo values of these props with our real content: id, title, duration, lanes, class. Keep the layout, the heading level rules and these accessibility details: The timeline scrubber is a native range input labeled Run time, and each horizontal span button carries an explicit lane, tool and time range label. Playback state, lane filter selections and scrubbed step updates announce cleanly through a polite role="status" region. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using ai-agent-lanes, check it fits: use it when visualizing concurrent sub-agent execution across overlapping search, read, thinking and write spans; letting operators scrub a multi-agent run to inspect exact tool calls and trace outputs at any timestamp. Avoid it when displaying a single linear agent execution trace without parallel workers; use agent-run instead; showing only raw tool payloads without time alignment; use ai-tool-calls. Alternatives: @haze/agent-orchestrator, @haze/agent-run, @haze/ai-tool-calls.

## Example requests that should lead here
- Add a parallel AI agent lanes timeline with play controls, lane filter buttons, time scrubber and live tool call inspector
- Build a multi-agent execution Gantt view showing Lead, Flights, Venues and Weather spans across 12 seconds

## Source

```astro
---
import { Pause, Play } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

type ToolKind = "Search" | "Read" | "Thinking" | "Write";

interface AgentSpan {
  id: string;
  start: number;
  end: number;
  tool: ToolKind;
  command: string;
  output: string;
}

interface AgentLane {
  id: string;
  name: string;
  role: string;
  spans: AgentSpan[];
}

interface Props {
  id?: string;
  title?: string;
  duration?: number;
  lanes?: AgentLane[];
  class?: string;
}

const {
  id = "haze-ai-agent-lanes",
  title = "Plan a 3-day offsite in Zurich for 14 engineers",
  duration = 12,
  lanes = [
    {
      id: "lead",
      name: "Lead",
      role: "Coordinator",
      spans: [
        {
          id: "lead-1",
          start: 0,
          end: 2.5,
          tool: "Thinking",
          command: "decompose_offsite_brief(headcount=14, days=3)",
          output: "Decompose brief into three parallel tracks",
        },
        {
          id: "lead-2",
          start: 2.5,
          end: 4,
          tool: "Write",
          command: "dispatch_agents([flights, venues, weather])",
          output: "Dispatch travel, venue, and weather subagents",
        },
        {
          id: "lead-3",
          start: 8.5,
          end: 12,
          tool: "Write",
          command: "compose_itinerary_summary()",
          output: "Synthesize Lakefront Loft plan and morning ZRH arrivals",
        },
      ],
    },
    {
      id: "flights",
      name: "Flights",
      role: "Travel",
      spans: [
        {
          id: "flights-1",
          start: 2.5,
          end: 5.5,
          tool: "Search",
          command: "search_routes(dest=\"ZRH\", hubs=[\"BER\",\"LHR\",\"AMS\"])",
          output: "Compare 28 nonstop morning departures into Zurich",
        },
        {
          id: "flights-2",
          start: 5.5,
          end: 8.5,
          tool: "Read",
          command: "verify_group_holds(seats=14)",
          output: "Verify refundable group holds landing before 11:15 CET",
        },
      ],
    },
    {
      id: "venues",
      name: "Venues",
      role: "Spaces",
      spans: [
        {
          id: "venues-1",
          start: 3,
          end: 6.5,
          tool: "Search",
          command: "query_spaces(city=\"Zurich\", capacity=14)",
          output: "Query Seefeld and District 1 studios with symmetric fiber",
        },
        {
          id: "venues-2",
          start: 6.5,
          end: 9.5,
          tool: "Read",
          command: "inspect_quotes([\"Lakefront Loft\", \"Kraftwerk\"])",
          output: "Confirm Lakefront Loft availability and breakout rooms",
        },
      ],
    },
    {
      id: "weather",
      name: "Weather",
      role: "Forecast",
      spans: [
        {
          id: "weather-1",
          start: 3.5,
          end: 6,
          tool: "Search",
          command: "fetch_forecast(region=\"Lake Zurich\", days=10)",
          output: "Fetch Lake Zurich hourly rain and temperature outlook",
        },
        {
          id: "weather-2",
          start: 6,
          end: 8,
          tool: "Read",
          command: "evaluate_outdoor_risk()",
          output: "Flag Day 2 afternoon showers and prepare indoor backup",
        },
      ],
    },
  ],
  class: className,
} = Astro.props;

const ticks = [0, 2, 4, 6, 8, 10, 12];
const initialTime = 0.5;
const initialPct = (initialTime / duration) * 100;

const spanFillClass = (tool: ToolKind): string => {
  switch (tool) {
    case "Search":
      return "bg-muted-foreground/15 border-frame";
    case "Read":
      return "bg-muted-foreground/30 border-frame-strong";
    case "Thinking":
      return "bg-muted border-frame";
    case "Write":
      return "bg-foreground/20 border-frame-strong";
  }
};
---

<section
  aria-labelledby={`${id}-title`}
  data-haze-ai-agent-lanes
  data-lanes-json={JSON.stringify(lanes)}
  data-duration={String(duration)}
  class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}
>
  <div class="mx-auto max-w-xl overflow-hidden rounded-2xl border border-border bg-card shadow-key">
    <header class="flex items-start justify-between gap-4 border-b border-border p-5">
      <div class="min-w-0 space-y-1">
        <p class="text-xs/4 text-muted-foreground tabular-nums">
          <span data-header-lane>{lanes[0]?.name ?? "Lead"}</span> agent · <span data-time-readout>{initialTime.toFixed(1)}s</span>
        </p>
        <h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-pretty text-foreground">
          {title}
        </h2>
      </div>

      <button
        type="button"
        data-lane-play
        aria-label="Play timeline"
        class="inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full border border-frame bg-muted/40 text-foreground transition-colors duration-150 ease-snappy hover:border-frame-strong hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring active:scale-95"
      >
        <span data-play-icon><Play class="size-3.5" aria-hidden="true" /></span>
        <span data-pause-icon hidden><Pause class="size-3.5" aria-hidden="true" /></span>
      </button>
    </header>

    <div class="overflow-x-auto p-5">
      <div class="min-w-[26rem]">
        <div class="grid grid-cols-[5.75rem_minmax(0,1fr)] gap-x-4">
          <div role="radiogroup" aria-label="Agent lanes" class="space-y-1.5">
            {
              lanes.map((lane, idx) => (
                <button
                  type="button"
                  role="radio"
                  data-lane-select={lane.id}
                  aria-checked={idx === 0 ? "true" : "false"}
                  class={cn(
                    "flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs font-medium transition-colors duration-150 ease-snappy focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",
                    idx === 0
                      ? "bg-muted text-foreground"
                      : "bg-transparent text-muted-foreground hover:text-foreground",
                  )}
                >
                  <span
                    data-lane-radio-dot
                    aria-hidden="true"
                    class={cn(
                      "size-2 shrink-0 rounded-full",
                      idx === 0 ? "bg-foreground" : "border border-muted-foreground/60 bg-transparent",
                    )}
                  ></span>
                  <span class="truncate">{lane.name}</span>
                </button>
              ))
            }
          </div>

          <div class="relative flex flex-col">
            <div data-track-area class="relative space-y-1.5">
              <div
                data-lane-playhead
                style={`left: ${initialPct}%;`}
                aria-hidden="true"
                class="pointer-events-none absolute top-0 -bottom-2 z-20 w-px bg-foreground/80 transition-[left] duration-150 ease-smooth"
              >
                <span class="absolute -bottom-1 -left-[4.5px] size-2.5 rounded-full bg-foreground shadow-key"></span>
              </div>

              {
                lanes.map((lane) => (
                  <div class="relative flex h-9 items-center border-b border-dashed border-border/70">
                    {lane.spans.map((span) => {
                      const leftPct = (span.start / duration) * 100;
                      const widthPct = ((span.end - span.start) / duration) * 100;
                      return (
                        <button
                          type="button"
                          data-span-btn={span.id}
                          data-span-start={span.start}
                          data-span-end={span.end}
                          data-lane-owner={lane.id}
                          style={`left: ${leftPct}%; width: ${widthPct}%;`}
                          aria-label={`${lane.name} ${span.tool} from ${span.start}s to ${span.end}s`}
                          class={cn(
                            "absolute top-1.5 bottom-1.5 cursor-pointer rounded-xs border transition-opacity duration-150 ease-snappy hover:opacity-100 focus-visible:z-10 focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",
                            spanFillClass(span.tool),
                          )}
                        ></button>
                      );
                    })}
                  </div>
                ))
              }
            </div>

            <div class="relative mt-2.5">
              <label for={`${id}-scrub`} class="sr-only">Run time in seconds</label>
              <input
                id={`${id}-scrub`}
                data-lane-scrub
                type="range"
                min="0"
                max={duration}
                step="0.5"
                value={initialTime}
                class="absolute -top-3.5 left-0 z-30 h-6 w-full cursor-pointer appearance-none bg-transparent opacity-0 [&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-border-strong [&::-webkit-slider-thumb]:-mt-1 [&::-webkit-slider-thumb]:size-3.5 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-0 [&::-webkit-slider-thumb]:bg-foreground [&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-border-strong [&::-moz-range-thumb]:size-3.5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-foreground focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
              />
              <div class="flex items-center justify-between font-mono text-[0.6875rem]/4 text-muted-foreground tabular-nums">
                {ticks.map((tick) => <span>{tick}s</span>)}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="space-y-2 border-t border-border px-5 py-3.5">
      <div class="flex flex-wrap items-center justify-between gap-2">
        <span data-inspector-lane class="text-xs/4 font-medium text-muted-foreground">
          {lanes[0]?.name ?? "Lead"}
        </span>
        <div class="flex flex-wrap items-center gap-3 text-[0.6875rem]/4 text-muted-foreground" aria-label="Tool legend">
          <span class="inline-flex items-center gap-1.5">
            <span class="size-2 rounded-xs bg-muted-foreground/45" aria-hidden="true"></span>
            Search
          </span>
          <span class="inline-flex items-center gap-1.5">
            <span class="size-2 rounded-xs bg-muted-foreground" aria-hidden="true"></span>
            Read
          </span>
          <span class="inline-flex items-center gap-1.5">
            <span class="size-2 rounded-xs bg-border-strong" aria-hidden="true"></span>
            Thinking
          </span>
          <span class="inline-flex items-center gap-1.5">
            <span class="size-2 rounded-xs bg-foreground" aria-hidden="true"></span>
            Write
          </span>
        </div>
      </div>

      <div class="flex flex-wrap items-baseline gap-x-3 gap-y-1 text-xs/5">
        <span class="inline-flex shrink-0 items-center gap-1.5 font-medium text-muted-foreground">
          <span data-inspector-dot class="size-1.5 rounded-full bg-border-strong" aria-hidden="true"></span>
          <span data-inspector-tool>{lanes[0]?.spans[0]?.tool ?? "Thinking"}</span>
        </span>
        <span data-inspector-output class="min-w-0 flex-1 text-pretty text-foreground">
          {lanes[0]?.spans[0]?.output ?? ""}
        </span>
      </div>
    </div>

    <p data-lane-status role="status" class="sr-only"></p>
  </div>
</section>

<script>
  type ToolKind = "Search" | "Read" | "Thinking" | "Write";

  interface AgentSpan {
    id: string;
    start: number;
    end: number;
    tool: ToolKind;
    command: string;
    output: string;
  }

  interface AgentLane {
    id: string;
    name: string;
    role: string;
    spans: AgentSpan[];
  }

  function initAiAgentLanes() {
    document.querySelectorAll<HTMLElement>("[data-haze-ai-agent-lanes]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");

      const raw = root.dataset.lanesJson;
      const duration = Number(root.dataset.duration ?? "12") || 12;
      const scrub = root.querySelector<HTMLInputElement>("[data-lane-scrub]");
      const playBtn = root.querySelector<HTMLButtonElement>("[data-lane-play]");
      const playIcon = root.querySelector<HTMLElement>("[data-play-icon]");
      const pauseIcon = root.querySelector<HTMLElement>("[data-pause-icon]");
      const headerLaneEl = root.querySelector<HTMLElement>("[data-header-lane]");
      const timeReadout = root.querySelector<HTMLElement>("[data-time-readout]");
      const playheadEl = root.querySelector<HTMLElement>("[data-lane-playhead]");
      const inspectorLaneEl = root.querySelector<HTMLElement>("[data-inspector-lane]");
      const inspectorDotEl = root.querySelector<HTMLElement>("[data-inspector-dot]");
      const inspectorToolEl = root.querySelector<HTMLElement>("[data-inspector-tool]");
      const inspectorOutputEl = root.querySelector<HTMLElement>("[data-inspector-output]");
      const statusEl = root.querySelector<HTMLElement>("[data-lane-status]");

      if (!raw || !scrub) return;

      let lanes: AgentLane[] = [];
      try {
        lanes = JSON.parse(raw) as AgentLane[];
      } catch {
        return;
      }
      if (lanes.length === 0) return;

      let currentTime = Number(scrub.value) || 0.5;
      let selectedLaneId = lanes[0].id;
      let playing = false;
      let timerId: number | undefined;
      const reducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;

      const dotClass = (tool: ToolKind | null): string => {
        switch (tool) {
          case "Search":
            return "size-1.5 rounded-full bg-muted-foreground/45";
          case "Read":
            return "size-1.5 rounded-full bg-muted-foreground";
          case "Thinking":
            return "size-1.5 rounded-full bg-border-strong";
          case "Write":
            return "size-1.5 rounded-full bg-foreground";
          default:
            return "size-1.5 rounded-full bg-muted-foreground/50";
        }
      };

      const updatePlayButton = () => {
        if (playIcon) playIcon.hidden = playing;
        if (pauseIcon) pauseIcon.hidden = !playing;
        playBtn?.setAttribute("aria-label", playing ? "Pause timeline" : "Play timeline");
      };

      const renderAtTime = () => {
        const clamped = Math.max(0, Math.min(duration, currentTime));
        currentTime = Math.round(clamped * 2) / 2;
        scrub.value = String(currentTime);

        const pct = (currentTime / duration) * 100;
        if (playheadEl) playheadEl.style.left = `${pct}%`;
        if (timeReadout) timeReadout.textContent = `${currentTime.toFixed(1)}s`;

        const selectedLane = lanes.find((l) => l.id === selectedLaneId) ?? lanes[0];
        if (headerLaneEl) headerLaneEl.textContent = selectedLane.name;
        if (inspectorLaneEl) inspectorLaneEl.textContent = selectedLane.name;

        root.querySelectorAll<HTMLButtonElement>("[data-lane-select]").forEach((btn) => {
          const isSelected = btn.dataset.laneSelect === selectedLane.id;
          btn.setAttribute("aria-checked", String(isSelected));
          btn.className = `flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs font-medium transition-colors duration-150 ease-snappy focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring ${
            isSelected ? "bg-muted text-foreground" : "bg-transparent text-muted-foreground hover:text-foreground"
          }`;
          const dot = btn.querySelector<HTMLElement>("[data-lane-radio-dot]");
          if (dot) {
            dot.className = `size-2 shrink-0 rounded-full ${
              isSelected ? "bg-foreground" : "border border-muted-foreground/60 bg-transparent"
            }`;
          }
        });

        root.querySelectorAll<HTMLButtonElement>("[data-span-btn]").forEach((btn) => {
          const start = Number(btn.dataset.spanStart ?? "0");
          const end = Number(btn.dataset.spanEnd ?? "0");
          const owner = btn.dataset.laneOwner ?? "";
          const isActive = currentTime >= start && (currentTime < end || (end === duration && currentTime === duration));
          const isFuture = currentTime < start;
          const isSelectedLane = owner === selectedLane.id;

          btn.classList.toggle("opacity-25", isFuture);
          btn.classList.toggle("opacity-60", !isFuture && !isActive && !isSelectedLane);
          btn.classList.toggle("opacity-100", isActive || (!isFuture && isSelectedLane));
          btn.classList.toggle("ring-1", isActive && isSelectedLane);
          btn.classList.toggle("ring-ring", isActive && isSelectedLane);
        });

        const activeSpan = selectedLane.spans.find(
          (span) =>
            currentTime >= span.start &&
            (currentTime < span.end || (span.end === duration && currentTime === duration)),
        );

        if (activeSpan) {
          if (inspectorDotEl) inspectorDotEl.className = dotClass(activeSpan.tool);
          if (inspectorToolEl) inspectorToolEl.textContent = activeSpan.tool;
          if (inspectorOutputEl) inspectorOutputEl.textContent = activeSpan.output;
        } else {
          const nextSpan = selectedLane.spans.find((s) => s.start > currentTime);
          if (inspectorDotEl) inspectorDotEl.className = dotClass(null);
          if (inspectorToolEl) inspectorToolEl.textContent = nextSpan ? "Waiting" : "Done";
          if (inspectorOutputEl) {
            inspectorOutputEl.textContent = nextSpan
              ? `Queued to start ${nextSpan.tool.toLowerCase()} at ${nextSpan.start.toFixed(1)}s`
              : "Completed all assigned subtasks";
          }
        }

        updatePlayButton();
      };

      const stopPlayback = () => {
        playing = false;
        if (timerId !== undefined) {
          window.clearInterval(timerId);
          timerId = undefined;
        }
        updatePlayButton();
      };

      const startPlayback = () => {
        if (currentTime >= duration) currentTime = 0;
        playing = true;
        updatePlayButton();
        if (statusEl) statusEl.textContent = "Playing multi-agent timeline.";
        const stepMs = reducedMotion ? 450 : 280;
        timerId = window.setInterval(() => {
          currentTime = Math.min(duration, currentTime + 0.5);
          if (currentTime >= duration) {
            stopPlayback();
            renderAtTime();
            if (statusEl) statusEl.textContent = `Timeline complete at ${duration.toFixed(1)}s.`;
            return;
          }
          renderAtTime();
        }, stepMs);
      };

      playBtn?.addEventListener("click", () => {
        if (playing) {
          stopPlayback();
          if (statusEl) statusEl.textContent = `Paused at ${currentTime.toFixed(1)}s.`;
        } else {
          startPlayback();
        }
      });

      scrub.addEventListener("input", () => {
        if (playing) stopPlayback();
        currentTime = Number(scrub.value) || 0;
        renderAtTime();
      });

      root.querySelectorAll<HTMLButtonElement>("[data-lane-select]").forEach((btn) => {
        btn.addEventListener("click", () => {
          selectedLaneId = btn.dataset.laneSelect ?? lanes[0].id;
          renderAtTime();
          if (statusEl) statusEl.textContent = `Inspecting ${btn.textContent?.trim() ?? selectedLaneId} lane.`;
        });
      });

      root.querySelectorAll<HTMLButtonElement>("[data-span-btn]").forEach((btn) => {
        btn.addEventListener("click", () => {
          if (playing) stopPlayback();
          selectedLaneId = btn.dataset.laneOwner ?? selectedLaneId;
          currentTime = Number(btn.dataset.spanStart ?? "0");
          renderAtTime();
          if (statusEl) statusEl.textContent = `Jumped to ${btn.getAttribute("aria-label") ?? "span"}.`;
        });
      });

      renderAtTime();
    });
  }

  initAiAgentLanes();
  document.addEventListener("astro:page-load", initAiAgentLanes);
</script>
```
