Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mindset.ai/llms.txt

Use this file to discover all available pages before exploring further.

Three complete starter integrations. The Built-in chat UI tab is the fastest path to a working agent. The two headless tabs show how to render your own UI on top of the <mindset-agent> element.
This is the minimum integration. The element renders Mindset AI’s built-in chat UI inside a shadow DOM. Your users see a chat panel; you write no UI code.

Complete page

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Mindset AI agent</title>
  <style>
    body { margin: 0; font-family: system-ui, sans-serif; }
    main { max-width: 800px; margin: 0 auto; padding: 2rem; }
    mindset-agent { display: block; height: 600px; border: 1px solid #ddd; border-radius: 8px; }
  </style>
</head>
<body>
  <main>
    <h1>Support agent</h1>
    <p>Ask anything about your account, orders, or our products.</p>

    <mindset-agent
      agent-uid="agt-your-agent-uid"
    ></mindset-agent>
  </main>

  <script src="MINDSET-SERVER-URL/mindset-sdk3.umd.js"></script>
  <script>
    window.mindset.init({
      appUid: 'your-app-uid',
      fetchAuthentication: async () => {
        // Your application's API - validates current user and then calls Mindset AI's API to create
        const r = await fetch('/api/mindset-token', { credentials: 'include' });
        const { authToken } = await r.json();
        return authToken;
      },
    });
  </script>
</body>
</html>
Replace the agent and app UIDs with yours, set up the token endpoint, and you have a working chat panel.

What you get

  • Chat input and message history
  • Thread switcher (the user can start, switch, rename, and delete threads)
  • Streaming responses with typing indicator
  • Tool widgets rendered automatically (cards, carousels, custom UIs)
  • Quick reply chips and follow-up question buttons
  • Citation display when the agent uses retrieval
  • Theme that matches the page’s color scheme (configurable)

Sizing the element

<mindset-agent> is display: block by default. Size it like any other block element:
mindset-agent {
  display: block;
  height: 600px;
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
}
Common patterns:
  • For full-page chat, use height: 100vh; width: 100%.
  • For a sidebar, use height: 100%; width: 360px.
  • For an embedded panel, use a fixed height like the example above.
The chat UI is responsive within the element. It works at sizes from ~320px wide up to full screen.

Reacting to events

Even with the built-in UI, you can hook into events to integrate the agent with the rest of your page.
const agent = document.querySelector('mindset-agent');

// Sync the active thread to the URL
agent.addEventListener('mindset:thread-changed', (e) => {
  if (e.detail.threadUid) {
    history.replaceState({}, '', `?thread=${e.detail.threadUid}`);
  }
});

// Track turn completions in your analytics
agent.addEventListener('mindset:complete', (e) => {
  analytics.track('agent_turn_complete', {
    threadId: e.detail.threadId,
    responseLength: e.detail.response.length,
  });
});

// Show your own loading state outside the chat panel
agent.addEventListener('mindset:agent-busy', () => updateStatusIndicator('thinking'));
agent.addEventListener('mindset:agent-idle', () => updateStatusIndicator('ready'));

Driving the agent from outside

You can call methods on the element from anywhere on your page. Useful for:Quick-action buttons that send a pre-written message:
<button id="ask-status">Where's my order?</button>

<script>
  document.getElementById('ask-status').addEventListener('click', () => {
    document.querySelector('mindset-agent').sendMessage("Where's my order?");
  });
</script>
Deep-linking to a specific thread:
const params = new URLSearchParams(location.search);
const threadUid = params.get('thread');

document.querySelector('mindset-agent').addEventListener('mindset:agent-idle', async function once() {
  if (threadUid) {
    await this.switchThread(threadUid);
  }
  this.removeEventListener('mindset:agent-idle', once);
}, { once: false });
Programmatic priming. Silently prime the agent with context when the user does something on the page:
document.querySelector('.cart-button').addEventListener('click', () => {
  const agent = document.querySelector('mindset-agent');
  agent.sendMessage('the user just opened the cart panel', { silent: true });
});
The agent receives the message and can respond, but no user-side bubble appears in the chat.

Adding page tools

Page tools let the agent call functions on your page during a turn. Configure them with agent.setPageTools():
const agent = document.querySelector('mindset-agent');

agent.setPageTools([
  {
    name: 'lookup_order',
    description: 'Look up the current user\'s order by ID',
    parameters: {
      type: 'object',
      properties: {
        orderId: { type: 'string', description: 'The order ID' },
      },
      required: ['orderId'],
    },
    handler: async ({ orderId }) => {
      const r = await fetch(`/api/orders/${orderId}`);
      return await r.json();
    },
  },
]);
Call setPageTools once the element has fired mindset:agent-idle. See When the element is ready to call.

Configuration via attributes

For static setup that’s known at render time, you can pass values as attributes on the element instead of calling JS methods. See the <mindset-agent> reference for the full list.
<mindset-agent
  agent-uid="agt-..."
  initial-question="What can I help you with today?"
  situational-awareness='{"currentPage":"/products","userPlan":"enterprise"}'
></mindset-agent>
Attributes are read once at render time. Use the JS method if you need to update values dynamically.

Switching to headless later

If you outgrow the built-in UI and want to render your own, add the headless attribute and start listening for events:
<mindset-agent agent-uid="agt-..." headless></mindset-agent>
The runtime, state machine, auth flow, and DOM events stay the same. The only thing that changes is whether the element renders its own UI. Switch to the Headless: vanilla HTML or Headless: React tab above for what that looks like end-to-end.

Methods reference

Every method on the element with signatures and behaviors.

Events reference

Every event the element fires, with payload shapes.

Integration walkthrough

The end-to-end setup, from token endpoint to working agent.

Data channels overview

How your application talks to the agent.