Design 10 min read

UI Patterns for AI Chat Interfaces

David Lee avatar

Contributotor

UI Patterns for AI Chat Interfaces
Featured image for UI Patterns for AI Chat Interfaces

Best practices for designing chat interfaces that feel natural, handle errors gracefully, and guide user intent.

The Challenge of AI Chat Design

Designing chat interfaces for AI is fundamentally different from traditional messaging apps. Users need clear feedback, error handling, and guidance - all while maintaining a natural conversation flow.

Core Design Principles

Recognizing something is always easier than recalling it. Interfaces should minimize the user’s memory load.

Jakob Nielsen| User Advocate

1. Progressive Disclosure

Don’t overwhelm users with options. Show advanced features as they need them:

Code
function ChatInput() {
  const [showAdvanced, setShowAdvanced] = useState(false);

  return (
    <div className="chat-input">
      <textarea placeholder="Ask me anything..." />

      {showAdvanced && (
        <div className="advanced-options">
          <select name="model">
            <option>GPT-4</option>
            <option>Claude</option>
          </select>
          <input type="range" name="temperature" />
        </div>
      )}

      <button onClick={() => setShowAdvanced(!showAdvanced)}>
        ⚙️ Advanced
      </button>
    </div>
  );
}

2. Loading States Matter

AI responses can take time. Make the wait feel intentional:

Code
function MessageBubble({ message, isLoading }) {
  if (isLoading) {
    return (
      <div className="message ai-message loading">
        <div className="typing-indicator">
          <span></span>
          <span></span>
          <span></span>
        </div>
        <p className="subtle-text">Thinking...</p>
      </div>
    );
  }

  return <div className="message">{message.content}</div>;
}

3. Error Recovery

Errors will happen. Make them recoverable:

Code
function ErrorMessage({ error, onRetry }) {
  return (
    <div className="message error-message">
      <p>⚠️ {error.message}</p>
      <div className="error-actions">
        <button onClick={onRetry}>Try Again</button>
        <button onClick={() => navigator.clipboard.writeText(error.details)}>
          Copy Error
        </button>
      </div>
    </div>
  );
}

Advanced Patterns

Streaming Responses

Show AI responses as they’re generated:

Code
function StreamingMessage({ messageId }) {
  const [content, setContent] = useState("");

  useEffect(() => {
    const eventSource = new EventSource(`/api/stream/${messageId}`);

    eventSource.onmessage = (event) => {
      setContent((prev) => prev + event.data);
    };

    return () => eventSource.close();
  }, [messageId]);

  return (
    <div className="message streaming">
      <ReactMarkdown>{content}</ReactMarkdown>
      <span className="cursor-blink">▊</span>
    </div>
  );
}

Suggested Prompts

Guide users with contextual suggestions:

Code
function SuggestedPrompts({ context }) {
  const suggestions = [
    "Explain this in simpler terms",
    "Show me an example",
    "What are the alternatives?",
  ];

  return (
    <div className="suggested-prompts">
      {suggestions.map((prompt) => (
        <button
          key={prompt}
          className="suggestion-chip"
          onClick={() => sendMessage(prompt)}
        >
          {prompt}
        </button>
      ))}
    </div>
  );
}

Accessibility Considerations

  1. Keyboard Navigation: Ensure all actions are keyboard accessible
  2. Screen Readers: Announce new messages with ARIA live regions
  3. Focus Management: Auto-focus input after sending a message

Conclusion

Great AI chat interfaces balance sophistication with simplicity. They guide users when needed, stay out of the way when not, and always provide clear feedback about what’s happening.

Related Articles

More articles coming soon...

Discussion (14)

Sarah J Sarah Jenkins

Great article! The explanation of the attention mechanism was particularly clear. Could you elaborate more on how sparse attention differs in implementation?

David Lee David Lee Author

Thanks Sarah! Sparse attention essentially limits the number of tokens each token attends to, often using a sliding window or fixed patterns. I'll be covering this in Part 2 next week.

Dev Guru Dev Guru

The code snippet for the attention mechanism is super helpful. It really demystifies the math behind it.