Skip to content

[appkit plugin] [5/x] Add chat server plugin to @databricks/appkit-agent#387

Open
hubertzub-db wants to merge 12 commits intodatabricks:mainfrom
hubertzub-db:stack/agent-plugin-p5
Open

[appkit plugin] [5/x] Add chat server plugin to @databricks/appkit-agent#387
hubertzub-db wants to merge 12 commits intodatabricks:mainfrom
hubertzub-db:stack/agent-plugin-p5

Conversation

@hubertzub-db
Copy link
Copy Markdown

@hubertzub-db hubertzub-db commented Mar 20, 2026

🥞 Stacked PR


Summary

Adds a ChatPlugin to @databricks/appkit-agent, exported from the @databricks/appkit-agent/chat subpath. The plugin provides a complete chat backend: streaming responses from agent or Databricks model serving endpoints, session management, optional PostgreSQL persistence, feedback via MLflow Traces, and stream resumption.

Adapted from app-templates/e2e-chatbot-app-next](https://github.com/databricks/app-templates/tree/main/e2e-chatbot-app-next), with @databricks/appkit as a peer dependency and a standalone auth module replacing internal imports.

Usage

import { createApp } from "@databricks/appkit";
import { agent, chat } from "@databricks/appkit-agent";
import { Pool } from "pg";

const app = createApp({
  plugins: [
    agent({ /* ... */ }),
    chat({
      pool: new Pool(),       // optional — omit for ephemeral (no history)
      autoMigrate: true,      // creates ai_chatbot schema/tables on startup
      backend: "agent",       // route chat through local agent plugin
    }),
  ],
});

Demo of the chat with persistence and tools (the UI runs from existing e2e-chatbot-app-next)

Screen.Recording.2026-03-25.at.11.04.21.mov

What's included

@@ -0,0 +1,299 @@
/**
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,28 @@
import type { ChatRow } from "./schema";
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,52 @@
const MAX_ENTRIES = 10_000;

function setBounded<K, V>(map: Map<K, V>, key: K, value: V): void {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


export type { ChatRow, MessageRow };

export function createDb(pool: Pool) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hubertzub-db hubertzub-db force-pushed the stack/agent-plugin-p5 branch from 1d83c9e to 61bf6ac Compare March 24, 2026 15:33
@hubertzub-db hubertzub-db changed the title Add @databricks/appkit-chat-server package [appkit plugin] [5/x] Add chat server plugin to @databricks/appkit-agent Mar 24, 2026
@hubertzub-db hubertzub-db requested a review from bbqiu March 24, 2026 16:02
@hubertzub-db hubertzub-db marked this pull request as ready for review March 25, 2026 08:06
@hubertzub-db hubertzub-db force-pushed the stack/agent-plugin-p5 branch 3 times, most recently from c469eda to c4d0cb8 Compare March 25, 2026 10:38
Copy link
Copy Markdown
Collaborator

@bbqiu bbqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with a few nits!

* Consolidated Databricks authentication module.
*
* Supported auth methods (checked in priority order):
* 1. PAT — DATABRICKS_TOKEN env var
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we make pat the lowest priority?
oauth u2m, oauth sp, then pat

could we also add a test to codify this priority order in the future

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reordered and added tests

this.registerEndpoint("chat", `/api/${this.name}`);
}

private resolveBackend(req: express.Request): {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add tests for this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type LanguageModel = any;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be the type from the ai-sdk?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, fixing now

* Resolve session for the request.
*
* Resolution order:
* 1. Custom getSession callback (if provided in plugin config)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some tests to codify this ordering? priority makes sense / is the same as the existing templat

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

);
this.registerEndpoint("deleteChat", `/api/${this.name}/:id`);

// ── POST / (main chat handler) ───────────────────────────────────────
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally for this file, can we add tests for expected behavior of each route?

i think the post is probably the most important to test (ex. fallback behvior, what to do with MCP approvals / denials etc)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me add some tests with simulated requests/responses

/** Enable feedback feature (thumbs up/down). Defaults to !!process.env.MLFLOW_EXPERIMENT_ID. */
feedbackEnabled?: boolean;
/** Auto-create the ai_chatbot schema and tables on startup. Defaults to false. */
autoMigrate?: boolean;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this default to true? in what case would we not want this to run

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, changed to true as default and retested - seems to be idempotent and works well

Move agent plugin source code into src/agent-plugin/ subfolder for
better organization when hosting multiple plugins.
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Add per-package pnpm-lock.yaml and CI/release workflows with
explicit pnpm version and cache-dependency-path.
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
@hubertzub-db hubertzub-db force-pushed the stack/agent-plugin-p5 branch from c4d0cb8 to b8cc404 Compare April 1, 2026 13:26
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
@hubertzub-db hubertzub-db force-pushed the stack/agent-plugin-p5 branch from b8cc404 to 638d1ee Compare April 1, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants