Skip to main content
Caylex widgets let you embed AI agents directly inside your SaaS application. You can add an AI chat interface to run full agentic workflows, and optionally add a permissions panel that lets admin users manage which tools are enabled for the agent.

Overview

Caylex provides two embeddable frontend components:
  • <CaylexChatWidget /> — a chat interface that connects to the Caylex Assistants API. It supports streaming responses, tool calls, saved sessions, connected-service visibility, a background-task approval Inbox, and optional agent-driven page navigation.
  • <CaylexToolPermissionsWidget /> — a permissions panel that lets end users control which tools are always allowed, require approval, or are disabled.
Both widgets use short-lived JWT tokens minted by your backend. Your platform token and navigator API key stay server-side and never reach the browser.

How Authentication Works

The widget uses a token-minting pattern:
1

Mint a widget token on your backend

Your backend calls the Caylex API with a platform access token, navigator API key, and user email.
2

Send the token to your frontend

Caylex returns a short-lived JWT that encodes the navigator context and user identity without exposing raw credentials.
3

Render the widget

Your frontend passes the token to the widget component. The widget handles session creation, streaming responses, token refresh, tool call display, and errors.
The mint endpoint must be called from your backend. Never expose your platform access token or navigator API key to the browser.

Prerequisites

  • A Caylex account
  • A Platform Token from Administration → Access Tokens
  • A Navigator API Key from your project’s navigator drawer → API Keys
  • A User Email for the end user who will chat with the assistant
  • Node.js 18+ for your backend token endpoint
  • React 18+ if you use the React component package
If your frontend does not use React, use the script-tag bundles instead. They include the widget’s frontend dependencies and expose browser globals you can call from plain JavaScript.

Install Packages

If your app uses React, install the widget packages:
Install peer dependencies for the chat widget:
The permissions widget uses the same peer dependencies except react-markdown and remark-gfm. The Caylex widget packages install the @caylex/shared package automatically. For script-tag usage, you do not need to install NPM packages in your frontend. Load the hosted bundle from Caylex’s asset CDN:
The unversioned URLs always serve the latest widgets. For production stability, you can pin a specific version:
The widgets isolate their Ant Design and Emotion styles from the host app by using a widget-specific Ant Design class prefix, injecting Ant Design css-in-js and Emotion styles into the widget root, and mounting widget popovers/drawers inside the widget container.This prevents normal Ant Design theme/style collisions between your app and the widgets. It is not a full Shadow DOM or iframe boundary: extremely broad global CSS in the host app, such as * { ... !important }, button { all: unset }, or global textarea rules, can still affect embedded widget DOM. Avoid broad global selectors if you want the widget to render exactly as designed.

Step 1: Mint A Widget Token

Your backend mints a token by calling the Caylex API.
This endpoint was previously named POST /widget/mint-token. It is now POST /widget/agent-session-init. The old path still works for backward compatibility, but we recommend using /widget/agent-session-init going forward.
token.py
The response includes:
  • token — the widget JWT to pass to the frontend
  • expires_at — ISO timestamp of when the token expires

Step 2: Embed The Chat Widget

Render the widget after your frontend receives a widget token.

Full-Page Widget

Use this pattern when the assistant is a dedicated page in your app.
AIAgentPage.tsx

Floating Popup Widget

Use this pattern when you want a chat bubble in the bottom-right corner that persists across pages. Render it in your root layout so it does not unmount during navigation.
Layout.tsx
Because the widget is in the root layout, it stays mounted across page navigations. Chat state, sessions, and server connections are preserved.

Background Task Approval Inbox

The chat widget can act as the human approval surface for background agent tasks. No additional widget prop is required. When your backend submits a task with approval_mode: "human":
  1. The background worker runs independently until it reaches a tool configured as User Approval.
  2. The widget shows a notification on its session menu for the matching navigator and user_email.
  3. The Inbox tab lists pending background approvals. Opening one displays the persisted task transcript and the same approval card used by interactive chat.
  4. The composer stays disabled because the thread belongs to a background task.
  5. After a decision, the task resumes and the open transcript follows its progress. Any later approval card appears inline.
Only pending approvals appear in the Inbox. This keeps background work out of the regular Chat Sessions list and surfaces it only when user input is required.

Step 3: Enable Agent-Driven Page Navigation

If you want the assistant to navigate users to different pages in your app, pass a navigablePages site map and an onNavigate callback. For simple apps, this site map can be static frontend data. For production SaaS apps, we recommend exposing it from your backend so you can return only the pages available to the current tenant and user.

Expose The Effective Site Map From Your Backend

Your backend should return a NavigablePage[] array. This endpoint can apply your existing tenant, feature flag, and user permission logic before sending pages to the browser.
navigation.ts
Then expose an authenticated endpoint from your SaaS app:
routes.ts
Each page has:
  • name — the page name the assistant sees and references
  • description — optional guidance that helps the assistant know when to navigate there
  • urlTemplate — a base path with optional {param} placeholders
  • templateParams — optional metadata for placeholders written directly in urlTemplate
  • queryParams — optional query filters appended to the resolved URL when the agent supplies a value
The legacy params field remains supported as a deprecated alias for templateParams. Do not provide both fields on the same page. Optional query parameters that the agent does not supply are omitted. Set defaultValue when the host application requires a value even when the agent does not provide one. An empty default intentionally preserves an empty query key:
Query parameter names and values are URL-encoded automatically. Parameters not declared in queryParams are rejected for pages using this contract.
The site map controls what the assistant can discover for navigation, but it is not a security boundary. Your app should still enforce normal authorization when a user visits a page.

Fetch And Pass Navigation To The Widget

The assistant gains two local tools:
  • get_page_info — looks up URL templates and parameter requirements
  • navigate_page_ui — triggers your onNavigate callback with the resolved URL
When the assistant calls navigate_page_ui, Caylex resolves the URL template, the widget calls your callback with the resolved URL, and the assistant confirms the navigation in chat.

Step 4: Embed The Permissions Widget

The permissions widget lets users control which tools the assistant can access through the navigator instance. Each tool can be set to:
  • Always Allow — run without user confirmation
  • User Approval — require confirmation before each use
  • Disabled — block the tool
This widget mirrors the Tool Permissions tab in the navigator drawer on the Caylex platform. Changes made in either place are reflected in both.
Set persistPermissions to true for production. When false or omitted, changes are local-only and are not saved.
The permissions widget uses the same token pattern as the chat widget, but the token does not require user_email because permissions are scoped to the navigator instance, not an individual user.

Token Refresh

Widget tokens are short-lived. To keep sessions alive without interruption, provide a refreshToken callback. The widget automatically calls this function when it receives a 401 response, obtains a fresh token, and retries the request.
Your /api/caylex/token endpoint should call the Caylex mint endpoint from your backend and return the new token.

Customization

Chat Widget Props

The current widget prop is still named agentInstanceId for compatibility. It refers to the Caylex navigator instance.

Permissions Widget Props

Widget Design Space

The Caylex platform includes a Widget Design Space where you can:
  • Enter your credentials and mint tokens interactively
  • Customize colors, dimensions, and feature toggles with live preview
  • Test the chat widget with your actual servers and tools
  • Switch between chat and permissions widget modes
  • Download backend and frontend code snippets for React, script tags, Python, and TypeScript
Use the Widget Design Space to experiment with the widget before integrating it into your application.

API Base URLs

The chat widget and permissions widget use different Caylex services:

Updating Widgets

For React package usage, pull the latest widget versions with NPM:
For script-tag usage, the unversioned CDN URLs automatically serve the latest deployed widgets:
If you want release stability, pin an explicit version and update the URL when you are ready to upgrade:

Security Model

  • Platform token + navigator API key stay on your backend
  • Widget JWT is short-lived and contains only encoded navigator context and user email
  • No raw secrets in the browser — the widgets communicate using the JWT
  • Playground keys are rejected — the mint endpoint blocks playground API keys to prevent misuse

Troubleshooting