Source Code

<div class="as-wrap">
  <div class="as-card">
    <div class="as-head">
      <span class="as-title" id="asTitle">Running agent task…</span>
      <span class="as-time" id="asTime">0.0s</span>
    </div>
    <div class="as-bar" id="asBar"></div>
    <div class="as-labels" id="asLabels"></div>
  </div>
</div>

Agent Task Segment Tracker — Multi-Step AI Progress Bar in JS

Agent Task Segment Tracker · Loaders · Plain HTML, CSS & JS · Live preview

What's included

Features

Segmented bar with one independently-filling segment per pipeline stage
Strictly sequential stage execution — no stage starts before the previous finishes
Real incremental per-segment fill loop, not a single blanket CSS transition
Randomized per-stage duration for a natural, non-mechanical pace
Pulsing active-stage indicator distinct from idle and complete states
Checkmark and color change on stage completion, built with pure CSS
Real elapsed-time header clock via Date.now() deltas
Data-driven STAGES array — add, remove, or rename stages freely
Zero dependencies — vanilla DOM and CSS only
Compact horizontal form factor suited to headers and toolbars

About this UI Snippet

Agent Task Segment Tracker — A Segmented Progress Bar for Multi-Stage AI Agent Work

Screenshot of the Agent Task Segment Tracker snippet rendered live

Autonomous AI agents don't do one thing at a time — they search, read, reason, and write in sequence, and users benefit from seeing which stage is active rather than a single ambiguous spinner. This snippet renders that as a segmented progress bar: one segment per named stage (Searching, Reading, Reasoning, Writing), each filling independently as its stage runs, with labels underneath that transition from idle to active to complete.

Strictly sequential stages

runStage(index) only calls itself for the next index after the current segment's own fill animation reaches 100% — there is no overlap and no stage can visually start before the previous one has genuinely finished. This mirrors how a real agent pipeline actually behaves: reasoning cannot begin before reading has produced something to reason about.

A real incremental fill per segment, not a single transition

Rather than letting one CSS transition: width 1s do all the work, each segment fills via a setInterval that recomputes (Date.now() - stageStart) / duration roughly every 40ms and sets fillEl.style.width directly. That means the segment's own internal progress is visible as it happens — useful if you later swap the fixed duration for a real progress event stream from your agent backend, where the fill only needs to track elapsed / estimatedTotal at each report.

Randomized per-stage duration

Each stage's minMs/maxMs range means the demo's timing varies between page loads, avoiding the mechanical, identical-every-time feel of a fixed CSS keyframe animation — closer to how search, reading, and writing genuinely take different, variable amounts of time depending on the task.

Pulsing active-stage indicator

The label underneath the currently active segment gets a small pulsing dot (a CSS scale/opacity keyframe) so it's immediately obvious which stage of the pipeline is running even at a glance, separate from reading the segment bar itself. Completed stages swap that dot for a checkmark built from a rotated border pseudo-element, and their segment turns green.

A real running clock

The header's elapsed-time label is driven by Date.now() - startedAt on a fast interval, exactly like the elapsed timers in the AI reasoning collapse loader — it stops and freezes only once every stage has genuinely completed, so the number in the corner is always trustworthy.

Customizing it

Change the STAGES array's labels and timing ranges to match your own agent's real pipeline (Planning, Calling tool, Verifying, etc.), or replace the simulated duration with a real progress percentage reported by your backend for each stage. Pair it with an AI agent steps timeline for a more detailed vertical trace alongside this compact horizontal summary.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Rather than guessing at the sequencing logic, paste this snippet's HTML, CSS, and JS into an AI coding assistant like Claude and ask it to explain exactly how runStage()'s recursive structure guarantees strict left-to-right stage ordering, and why each segment uses its own setInterval-driven fill loop instead of one CSS transition per segment. The same assistant can help optimize it — for instance asking whether requestAnimationFrame would produce smoother fill motion than the current 40ms setInterval, especially on lower-end devices. It's also useful for extending it: ask it to replace the simulated per-stage duration with real progress events from a WebSocket, add a subtle error/retry state to an individual segment, or make the number of visible stages responsive to how many an actual agent run reports. Treat the code less like a finished artifact and more like a starting point for a conversation.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a segmented, multi-stage progress bar for an AI agent task in plain HTML, CSS, and JavaScript — no libraries.

Requirements:
- A horizontal bar made of several equal-width segments (built from a small array of named stages, e.g. Searching, Reading, Reasoning, Writing), each segment able to fill from 0% to 100% independently, with labels underneath each segment.
- Stages must run strictly in sequence: a segment can only begin filling once the previous segment has reached 100% and been marked complete — never in parallel and never out of order.
- Each segment's fill must be driven by a real repeating interval that computes elapsed time against that stage's expected duration and updates the segment's width accordingly (so genuine intermediate progress within a stage is visible), not a single CSS width transition jumping straight to 100%.
- Randomize each stage's duration within a min/max range so the pacing feels natural and varies between runs, instead of being identical and mechanical every time.
- The label under the currently active stage must show a distinct pulsing indicator (its own small CSS animation) that no other stage shows, and completed stages must show a checkmark and a different color from both pending and active stages.
- A header above the bar must show the current stage name while running, switch to a completed message once every stage is done, and display a live elapsed-time clock computed from a real timestamp difference, updated on a fast interval and frozen only once the whole sequence genuinely finishes.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSThe first segment ("Searching") begins filling immediately and the header timer starts ticking.
  2. 2
    Watch each stage in turnA segment fills to 100%, turns green, and only then does the next stage\u2019s label become active.
  3. 3
    Watch the pulsing dotThe currently active stage\u2019s label shows a pulsing indicator distinct from completed and pending stages.
  4. 4
    Reach completionThe header switches to "Task complete" and the timer freezes at the true total elapsed time.
  5. 5
    Edit the STAGES arrayRename stages and adjust their minMs/maxMs duration ranges to match your real pipeline.
  6. 6
    Wire up real progressReplace the simulated duration-based fill with a live percentage reported by your agent backend for each stage.

Real-world uses

Common Use Cases

Autonomous AI agent task runners
The primary use case — show which stage (search, read, reason, write) an agent is currently in.
Multi-step API pipelines
Any backend job with distinct named phases benefits from a segmented view over one vague spinner.
Document generation and analysis tools
Narrate "Extracting… Summarizing… Formatting…" while a report builds.
Teaching sequential async orchestration
A clear example of chaining stages so each only begins after the last resolves.
Copilot and assistant sidebars
Pair with an ai agent steps timeline for a compact header summary above a detailed trace.
Related: Multi-Stage Loading Checklist
See the Multi-Stage Loading Checklist for a vertical alternative to this horizontal segment tracker.
Related: AI Token Flicker Typing Loader
See the AI Token Flicker Typing Loader for a related loaders pattern worth pairing with this one.
Related: Heartbeat Pulse Monitor Loader
See the Heartbeat Pulse Monitor Loader for a related loaders pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

No. runStage(index) is only called for the next stage inside the current stage\u2019s own completion branch, once its fill interval reports 100%. There is no overlapping timer, so segments always complete strictly left to right.

A single transition to 100% has no notion of intermediate real progress — you would only ever see 0% or fully filled. The interval recomputes elapsed time against the stage\u2019s duration roughly every 40ms, so the fill genuinely tracks how far into the stage you are, which matters once duration is replaced by a real backend-reported percentage instead of a fixed simulated range.

Replace each stage\u2019s randomized duration with the actual expected or reported duration from your backend, or better, report a live percentage per stage over SSE/WebSocket and set fillEl.style.width directly from that value each time a message arrives, skipping the internal setInterval loop entirely.

The .as-active class is added to a stage\u2019s label only while its segment is filling, and removed the instant it completes. The pulse keyframe is scoped to .as-label.as-active .as-dot, so exactly one stage shows the pulsing indicator at any time, making the current stage unambiguous.

Edit the STAGES array — each entry is just a { label, minMs, maxMs } object. The script builds one bar segment and one label per array entry automatically, so adding a fifth stage like "Verifying" requires no other code changes.

Yes. Keep an activeIndex and a per-stage progress percentage in state, advancing activeIndex only once the current stage\u2019s percentage state reaches 100 inside an effect-driven interval or real progress event handler. Render one segment/label pair per array entry from state; the CSS classes and transitions carry over directly.