# Agent chat

- **[Atoms](/components/)**

The chat every Klarhimmel app uses: an empty start with suggestions, the person's message as a bubble on the right, the reply as plain rich text with quiet actions, a small loader, the newest message scrolled to the top, and ChatComposer.

## Preview

agent-chat.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { ChatThread, ChatMessage, MessageActions } from '@/components/klarhimmel/ui/agent-chat';
import { ChatComposer } from '@/components/klarhimmel/ui/chat-composer';

export default function Example() {
  return (
    <Theme theme="brand">
      <ChatThread anchor="m2" composer={<ChatComposer label="Message" value="" onChange={() => {}} onSend={() => {}} />}>
        <ChatMessage from="user">What can you change for me?</ChatMessage>
        <ChatMessage from="assistant" actions={<MessageActions copyText="Your opening hours and menu." onRetry={() => {}} />}>
          <p>Your <strong>opening hours</strong> and menu.</p>
        </ChatMessage>
      </ChatThread>
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add https://ui.klarhimmel.com/r/agent-chat.json https://ui.klarhimmel.com/r/chat-composer.json
  ```
- **Import**

  ```
  import { ChatStart, ChatThread, ChatMessage, MessageActions, ChatLoader, ChatComposer } from '@/components/klarhimmel/ui/agent-chat';
  ```

- **Files**: agent-chat.tsx, agent-chat.css, chat-composer.tsx, in components/klarhimmel/ui/. With it: menu, theme, utils. npm: lucide-react.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Examples

- **Chat start basic**

  ```
  import { useState } from 'react';
  import { CalendarClock, ChevronDown, ImageIcon, PenLine } from 'lucide-react';
  import { ChatComposer, ComposerTool } from '@/components/klarhimmel/ui/chat-composer';
  import { ChatStart } from '@/components/klarhimmel/ui/agent-chat';
  
  // An empty chat: the greeting, the pill, suggestion rows that fill it, the plain canvas (Felix 2026-10-22 18:48 Gemini empty state; 18:55 no gradient).
  export default function ChatStartBasic() {
    const [text, setText] = useState('');
    return (
      <div className="w-[min(52rem,calc(100cqw-3rem))] overflow-hidden rounded-kh-lg border border-kh-line bg-kh-surface">
        <ChatStart greeting="Where should we start?" className="min-h-[28rem]"
          suggestions={[
            { label: 'Change my opening hours', icon: <CalendarClock />, onSelect: () => setText('Change my opening hours to ') },
            { label: 'Add photos of the new menu', icon: <ImageIcon />, onSelect: () => setText('Add photos of the new menu') },
            { label: 'Write a post about our autumn offer', icon: <PenLine />, onSelect: () => setText('Write a post about our autumn offer') },
          ]}>
          <ChatComposer label="Message to the assistant" placeholder="Ask the assistant" value={text} onChange={setText} onSend={() => setText('')}
            attach={{ onFiles: () => {} }} tools={<ComposerTool end={<ChevronDown />}>Fast</ComposerTool>} />
        </ChatStart>
      </div>
    );
  }
  ```

## Props

- **ChatStart.greeting**
- **ChatStart.children**: The ChatComposer.
- **ChatStart.suggestions**: Up to four: each fills or sends a first message.
- **ChatStart.className**: Extra classes, merged after the component's own.
- **ChatThread.children**
- **ChatThread.composer**: The ChatComposer, at the bottom of the view.
- **ChatThread.anchor**: Changes on each send: the id of the newest user message.
- **ChatThread.scroll**: page: scrolls with the page (default). inner: its own scroll area (give it a height), scrollbar hidden.
- **ChatThread.jumpLabel**
- **ChatThread.className**: Extra classes, merged after the component's own.
- **ChatMessage.from**
- **ChatMessage.children**
- **ChatMessage.actions**: user: a bubble on the right. assistant: plain rich text (headings, bold, lists, code), its MessageActions under it.
- **ChatMessage.className**: Extra classes, merged after the component's own.
- **MessageActions.rating**: The person's rating, so the pressed thumb stays pressed.
- **MessageActions.onRate**
- **MessageActions.onRetry**
- **MessageActions.copyText**: The reply as text: Copy copies it and says Copied.
- **MessageActions.more**
- **MessageActions.labels**
- **ChatLoader.label**
- **ChatLoader.className**: Extra classes, merged after the component's own.
- **ChatLoader.live**: The Klarhimmel mark rising over its horizon where the reply will start; the label is for screen readers only. live: false inside a role=log, so it is not a second live region.
- **ChatComposer.label**: Required: names the text box (not shown).
- **ChatComposer.value**
- **ChatComposer.onChange**
- **ChatComposer.onSend**: Enter or the send button, with text that may be sent. The app clears `value`.
- **ChatComposer.placeholder**
- **ChatComposer.busy**: An answer is streaming: send becomes stop (or a quiet Working without onStop). Typing goes on.
- **ChatComposer.onStop**

[Previous](/components/number-field)

[Next](/components/chat-composer)
