Databricks App Templates

repository·main·Indexed 41 days ago

https://github.com/databricks/app-templates

A collection of production-ready templates for creating Databricks Apps, including full-stack AI agents and data dashboards. Features include a LangChain TypeScript agent with MLflow tracing (v1.0.0), support for Model Context Protocol (MCP) tools like Databricks SQL and Unity Catalog, and advanced LangGraph implementations with short-term and long-term memory via Lakebase and background mode for long-running tasks.

Tokens
105.5K
Snippets
345
Records
473
Agent score
53%

What's inside Databricks App Templates

  1. Overview of the Agentic Support Console

    main

    The Agentic Support Console is an end-to-end AI-powered support application built on the Databricks platform. It demonstrates a complete data lifecycle including:

    • OLTP: Lakebase (Postgres) for operational data.
    • CDC: Lakehouse Sync to move data from Lakebase to the Lakehouse.
    • Medallion Architecture: Lakeflow Declarative Pipelines moving data from Bronze (history) to Silver (current state) to Gold (analytics/context).
    • AI Agent: A Lakeflow Job that calls an LLM via AI Gateway, writing responses back to Delta tables.
    • Reverse Sync: Syncing Gold Delta tables back to Lakebase via Sync Tables.
    • Frontend: A Databricks App using AppKit (Express + React 19) with Genie analytics integration.
  2. Overview of the Advanced Responses API Agent template

    main

    The Advanced Responses API Agent is a stateful conversational agent template designed for Databricks Apps. It implements the OpenAI Responses API interface, making it compatible with the OpenAI Python SDK.

    Key capabilities include:

    • Stateful Sessions: Uses Databricks Lakebase to provide short-term memory (conversation history) via AsyncDatabricksSession.
    • Long-Running Background Execution: Decouples agent execution from HTTP connection limits (which are ~120s on Databricks Apps) using a background=true flag. This allows for tasks lasting up to 1 hour by default.
    • Resumable Streaming: Supports cursor-based resumption using starting_after=N to allow clients to reconnect and skip already-received events.
    • API Access: While it includes a built-in chat UI, it exposes an API endpoint for integration into external websites or mobile apps.
  3. Overview of Databricks Agent Chat Template

    main

    The Databricks Agent Chat Template is a full-stack chat application designed to interact with Databricks Agent serving endpoints and Agent Bricks. It is built using ExpressJS, React, and the Vercel AI SDK.

    Key capabilities include:

    • Databricks Integration: Direct connection to agent serving endpoints.
    • Authentication: Uses Databricks authentication to identify users and secure conversations.
    • Persistent History (Optional): Uses Databricks Lakebase (Postgres) to store and retrieve chat history.
    • User Feedback (Optional): Collects thumbs up/down feedback, which is stored as MLflow assessments on underlying traces.
  4. Overview of appkit-all-in-one

    main

    The appkit-all-in-one template is a Databricks App powered by AppKit. It provides a full-stack foundation using React, TypeScript, and Tailwind CSS.

    It comes with several enabled plugins:

    • Analytics: Executes SQL queries against Databricks SQL Warehouses.
    • Lakebase: Provides a fully managed Postgres database for transactional (OLTP) workloads on Databricks.
    • Genie: Integrates the AI/BI Genie conversational interface for natural language data queries.
    • Server: An Express HTTP server that handles static file serving and Vite dev mode.
  5. Overview of Inventory Intelligence

    main

    Inventory Intelligence is an end-to-end retail inventory management application built on Databricks. It utilizes a multi-layered architecture to manage data from an OLTP source to a consumer-facing app:

    1. OLTP (Lakebase Postgres): The source of truth for retail data.
    2. Lakehouse Sync (CDC): Replicates data from Lakebase to the Bronze layer in Unity Catalog.
    3. Lakeflow Declarative Pipelines: Processes Bronze data into Silver (SCD Type 1) and Gold (aggregated/business-ready) layers.
    4. Lakeflow Jobs: A pluggable demand forecast model that populates replenishment recommendations.
    5. Sync Tables (Reverse ETL): Syncs Gold layer Delta tables back to Lakebase for application use.
    6. Databricks App: A user interface (built with AppKit) providing Dashboards, Stores, Replenishment, and Genie analytics.
  6. Deploy an MCP server for any REST API with Databricks Apps

    main

    This template allows you to deploy a Model Context Protocol (MCP) server on Databricks Apps that acts as a bridge between LLM agents and external REST APIs. It uses an OpenAPI specification to automatically expose API endpoints as tools for agents.

    Core Functionality:

    1. Loads OpenAPI specifications from a JSON file stored in a Unity Catalog (UC) Volume.
    2. Provides three main tools to LLM agents:
      • list_api_endpoints: Discovers available endpoints.
      • get_api_endpoint_schema: Retrieves detailed schema for specific endpoints.
      • invoke_api_endpoint: Executes API calls using secure authentication via Unity Catalog connections.
    3. Secure Authentication: Uses Unity Catalog connections to handle credentials (Bearer, OAuth, etc.) for the external service.
    4. Hosting: Runs on Databricks Apps for scalability.
  7. How Databricks Asset Bundles (DAB) and CLI interact

    main

    The deployment process uses a mix of Databricks Asset Bundles (DAB) and direct CLI commands depending on the resource type:

    TaskTool
    App resource + configdatabricks bundle deploy
    Source code deploymentdatabricks apps deploy
    Analytics pipelinedatabricks bundle deploy (in pipelines/)
    Forecast jobdatabricks bundle deploy + run (in pipelines/)
    Lakebase project creationCLI only
    Database seedingCLI + seed/seed.ts
    Lakehouse SyncUI only
    Sync TablesUI only
    Genie Space creationUI only
  8. Configure Short-term and Long-term Memory

    main

    The agent supports two types of memory to maintain context and user preferences:

    Short-term Memory (Conversation History)

    Uses AsyncCheckpointSaver to preserve history within a single session. To maintain context across multiple requests in the same conversation, pass a thread_id in the custom_inputs field.

    Long-term Memory (User Facts)

    Uses AsyncDatabricksStore to persist information across different sessions. The agent provides three tools: get_user_memory, save_user_memory, and delete_user_memory. To scope these memories to a specific user, pass a user_id in custom_inputs. If user_id is omitted, memory tools are disabled.

    {
      "input": [{ "role": "user", "content": "Remember I prefer Python" }],
      "custom_inputs": { "thread_id": "<thread-id>", "user_id": "alice@example.com" }
    }
  9. Understand the appkit-serving project structure

    main

    The project is organized into client, server, and shared directories:

    • client/: React frontend (contains src/ and public/)
    • server/: Express backend (contains server.ts and routes/)
    • shared/: Shared TypeScript types used by both client and server
    • databricks.yml: Databricks Asset Bundle configuration
    • app.yaml: App configuration
    • .env.example: Template for environment variables
  10. How Long-Running Background Execution works

    main

    To bypass the ~120s HTTP timeout enforced by Databricks Apps, this template uses the background=true flag to run agent tasks asynchronously.

    Workflow:

    1. Initiation: A POST request with background=true returns a response_id immediately.
    2. Execution: The agent runs in the background, managed by LongRunningAgentServer (from databricks-ai-bridge).
    3. Retrieval/Polling: Clients can poll for results or stream them using the GET /responses/{id} endpoint.
    4. Resumption: If a connection is lost, clients can use the starting_after=N parameter to resume streaming from a specific cursor.
    5. Persistence: Stream events are persisted to Lakebase PostgreSQL to support this resumption.
  11. Understand the vacation-rentals project structure

    main

    The project is organized into a client-server architecture:

    • client/: React frontend (source in src/, static assets in public/).
    • server/: Express backend (entry point at server.ts, routes in routes/).
    • shared/: Shared TypeScript types used by both client and server.
    • config/: Configuration files, including SQL queries in queries/.
    • databricks.yml: Databricks Asset Bundle configuration.
    • app.yaml: Application configuration.
    • .env.example: Template for environment variables.
  12. Understand Database Modes: Persistent vs Ephemeral

    main

    The application operates in two modes based on the presence of database environment variables.

    Persistent Mode

    Requirement: POSTGRES_URL or (PGUSER, PGPASSWORD, PGDATABASE, PGHOST) must be configured.

    • Conversations are saved to Postgres/Lakebase.
    • Users can access history via the sidebar.
    • History persists across sessions.

    Ephemeral Mode

    Requirement: No database environment variables are set.

    • Conversations are stored in memory and lost on page refresh or server restart.
    • The sidebar shows "No chat history available".
    • An "Ephemeral" indicator appears in the header.