Showing agent activity

How the five agent components fit together on a page where an AI agent works while the reader watches: agent status for right now, agent plan for the plan, agent timeline for what happened, with tool calls and reasoning inside it.

Agent activity

None of them runs anything. Your server runs the agent and stores its steps; the page renders them, and a re-render brings the next step in. The recipe below does that with Livewire, but any re-render works: a poll, a Turbo stream, a full page.

The recipe

One Livewire component re-renders the run. The agent itself runs in a queued job that writes each step to the database as it happens.

use Livewire\Attributes\Computed;
use Livewire\Component;

class RunActivity extends Component
{
    public Run $run;

    #[Computed]
    public function steps()
    {
        return $this->run->steps()->oldest()->get();
    }

    public function stop(): void
    {
        $this->run->update(['status' => 'cancelled']);
    }

    public function approve(string $call): void
    {
        $this->run->steps()->findOrFail($call)->approve();
    }

    public function render()
    {
        return view('livewire.run-activity');
    }
}
{{-- livewire/run-activity.blade.php --}}
<div @if ($run->isLive()) wire:poll.1s @endif class="flex flex-col gap-4">
    <x-ds::agent-status :status="$run->status" :label="$run->activity" :elapsed="$run->elapsed">
        <x-slot:cancel><x-ds::button size="sm" variant="ghost" icon="stop" wire:click="stop">Stop</x-ds::button></x-slot:cancel>
    </x-ds::agent-status>

    <x-ds::agent-plan title="Plan" :steps="$run->plan" variant="compact" />

    <x-ds::agent-timeline label="Run {{ $run->id }}" :fold="6">
        @foreach ($this->steps as $step)
            <x-ds::agent-timeline-item wire:key="step-{{ $step->id }}"
                :type="$step->type" :status="$step->status" :title="$step->title" :duration="$step->seconds">
                @if ($step->type === 'tool')
                    <x-ds::tool-call id="call-{{ $step->id }}" :name="$step->tool" :status="$step->status"
                        :arguments="$step->input" :result="$step->output" :error="$step->error">
                        @if ($step->status === 'waiting')
                            <x-slot:actions>
                                <x-ds::button size="sm" wire:click="approve('{{ $step->id }}')">Approve</x-ds::button>
                            </x-slot:actions>
                        @endif
                    </x-ds::tool-call>
                @elseif ($step->type === 'reasoning')
                    <x-ds::reasoning :status="$step->status" :duration="$step->seconds" :maxHeight="8">{{ $step->text }}</x-ds::reasoning>
                @else
                    {{ $step->text }}
                @endif
            </x-ds::agent-timeline-item>
        @endforeach
    </x-ds::agent-timeline>
</div>

That is all of it. Each poll re-renders the run; Livewire's morph patches the page, and:

  • a new step grows in at the end of the timeline, and the fold counts the ones it now hides;
  • a finished step's marker changes, and the spinner becomes its kind's icon;
  • the status says its new label once to a screen reader, and only when the label changes;
  • whatever the reader opened stays open, and whatever they closed stays closed: a tool call they are reading does not snap shut when the server renders it closed. That needs the package's script, which a Livewire page already has Alpine for.

wire:key on every row is what lets the morph tell the steps apart. Key by the step's id, never by its position.

Streaming the text as it arrives

Polling brings in whole steps. For the words of one step as the model writes them, stream them into it with wire:stream, from a component action that runs the model itself:

<x-ds::reasoning :status="$thinking ? 'running' : 'done'" :duration="$seconds" :maxHeight="8">
    <div wire:stream="reasoning">{{ $reasoning }}</div>
</x-ds::reasoning>
foreach ($client->stream($prompt) as $chunk) {
    $this->reasoning .= $chunk->text;
    $this->stream(to: 'reasoning', content: $chunk->text);
}
$this->thinking = false;

The capped box follows the text with no script; the streamed words are not read aloud as they arrive, and "Thought for 12 seconds" is, once, at the end.

What goes where

The reader wants to knowUse
Is it still going, and what is it doing?Agent status
What will it do, and how far is it?Agent plan
What did it do, and in what order?Agent timeline
What did it call, with what, and what came back?Tool call
Why did it answer that way?Reasoning

A chat with one agent may need only reasoning and tool calls above each answer. A long background job may need only the status and the plan. Use the timeline when the order matters: debugging, audit, several agents handing work to each other.

Statuses

All five take the same six statuses (pending, running, done, failed, cancelled, waiting), with the same marks and words. See the status set. Store whatever your agent framework calls them; in_progress, completed, error and the like are read as their match.


From the package repo: edit this page on GitHub.

Was this page helpful?