# Agent composer

> The taller composer for agent surfaces: branch, folder and context on a tab above, permissions and model as pills that grow into their lists.

A coding or ops agent needs more around the prompt than a chat box: where it’s working, how much it may do on its own, which model, and how full its memory is. Here a tab hangs off the card’s top edge with the branch, the project folder and a context ring that fills and turns amber past 80%, each morphing when it changes. Under the prompt, the permission pill says how far the agent may go (Auto, Ask first, Plan only, Full access) and grows into a list with a line on each, opening clear of the composer; the model pill on the right does the same, with thinking effort for models that reason. Send blurs into a spinner, then into Stop, and the mic beside it breathes while it listens. Files come in through +, paste or drop.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/agent-composer.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `model-picker`, `text-morph`, `number-roll`
- Docs and live preview: https://hairlineui.com/ui/agent-composer
- Registry item (source): https://hairlineui.com/r/agent-composer.json

## Usage

```tsx
import { AgentComposer } from "@/components/agent-composer";

<AgentComposer
  branch="main"
  folder="kept-till"
  context={{ used: 570000, limit: 1000000 }}
  models={models}
  model={model}
  onModelChange={setModel}
  status={status}
  onSubmit={(text) => sendMessage({ text })}
  onStop={stop}
/>
```

## With the AI SDK

```tsx
"use client";
import { useState } from "react";
import { useChat } from "@ai-sdk/react";
import { AgentComposer } from "@/components/agent-composer";

export function AgentInput({ branch, folder }: { branch: string; folder: string }) {
  const { sendMessage, status, stop, messages } = useChat();
  const [model, setModel] = useState("aurora");
  const [permission, setPermission] = useState("auto");
  const used = messages.reduce((sum, m) => sum + (m.metadata?.tokens ?? 0), 0);

  return (
    <AgentComposer
      branch={branch}
      folder={folder}
      context={{ used, limit: 1_000_000 }}
      models={MODELS}
      model={model}
      onModelChange={setModel}
      permission={permission}
      onPermissionChange={setPermission}
      status={status}
      onSubmit={(text) => sendMessage({ text }, { body: { model, permission } })}
      onStop={stop}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onSubmit` | `(value: string) => void` | – | Called with the text on Enter or Send. |
| `status` | `"ready" \| "submitted" \| "streaming" \| "error"` | `"ready"` | useChat’s status, passed straight through. |
| `onStop` | `() => void` | – | Turns the spinner into Stop while streaming. |
| `branch / folder` | `string` | – | On the tab above the card; they morph when they change. |
| `context` | `{ used: number; limit: number }` | – | The ring on the tab; amber from 80%, red from 95%. |
| `models / model / onModelChange` | `ModelOption[] / string / (id) => void` | – | The model pill (see Model picker); effort and onEffortChange add thinking effort. |
| `permissions` | `ModelOption[]` | `Auto, Ask first, Plan only, Full access` | The permission modes, each with a name, a line and an icon. |
| `permission / defaultPermission / onPermissionChange` | `string / string / (id) => void` | `"auto"` | Controlled or not. |
| `onFilesSelected / accept / attachments` | `(files) => void / string / ReactNode` | – | Enables +, paste and drop; render chips in attachments and they fold open above the prompt. |
| `onVoice / listening` | `() => void / boolean` | – | Shows the mic and whether it’s listening. |
| `placeholder` | `string` | `"What should we build?"` | Also the field’s label. |

## States

- **ready**: Type; Enter sends, Shift+Enter adds a line; the field grows to 220px, then scrolls. Send is dim until there’s text.
- **submitted / streaming**: The arrow blurs into a spinner (submitted), then into Stop while streaming if onStop is set (260ms blur, scale 0.6→1).
- **status tab**: Branch and folder morph letter by letter when they change; the context ring eases to its new share (600ms) and its figure rolls, turning amber at 80% and red at 95%.
- **permission / model**: Each pill grows into its list (Model picker’s one-surface morph), opening above the composer and lined up with its left or right edge; choosing morphs the pill’s label.
- **listening**: With onVoice, the mic turns primary and a soft disc breathes behind it until it’s pressed again.

## What it handles

A chat box has one job. An agent’s prompt box has several more: where it is working, how much it may do on its own, which model it runs on and how much of its memory is used.

- **Where the agent is working**: The branch and project folder sit on a tab above the prompt and morph when they change.
- **How full the context is**: A ring fills with the share used, turning amber at 80% and red at 95%, always with the figure beside it.
- **How far it may go**: A permission pill opens into a list such as Auto, Ask first, Plan only and Full access. Pass your own list.
- **Model and thinking effort**: The model pill grows into its list, with an effort setting for models that reason.
- **Send, then Stop**: It follows the AI SDK’s status: the arrow becomes a spinner, then Stop while the answer streams.
- **Files and voice**: Add files with the plus button, paste or drop, and show a microphone that breathes while it listens.

## Replaces

a growing textarea, a permissions dropdown, a model dropdown, a context meter, send and stop state, file paste and drop

## Where it fits

- **Coding agents**: A prompt box that shows the branch, the folder and how full the context is.
- **Ops and DevOps agents**: Let people choose whether the agent asks first, plans only or acts on its own.
- **Internal AI tools**: Staff pick the model, and the thinking effort for models that reason, before they send.
- **Research and writing agents**: A prompt box where files come in through the plus button, paste or drop.

## Notes

- The field is labelled by its placeholder; Send, Stop, Speak and Add files are labelled buttons, and the mic says whether it’s pressed.
- Both pickers are listboxes with arrow keys, Home, End and Escape (see Model picker), announced as "Permission: Auto" and "Model: Aurora".
- The tab’s branch and folder have visually hidden labels, and the context ring reads as "57% of the context used"; amber and red always come with the figure.
- The breathing disc only runs while listening and stops with reduced motion.
- Installs Model picker, Number roll and Text morph.

License: MIT (https://hairlineui.com/license#components)
