# Agent Plan

> What an agent did and plans to do, step by step, with each step's input and result.

Page: https://uicontext.com/docs/components/agent-plan

Group: Chat.

## When to use

What an agent did and plans to do, step by step, with each step's input and result. Use [Run Summary](https://uicontext.com/docs/components/run-summary.md) instead when the run is over and only the receipts matter.

## Usage

```ts
import { type Step, AgentPlan } from "./ui/uicontext/components/AgentPlan.ts"

const Message = UiSchema.TaggedEnum({ ClickedRetryStep: { step: Schema.String } })

// your app maps each tool call of the run to a step: its status, input and result as text
export const ToolCalls = (h: Html.H<typeof Message.Type>, steps: ReadonlyArray<Step>) =>
	AgentPlan(h, {
		key: "run-218",
		label: "What the agent did",
		steps,
		onRetry: (step) => Message.ClickedRetryStep({ step: step.id }),
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A coding agent's run

The plan beside the tool calls. Open a call for its input and result; a failed call says why at once and can run again.

```ts title="src/demo.ts" source="www/src/examples/agent-plan/demo.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { Checklist, type Step, AgentPlan } from "./ui/uicontext/components/AgentPlan.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { space } from "./ui/uicontext/components/tokens.stylex.ts"

const initial: ReadonlyArray<Step> = [
	{
		id: "s1",
		title: "Read src/auth/links.ts",
		status: "succeeded",
		duration: "0.2s",
		input: '{ "path": "src/auth/links.ts" }',
		result: "export const LINK_TTL = Duration.minutes(10)\n…48 more lines",
	},
	{
		id: "s2",
		title: "Searched for LINK_TTL",
		status: "succeeded",
		duration: "0.4s",
		input: '{ "query": "LINK_TTL", "glob": "src/**/*.ts" }',
		result: "src/auth/links.ts:4\nsrc/auth/links.test.ts:12\nsrc/mail/queue.ts:31",
	},
	{
		id: "s3",
		title: "Ran bun test src/auth",
		status: "failed",
		duration: "6.1s",
		input: "bun test src/auth",
		result: "✗ links > a late email still signs in\n  expected 200, got 410 Gone",
		error: "1 of 38 tests failed: a link sent 20 minutes ago is already expired.",
	},
	{ id: "s4", title: "Open a pull request", status: "queued" },
]

const Message = UiSchema.TaggedEnum({
	ClickedRetry: { step: Schema.String },
	CompletedRetry: { step: Schema.String },
})

// Stands in for running the tool again: two seconds, then it passes.
const RunAgain = Command.make("RunStepAgain", { args: { step: Schema.String } }, ({ step }) =>
	Effect.sleep("2 seconds").pipe(Effect.as(Message.CompletedRetry({ step }))),
)

const styles = stylex.create({
	frame: { display: "grid", gap: space.xl, inlineSize: "min(100%, 38rem)" },
})

export const AgentRun = Html.component({
	name: "AgentRun",
	model: Schema.Struct({ retried: Schema.Literals(["no", "running", "passed"]) }),
	message: Message,
}).make({
	init: () => ({ retried: "no" as const }),
	update: {
		ClickedRetry: ($, { step }) =>
			$.model.retried === "running" ? $.model : $.evolve({ retried: "running" }).run(RunAgain.make({ step })),
		CompletedRetry: ($) => $.evolve({ retried: "passed" }),
	},
	view: (h, model) => {
		const steps = initial.map((step): Step => {
			if (step.id !== "s3" || model.retried === "no") return step
			const { error: _, result: __, ...rest } = step
			return model.retried === "running"
				? { ...rest, status: "running", duration: "" }
				: { ...rest, status: "succeeded", duration: "5.8s", result: "✓ 38 passed" }
		})
		return h.div.attrs(sx(styles.frame)).children(
			Checklist(h, {
				label: "Plan",
				items: [
					{ id: "p1", label: "Find where link lifetime is set", status: "done" },
					{ id: "p2", label: "Raise it to 30 minutes and fix the tests", status: model.retried === "passed" ? "done" : "in-progress" },
					{ id: "p3", label: "Open a pull request", status: "not-started" },
				],
			}),
			AgentPlan(h, {
				key: "steps-demo",
				label: "Tool calls",
				steps,
				onRetry: (step) => Message.ClickedRetry({ step: step.id }),
			}),
		)
	},
})
```

### A step that waits for approval

The run stops at a step that needs a person. The approval sits under that step; once answered, the step runs or is refused.

This example also uses Approval and Domain. Install them too:

```sh
npx shadcn@latest add checkfu/uicontext/approval checkfu/uicontext/domain
```

```ts title="src/approval-gate.ts" source="www/src/examples/agent-plan/approval-gate.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"
import { Approval, ApprovalState } from "./ui/uicontext/components/Approval.ts"
import { type Step, AgentPlan } from "./ui/uicontext/components/AgentPlan.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const scout: Actor = { id: "scout", name: "Scout", kind: "agent" }
const ada: Actor = { id: "ada", name: "Ada Lovelace", kind: "person" }

const Message = UiSchema.TaggedEnum({ ChoseDeploy: { choice: Schema.String } })

const styles = stylex.create({ frame: { inlineSize: "min(100%, 38rem)" } })

export const GatedRun = Html.component({
	name: "GatedRun",
	model: Schema.Struct({ state: ApprovalState }),
	message: Message,
}).make({
	init: () => ({ state: { _tag: "Pending" as const } }),
	update: {
		// the app records the answer; a real one would also resume the run
		ChoseDeploy: ($, { choice }) => $.evolve({ state: { _tag: "Answered", choice, actor: ada, at: "2026-12-01T10:02:00Z" } }),
	},
	view: (h, model) => {
		const answered = model.state._tag === "Answered" ? model.state.choice : null
		const deploy: Step = {
			id: "deploy",
			title: "Deploy billing-api build 218 to production",
			status: answered === null ? "waiting" : answered === "deploy" ? "running" : "refused",
			input: '{ "service": "billing-api", "build": 218, "env": "production" }',
			...(answered === "deny" ? { error: "Ada denied the deploy." } : {}),
		}
		const steps: ReadonlyArray<Step> = [
			{ id: "build", title: "Built billing-api #218", status: "succeeded", duration: "1m 12s", result: "image sha256:9f2c…e41a" },
			{ id: "staging", title: "Deployed to staging and ran smoke tests", status: "succeeded", duration: "48s", result: "14 of 14 checks passed" },
			deploy,
		]
		return h.div.attrs(sx(styles.frame)).children(
			AgentPlan(h, {
				key: "steps-gate",
				label: "Release run",
				steps,
				detail: (step) =>
					step.id === "deploy"
						? Approval(h, {
								props: {
									id: "deploy-218",
									title: "Deploy build 218 to production",
									fields: [
										{ label: "Service", value: "billing-api" },
										{ label: "Changes", value: "Sign-in links last 30 minutes" },
									],
									digest: "deploy:billing-api:218",
									actor: scout,
									tool: "deploys.create",
									choices: [
										{ id: "deny", label: "Deny", dismiss: true },
										{ id: "deploy", label: "Deploy", primary: true },
									],
									can: ["answer"],
									state: model.state,
									timeZone: "UTC",
								},
								onEmit: { RequestedChoose: ({ choice }) => Message.ChoseDeploy({ choice }) },
							})
						: undefined,
			}),
		)
	},
})
```

### An assistant's live plan

The job in one sentence, then the plan in plain verbs: done steps step back, the current one is bold with an open ring, and one shimmering line says what it's on.

This example also uses Streaming Text. Install it too:

```sh
npx shadcn@latest add checkfu/uicontext/streaming-text
```

```ts title="src/plan.ts" source="www/src/examples/agent-plan/plan.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Checklist } from "./ui/uicontext/components/AgentPlan.ts"
import { Thinking } from "./ui/uicontext/components/Stream.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	column: { display: "flex", flexDirection: "column", gap: space.md, width: "min(100%, 34rem)" },
	text: { margin: 0, fontSize: 15, lineHeight: 1.55, color: color.fg },
	card: { paddingBlock: space.sm, paddingInline: space.lg, borderRadius: corner.card, borderWidth: 1, borderStyle: "solid", borderColor: color.line },
})

export const LivePlan = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.column)).children(
		h.p.attrs(sx(styles.text)).children("I'll check the invoice, then what Alder says they sent, then whether the money ever arrived."),
		h.div.attrs(sx(styles.card)).children(Checklist(h, {
			look: "plan",
			items: [
				{ id: "open", label: "Open invoice 4410", status: "done" },
				{ id: "read", label: "Read what Alder sent", status: "done" },
				{ id: "look", label: "Look for the money", status: "in-progress" },
				{ id: "match", label: "Match it to the invoice", status: "not-started" },
			],
		})),
		Thinking(h, "Looking for the money…"),
	)
```

## API reference

### AgentPlan (view function)

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `steps` (required) | `Step[]` | — | What the agent did, in order: each tool call, command or app action |
| `label` | `string` | `"Steps"` | The list's accessible name; "Steps" by default |
| `onRetry` | `(step: Step) => Message` | — | A failed step's Retry: the message to send, or undefined where it can't be retried |
| `detail` | `(step: Step) => View.Input<Message, R>` | — | What shows under a step without opening it, such as the Approval a waiting step needs before it runs. Return undefined for none. |
| `key` | `string` | — | Gives the copy buttons of input and result keys of their own when several lists share a parent |

### Checklist (view function)

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` (required) | `ChecklistItem[]` | — | The plan's items, in order, each not started, in progress or done |
| `label` | `string` | `"Plan"` | The list's accessible name; "Plan" by default |
| `look` | `"list" \| "plan"` | — | "plan" reads as an assistant's live plan in a card: done items get a green check and step back, the current one an open ring and bold text, the rest a gray ring. |

## Keyboard and accessibility

- The plan is an ordered list, and each step is a native disclosure: Enter or Space on its title shows its input and result.
- Each step's status is said in words beside its title, never by color alone.
- A checklist is a live list, so screen readers hear the plan change as the agent works through it.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/agent-plan
```

With npm: `npx shadcn@latest add checkfu/uicontext/agent-plan`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/agent-plan`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/agent-plan`.

It writes these files:

- `src/ui/uicontext/components/AgentPlan.ts`
- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/CopyButton.ts`
- `src/ui/uicontext/components/Glyph.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Glyph.ts`
- `src/ui/uicontext/components/domain/Run.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/AgentPlan.ts](https://github.com/checkfu/uicontext/blob/main/src/AgentPlan.ts)

## Used in

- [Automation runs](https://uicontext.com/blocks/automation-runs.md)

## Related

- [Conversation](https://uicontext.com/docs/components/conversation.md) (`conversation`): What a person and an assistant say to each other, with actions, sources and tool calls on each message.
- [Composer](https://uicontext.com/docs/components/composer.md) (`composer`): Write and send a message, with attachments and modes.
- [Conversation Viewport](https://uicontext.com/docs/components/conversation-viewport.md) (`conversation-viewport`): Keeps the newest message in view, and lets you scroll back without losing your place.
- [Streaming Text](https://uicontext.com/docs/components/streaming-text.md) (`streaming-text`): A reply that appears as it's written, with a stop button.
- [Tool Call](https://uicontext.com/docs/components/tool-call.md) (`tool-call`): What an assistant's tools did, one past-tense row each, such as "Searched the web · 8 sources". Each opens to what it read.
- [Approval](https://uicontext.com/docs/components/approval.md) (`approval`): Asks a person to allow an action before an agent takes it.
