---
title: Build and share a chat UI with Databricks Apps
description: Use Databricks Apps to build and deploy a custom chat UI for any Databricks agent, with streaming responses and tool-call rendering.
canonical_url: https://docs.databricks.com/aws/en/agents/custom-agents/chat-app
---

# Build and share a chat UI with Databricks Apps

> [!WARNING]
> **Legacy**
>
> This page describes the chat UI in the [legacy](https://docs.databricks.com/aws/en/release-notes/runtime/databricks-runtime-ver.md) app templates. Projects that you create with the [Agent Bricks CLI](https://docs.databricks.com/aws/en/agents/custom-agents/agent-bricks-cli.md) include a chat UI. See [Legacy agent offerings](https://docs.databricks.com/aws/en/agents/legacy/index.md).

Use Databricks Apps to build and deploy a chat UI for your agent. [Agent app templates](https://github.com/databricks/app-templates/tree/main) include this chat UI with no additional setup. Use this page to customize the template UI or to add a chat UI to an agent deployed without a template.

![Example chat UI for chatting with deployed agents.](https://docs.databricks.com/aws/en/images/generative-ai/chat-app.png)

## Requirements

This chat UI works with any Databricks agent, except [legacy schemas](https://docs.databricks.com/aws/en/agents/custom-agents/model-serving/agent-legacy-schema.md), including:

* [Agents deployed on Apps](https://docs.databricks.com/aws/en/agents/custom-agents/author-agent.md)
* [Agents deployed on Model Serving](https://docs.databricks.com/aws/en/agents/custom-agents/model-serving/author-agent-model-serving.md) with the **Chat** or **Responses** task type

- [Knowledge Assistant](https://docs.databricks.com/aws/en/agents/agent-bricks/knowledge-assistant.md)
- [Supervisor Agent](https://docs.databricks.com/aws/en/agents/agent-bricks/multi-agent-supervisor.md)

* [Foundation model endpoints](https://docs.databricks.com/aws/en/machine-learning/model-serving/foundation-model-overview.md) with **Chat** task type

You must have the following development tools:

* **NPM CLI**: Required for local development. See [GitHub - NPM CLI](https://github.com/npm/cli)
* **Databricks CLI**: Required for authentication, see the [installation guide](https://docs.databricks.com/aws/en/dev-tools/cli/install.md).

  1. Install the Databricks CLI.
  2. Set your profile name:
     ```bash
     export DATABRICKS_CONFIG_PROFILE='your_profile_name'
     ```
  3. Configure authentication:
     ```bash
     databricks auth login --profile "$DATABRICKS_CONFIG_PROFILE"

     ```

## <a id="example-app" />Example chat application

The example app, [e2e-chatbot-app-next](https://github.com/databricks/app-templates/tree/main/e2e-chatbot-app-next) uses [NextJS](http://nextjs.org/), [React](https://react.dev/), and [AI SDK](https://ai-sdk.dev/) to build a production-ready chat interface.

See the project [README.md](https://github.com/databricks/app-templates/blob/main/e2e-chatbot-app-next/README.md) for detailed instructions on how to use the template.

The example app demonstrates the following:

* **Streaming output**: Displays agent responses as they generate with automatic fallback to non-streaming mode
* **Tool calls**: Renders tool calls for agents authored using [Custom Agents best practices](https://docs.databricks.com/aws/en/agents/custom-agents/author-agent.md)

- **Databricks Agent and Foundation Model integration**: Direct connection to Foundation Models, Databricks Agent serving endpoints, [Knowledge Assistant](https://docs.databricks.com/aws/en/agents/agent-bricks/knowledge-assistant.md), and [Supervisor Agent](https://docs.databricks.com/aws/en/agents/agent-bricks/multi-agent-supervisor.md).

* **Databricks authentication**: Uses Databricks authentication to identify end users of the chat app and securely manage their conversations.
* **Persistent chat history**: Stores conversations in Databricks Lakebase (Postgres) with full governance

Open the following sections to enable optional features:

**Enable chat history**

### <a id="chat-history" />Enable chat history

By default, conversations are stored in memory only and are lost when the session ends. To persist history in PostgreSQL, run the quickstart script described in the template [README.md](https://github.com/databricks/app-templates/blob/main/e2e-chatbot-app-next/README.md).

**Enable user feedback**

Users can provide thumbs up/down feedback on responses, which gets logged in an MLflow experiment.

If you are using an agent template such as [agent-openai-agents-sdk](https://github.com/databricks/app-templates/tree/main/agent-openai-agents-sdk) or [agent-langgraph](https://github.com/databricks/app-templates/tree/main/agent-langgraph), the bundle automatically configures authentication for the app to write user feedback to the MLflow experiment. Feedback works after `databricks bundle deploy` with no extra steps.

If you are using the standalone [e2e-chatbot-app-next](https://github.com/databricks/app-templates/tree/main/e2e-chatbot-app-next) pointed at an existing agent endpoint, run the quickstart script described in the template [README.md](https://github.com/databricks/app-templates/blob/main/e2e-chatbot-app-next/README.md) to configure authentication for the MLflow experiment.

> [!NOTE]
>
> Also bind a Lakebase database to persist the thumbs up/down state across page reloads. See [Enable chat history](https://docs.databricks.com/aws/en/agents/custom-agents/chat-app.md#chat-history).

**Host multiple apps on the same database instance**

This example only creates one database per app, because the app code targets a fixed `ai_chatbot` schema in the database instance. To host multiple apps out of the same instance, you must do the following:

1. Update the database instance name in `databricks.yml`.
2. Update references to `ai_chatbot` in the codebase to your new desired schema name within the existing database instance.
3. Run `npm run db:generate` to regenerate database migrations.
4. Deploy the app.

**Enable user authorization**

Some serving endpoints require the app to forward the user's access token instead of the app's service principal token. This is called [*user authorization*](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/auth.md#user-authorization), sometimes referred to as *on-behalf-of-user authorization*.

Supervisor Agent endpoints always require user authorization. Custom model serving endpoints also require user authorization when the endpoint has API scopes configured in its auth policy.

The [e2e-chatbot-app-next](https://github.com/databricks/app-templates/tree/main/e2e-chatbot-app-next) template automatically detects whether the configured serving endpoint requires user authorization. If the app is missing required scopes, it displays a warning banner listing the missing scopes.

To configure user authorization, add the required scopes when you create or edit an app in the Databricks UI:

1. In the **Configure resources** step, under **User authorization**, click **+Add scope**.
2. Add the `model-serving` scope. This scope is required for all endpoints that use user authorization.
3. Add any additional scopes listed in the endpoint's auth policy.

For detailed instructions, see [Add scopes to an app](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/auth.md#add-scopes-to-an-app).

Scope changes take effect immediately, and the app doesn't need to restart. However, your browser session reuses the tokens issued before the change, so you must clear cookies for the app URL before testing:

1. Go to the app URL.
2. In Chrome, open DevTools (**F12**, or **Cmd+Option+I** on macOS, or **Ctrl+Shift+I** on Windows or Linux).
3. Open the **Application** tab, select your app's URL under **Storage** > **Cookies**, then right-click each cookie and choose **Delete**, as shown below.

![Chrome DevTools showing the Application tab, cookies for an app URL, and the right-click Delete menu.](https://docs.databricks.com/aws/en/images/generative-ai/agent-platform/chrome-devtools-clear-cookies.png)

## Share the app

Grant users permission to view the app (see [Configure permissions for a Databricks app](https://docs.databricks.com/aws/en/dev-tools/databricks-apps/permissions.md)), then share the app URL.

## Known limitations

* No support for image or other multi-modal inputs
* This app supports Databricks CLI auth (local development) and service principal auth (deployed apps) only. PAT, Azure managed identities, and other mechanisms are not supported.
* Unity Catalog function scopes are not supported for user authorization.

## Streamlit agent chat app

The previous Streamlit template, [e2e-chatbot-app](https://github.com/databricks/app-templates/tree/main/e2e-chatbot-app), is still available but lacks the production features of [e2e-chatbot-app-next](https://github.com/databricks/app-templates/tree/main/e2e-chatbot-app-next).
