Example: Building a Web Chat Agent

Generate a full, branded browser chat page for an agent - no frontend code, no Node, no build step.

On this page

Example: Building a Web Chat Agent

examples/webui-agent/ generates a complete, themed browser chat page for an agent from a single gateways/* entry with exposes: "webui" - the v1 web chat UI. No frontend code to write, no Node/npm in the build, no separate deploy step for a SPA - the app is a ColdBox module BxAgents copies, already built, into the generated app.

This is the one example in this guide series with real screenshots, because it's the one kind of BxAgents example whose output is actually a browser page. The images below show the current page layout, captured from a demo app (title "Acme Assistant", blue accent), so the title, tagline and colors differ from this example's own config. The page is the same: only the branding comes from the gateway file.

The project

webui-agent/
β”œβ”€β”€ Agent.yml
β”œβ”€β”€ instructions.md
β”œβ”€β”€ gateways/
β”‚   └── chat.bx
└── resources/
    └── webui/
        └── theme.css

Agent.yml is the same shape as every other example:

name: webui-agent
description: An agent reachable through the v1 web chat UI via gateways/.
model: mock/mock-model

The gateway: branding and theme, all in config

gateways/chat.bx is where the actual page comes from - exposes: "webui" is the trigger, and everything else is optional branding:

class {

	function configure() {
		return {
			exposes     : "webui",
			path        : "/chat",
			apiKeyEnvVar: "CHAT_UI_API_KEY",   // optional - omit entirely to leave the agent API open (dev-mode)

			// ---------------------------------------------------------------
			// Branding
			// ---------------------------------------------------------------
			title      : "Acme Support",
			subtitle   : "Orders, returns and shipping",
			icon       : "πŸ›Ÿ",                 // an emoji, an image URL/path ("/logo.svg", "https://..."), or "phosphor:<name>" ("phosphor:lightning")
			welcome    : "Hi! Ask me about an order, a return, or shipping times.",
			placeholder: "Ask about your order...",
			footer     : "Answers are generated and may be wrong - check anything important.",

			// ---------------------------------------------------------------
			// Stream detail - both default to true
			// ---------------------------------------------------------------
			showReasoning: true,   // the model's thinking, as a collapsed "Thinking" strip
			showToolCalls: true,   // each tool call as a collapsed chip (name + arguments)

			// ---------------------------------------------------------------
			// Theme - every key maps to a CSS custom property on the page.
			// ---------------------------------------------------------------
			theme: {
				accent  : "0f766e",
				accentFg: "ffffff",
				radius  : "10px",
				font    : "Inter, system-ui, sans-serif",
				maxWidth: "68%",

				dark: {
					accent  : "2dd4bf",
					accentFg: "05201c"
				}
			}
		};
	}

}

Other branding keys you can add: suggestions (up to four short texts, shown as buttons under the welcome message on an empty conversation; one click sends it) and icon: "phosphor:<name>" for an icon from the page's own set. With no icon the header shows a robot.

suggestions: [ "Where is my order?", "How do I return something?" ],

Colors are written as bare hex with no leading # ("0f766e", not "#0f766e") - BoxLang starts string interpolation at a hash in both single- and double-quoted strings, so a literal one has to be doubled to parse at all. Bare hex sidesteps that entirely; see the comment in the file itself for the full reasoning, and The web chat UI for anything the theme tokens don't cover (that goes in resources/webui/theme.css, inlined last and wins).

Build and run

cd examples/webui-agent
bxAgents build
bxAgents serve --port=8080

Open http://localhost:8080/chat/. You get the left menu, the conversation sidebar, the streaming transcript, and a header and composer in the colors of your theme:

The generated web app: the left menu, a conversation with a tool call, and a themed header and composer

Dark mode

The theme.dark overrides (accent/accentFg) apply when the page switches to dark, from the switch in the header or the Appearance card of Settings - everything else is the same CSS, just re-tokened:

The same page and conversation in the dark theme - theme.dark's accent/accentFg tokens carry over, everything else is the same generated CSS

Narrow screens

The page is responsive with no separate mobile build - at a narrow viewport, the transcript keeps its full width and the menu becomes a drawer instead of squeezing the content:

The same page at a narrow viewport, the transcript keeps the full width

The header and the bar above the conversation

The header holds the agent's icon, title and subtitle, a light or dark switch, and either the Password button (the key, on an agent without accounts like this one) or who is signed in and Sign out.

The header: the agent's title, the light or dark switch, and who is signed in with Sign out

On the Chat page, the bar above the conversation holds the model picker (only when the gateway lists profiles), the context ring (click it for what is sent to the model), any status chips from extensions, and the Fork, Export and Compact buttons. Everything else is a page of the menu on the left, each at its own address (/chat/memory, /chat/vault, /chat/settings, ...); see the web app, page by page.

In the message box, the paperclip attaches a picture or a text file (you can also paste or drop them), the lightning button opens the / commands menu, and the arrow sends. While the agent works the arrow steers the run and a stop button appears.

The optional API key

This example ships apiKeyEnvVar set. It is the agent API's shared secret, so every call to /__bxagents must carry a matching x-bxagents-token header - the app's pages (/chat/) stay reachable regardless, since a browser's plain page navigation can't send a custom header, and the app is exactly what prompts you for the key:

export CHAT_UI_API_KEY="a-real-secret"
bxAgents build
bxAgents serve --port=8080

The page loads fine either way, but a call without the matching key gets a 401 and the page opens its Password dialog by itself (once per page load) - type a-real-secret and choose Save, which loads the page again with it. The key button in the header opens the dialog any time, and Forget it removes the saved value. The password is kept in the browser's localStorage until you forget it. Delete the apiKeyEnvVar line entirely to leave the UI open instead (fine for local dev, never for a public deployment).

Access tokens for administrators

With agentApi: { tokens: true, manageTokens: true } in Agent.yml, a caller with an admin token sees the Access page (/chat/access/tokens). Its Tokens tab lists tokens, creates one (a name, a scope of chat or admin, and how long it lasts, such as 90d), shows the secret once for you to copy, and revokes tokens. manageTokens is off by default and a chat token gets 403. The same thing from a shell is bxAgents token create|list|revoke.

The Access page: the token list and the form that makes a token

One API for the page, the terminal and the gateways

path: "/chat" is only where the app's pages are served. The page calls the agent API at /__bxagents, which derives the visitor's identity server-side only, rather than trusting a caller-supplied userId the way ColdBox's toAi() does, and which the terminal chat and the gateways use too. See Conversation identity for the full reasoning.

What's proven, and what isn't

The generator output itself - the web app module and its config/bxagentsui.json, the sign-in pieces when there are accounts, its registration from Application.bx - is proven by real generator specs and confirmed to compile and instantiate. Over real HTTP, runColdBoxIntegrationTests.bxs proves /__bxagents/health and, further, the shared-preferences round trip (/__bxagents/preferences/set + /__bxagents/preferences) between two independent callers. The screenshots above were captured from the real generated page, not a hand-built mockup - but do at least one real bxAgents serve + browser check of your own theme/branding choices before depending on them in production.

Where to go next

Edit this page Download Markdown Last updated Nov 26, 2026, 8:45:51 AM Report an issue