Overview
This guide walks through a complete integration flow where your backend system creates an agent conversation in response to an event, then delivers that conversation to your end user via the embedded SDK widget. What you’ll build: A backend function that detects an event, starts an agent conversation about it, and directs the user to pick it up — with the agent’s response already waiting. Time to complete: 20–30 minutes Prerequisites:- A Mindset AI app with a configured agent (agentVersion 3)
- An API key from the Developer section of AMS
- Your API host URL — of the form
{subdomain}.api.mindset.ai, shown as{api-host}in this guide. Available in the Developer section of AMS. - Your SDK script URL — shown as
{MINDSET_SDK_LOCATION}in this guide. Also available in the Developer section of AMS. - The Mindset AI SDK v3 script loaded on the page where the agent will be embedded
How the Flow Works
Your backend makes two API calls before notifying the user, then one more when the user arrives.Step-by-Step
Event Occurs
Your system detects an event that warrants a proactive agent conversation. You know which user it relates to and what information the agent needs.For this example, an order has shipped and you want an agent to proactively brief the user on their delivery details.
Create an Agent Session
Create an agent session that links the agent to the specific user. This session scopes the conversation and can optionally attach specific contexts or MCP servers.Response (201):Store the
agentSessionUid value — you’ll need it in steps 3 and 7.Optional fields:| Field | Purpose |
|---|---|
tags | Label the session (e.g., ["order-shipped", "priority"]) |
Create a Thread via the Threads API
Use the Threads API to start a new conversation thread. The agent processes your message and generates its first response.Response (201):Store the With
Pass the full
agentSessionUid (the composite agentUid::sessionUid string) as the agentUid field. This links the thread to the session you created in step 2.Use the same user identifier type (
externalUserId in this example) that you used when creating the agent session.threadUid — this is the conversation the user will be directed to.The API waits for the agent to process your message before responding. The agent’s first response is now stored in the thread and ready for the user to see.Message Types
By default, your message appears in the conversation as a visible user message. To have the agent act on context without the user seeing your original prompt, usemessageType: "system":"system", the user only sees the agent’s response — not your original message. Because your backend knows who the user is and what triggered the event, you can include personal details (name, order number, account status) in the system message. The agent can then greet the user by name and reference specifics naturally, without needing agent memory or prior conversation history.Store the Identifiers
Your system now has everything it needs to deliver this conversation to the user later.
Store these against the user and event in your system.
| Value | From | Used In |
|---|---|---|
agentSessionUid | Step 2 response | Embedding the SDK (step 7) |
threadUid | Step 3 response | Embedding the SDK (step 7) |
externalUserId | Your system | Authenticating the user (step 6) |
Notify the User
Notify the user through whatever channel suits your application — email, push notification, in-app alert, SMS. Include a link that takes them to the page where the agent is embedded.This step is entirely within your system. Mindset doesn’t send the notification.See Building Deep Links below for how to construct the link.
Authenticate the User
When the user arrives, authenticate them with Mindset to get a Firebase auth token. Use the same identifier you used in steps 2 and 3.Response (201):
Embed the SDK with the Thread
Render the page with the Mindset AI SDK, passing the Replace the placeholders:
agentSessionUid and threadUid so the widget loads the existing conversation rather than starting a new one.{appUid}— your Mindset app UID{agentSessionUid}— the composite string from step 2 (e.g.,your-agent-uid::a1b2c3d4e5){threadUid}— the thread UID from step 3{authToken}— the token from step 6
User Sees the Conversation
The SDK loads the existing thread and displays the agent’s response to the event-specific message you sent in step 3. The user can continue the conversation naturally from there.
- If
messageTypewas"user"(the default), the user sees both their message and the agent’s reply. - If
messageTypewas"system", the user sees only the agent’s reply — the conversation appears to have been initiated by the agent.
User Identifier Consistency
You must use the same user identifier type across all three API calls. The identifier resolves to the same internal user, so mixing types creates separate users.| API Call | Field Name | Example Value |
|---|---|---|
| Agent Sessions (step 2) | externalUserId | user-12345 |
| Threads (step 3) | externalUserId | user-12345 |
| SDK Users Auth (step 6) | externalId | user-12345 |
The
sdkusers/auth endpoint uses externalId rather than externalUserId. Despite the different field name, these refer to the same identifier.Using Email-Based Identifiers
If your users are identified by email rather than an external ID:| API Call | Field Name | Example Value |
|---|---|---|
| Agent Sessions (step 2) | sdkUserEmail | jane@example.com |
| Threads (step 3) | sdkUserEmail | jane@example.com |
| SDK Users Auth (step 6) | sdkUserEmail | jane@example.com |
Error Handling
Thread Creation Errors
| Status | Meaning | Action |
|---|---|---|
| 404 | Agent not found or not version 3 | Check agent UID and that the agent is active |
| 422 | User identifier invalid or agent denied access | Check identifier format; review agent access rules |
| 502 | Agent processing failed | Retry; if persistent, check agent configuration |
| 503 | Agent service unavailable | Retry after a short delay |
| 504 | Agent timed out (120s) | The message may be too complex — simplify or retry |
SDK Thread Loading
If thethreadUid is invalid or the thread can’t be loaded, the SDK displays an error message and offers the user a “Start New Thread” option to begin a fresh conversation.
Complete Backend Example (Node.js)
Building Deep Links
The flow above creates several identifiers that together point to a specific conversation for a specific user. To notify the user in step 5, you need to build a link that routes them to the right place in your application.Why Deep Links Are Your Responsibility
In the embedded SDK model, the Mindset agent lives inside your application. You control how users log in, what pages exist, and how the<mindset-agent> element is rendered. Mindset can’t generate a working deep link for you because we don’t know your application’s URL structure or routing. What we provide is the set of identifiers your application needs to render the right conversation — you build the link.
What Your Deep Link Needs to Encode
At minimum, your link needs to carry enough information for your application to:- Identify the user (so your app can authenticate them and call
/sdkusers/auth) - Retrieve the stored
agentSessionUidandthreadUid(so your app can render<mindset-agent>with the correct attributes)
sid and tid from the query string and passes them to the SDK element. Authentication is handled by your existing user session.
Option B: Use your own event or notification ID
evt-77890 in your database, retrieves the associated agentSessionUid and threadUid stored in step 4, authenticates the user, and renders the agent.
Option C: Route within an existing page
Example: Email Notification with Deep Link
- Recognises Jane from her existing session (or prompts login)
- Reads
sidandtidfrom the query string - Calls
/sdkusers/authwith Jane’sexternalIdto get an auth token - Renders
<mindset-agent agent-uid="{sid}" thread-uid="{tid}">with the token
Universal Client: A Simpler Path
When Mindset provides the entire end-user application — as with Universal Client — the deep linking story is simpler:- User identifier:
realEmailAddress— users log into the UC app directly with their real email, so there’s no need for/sdkusers/author external ID mapping - Agent session: Not required — the Threads API can be called with a plain
agentUidrather than a compositeagentSessionUid, because the UC app manages agent access directly - Deep link: A URL pointing to the specific app, agent, and thread within the UC app
Deep link URL patterns for Universal Client are under active development and will be documented separately.