Put an agent on your site
One of your agents on your website or your app, with a couple of lines of frontend code. It comes in three forms, a chat bubble, an inline chat and a page of its own, and you can use more than one at once: a bubble on every page and an inline chat on your help page. One set of settings and one look apply to all of them, set on the agent's embed in your console, where its live preview shows each form as you change it.
Before a page can show it: turn the agent's embed on, list your sites, and publish a version. People always reach the
agent's version in use. Each line below names the agent by its ID, YOUR_AGENT_ID here; the agent's embed in the
console gives you these lines with its own ID filled in.
A chat bubble
A launcher in a corner of every page that opens a chat window over it. Put these two lines in your site's layout:
<script src="https://hados.io/embed.js" async></script>
<agent-chat agent="YOUR_AGENT_ID" mode="bubble"></agent-chat>
The window is 400 by 640 pixels, 480 by 760 when the bubble is large, and the whole screen on a phone. The launcher, its
label, its corner and its teaser come from the agent's embed settings; position and launcher override them on a page.
An inline chat
The chat in a box of your page, such as a help page's column. It takes the height you give it, 600 pixels when none, and never less than 360:
<script src="https://hados.io/embed.js" async></script>
<agent-chat agent="YOUR_AGENT_ID" style="height: 640px"></agent-chat>
With no script at all, a plain iframe does the same for visitors. A page can't hand an iframe a signed-in person's token, so an agent for signed-in people only says "Sign in to chat." in one.
<iframe
src="https://hados.io/embed/YOUR_AGENT_ID"
title="Chat with Your agent"
style="width: 100%; height: 640px; border: 0"
allow="clipboard-write"
></iframe>
A page of its own
A link that opens the chat full screen, to share anywhere a link goes. Turn the agent's page on in its embed settings. It's for an agent anyone may use: a link carries no one's sign-in, so an agent for signed-in people only says "Sign in to chat" there.
https://hados.io/embed/YOUR_AGENT_ID
The element
<agent-chat>, which the script defines, takes these attributes:
| Attribute | What it does |
|---|---|
agent |
The agent's ID. Required. |
mode |
bubble for a bubble; an inline chat when left out. |
theme |
light, dark or system, over the embed's own. |
lang |
The chat's own words, en-US or zh-CN, over each person's browser's language until they choose one in its menu. visitor-language only tells the agent. |
position |
bottom-right or bottom-left: the bubble's corner. |
launcher |
none hides the bubble's launcher, for a page that opens it from its own button. |
open |
The bubble's window is open while it's set. |
conversation |
A conversation's ID, opened when the chat starts. |
token-url |
A path on your page's own origin that answers the signed-in person's token, read with your page's cookies: for a session behind a cookie (A signing key, below). getUserToken wins when both are set. |
visitor-name, visitor-email, visitor-language, visitor-time-zone |
What your page knows of a visitor, told to the agent as your page's words, never as proof of who they are. |
Its properties are getUserToken, a function that answers the signed-in person's token (below), and context, what the
person is looking at: a JSON object of strings, numbers and booleans, or objects of them one level down, 8 KB at most,
sent with their next message after it changes; null clears it. Its methods are open(), close() and toggle(),
for the bubble's window.
It tells your page what happens with events on the element:
| Event | When | detail |
|---|---|---|
chat-ready |
The chat is up and knows who the person is | |
chat-open, chat-close |
The bubble's window opened or closed | |
chat-conversation |
A conversation opened | { id } |
chat-turn-ended |
A turn of the agent's ended | { conversation, turn, outcome }, its outcome below |
chat-sign-in |
The agent is for signed-in people and your page gave no one's token | |
chat-error |
The chat can't work here, or can't now | { code }, below |
A turn's outcome says how it ended:
answered: the agent answered; its words are in the chat.quiet: a background job's end the agent had nothing new to tell of: it wrote nothing, so there's nothing new to read.stopped: the person stopped it, or a message they sent did; the chat offers to try it again.limit: it stopped at one of the agent's limits, its last words saying so; the chat offers to try it again.failed: it couldn't answer this time; the chat offers to try it again.expired: it asked the person something that went unanswered, and stopped waiting; there's nothing to try again.
TypeScript declarations for the element are at https://hados.io/embed.d.ts.
Its language
The chat speaks English and Simplified Chinese. Each person reads it in their browser's language and can change it in
its menu. Give the element lang to set it for your page, until they choose one in its menu:
<agent-chat agent="YOUR_AGENT_ID" mode="bubble" lang="zh-CN"></agent-chat>
A page of its own and an iframe take it in their address: https://hados.io/embed/YOUR_AGENT_ID?lang=zh-CN. It sets the chat's
own words, its buttons and notices, not the agent's answers, which follow its instructions and the person's messages.
Your sites
The embed runs only on the sites listed on the agent's embed, each an origin: its scheme, its host and its port, such as
https://docs.acme.com or http://erp.corp:8080. https://*.acme.com stands for any name below acme.com. On a page
of any other origin there's no chat, and the element tells it chat-error with site_not_allowed.
Ask the docs
A knowledge agent on a public documentation site, answering visitors with its sources. Put the bubble in the site's layout, and the inline chat on the help page, its box as tall as the page allows:
<script src="https://hados.io/embed.js" async></script>
<agent-chat agent="YOUR_AGENT_ID" mode="bubble"></agent-chat>
Visitors need nothing more. A page may tell the agent who a visitor is with the visitor- attributes; it never has to.
A copilot in your business system
An agent beside the people using your app, acting for the signed-in user through connectors on their own accounts, each signed in once from the card the agent shows (Let people connect their accounts explains how). Hand it the user's token (Signed-in people, below), tell it what they are looking at, and open it from your own button:
const chat = document.querySelector('agent-chat')
chat.context = {
page: 'Orders',
order: 'SO-1042',
status: 'awaiting payment',
}
<script src="https://hados.io/embed.js" async></script>
<agent-chat
agent="YOUR_AGENT_ID"
mode="bubble"
launcher="none"
></agent-chat>
<button type="button" id="ask-ai">Ask AI</button>
<script>
const chat = document.querySelector('agent-chat')
const button = document.getElementById('ask-ai')
button.addEventListener('click', () => chat.toggle())
</script>
The agent reads the context as your page's words, maybe out of date, so it confirms before it acts on them.
Support on a customer portal
Public pages and a signed-in area of one site. The same bubble goes on every page: visitors chat before they sign in, and once they have, your page's token makes them your user, whose conversations follow them on every device.
An internal tool
An intranet app on a private address, such as http://erp.corp:8080. List that origin among the agent's sites, and the
embed works there as it does for a copilot.
A chat to share
The agent's page of its own, with nothing to install: its link in an email, a QR code or a post opens the chat full screen on any device. It's for an agent anyone may use.
Signed-in people
Hand the element the token your identity provider already keeps in the page, and the person chats as your user. Their
token is checked against your identity provider, added once in your console under Access → Sign-in, before they chat, and asked for
again before the session it made ends; it's never stored. The user is the one your servers name with X-User-ID through
the API: the token's sub, or the claim you choose. Sign-in fills in Okta's uid and Entra ID's oid, since their
sub isn't the one ID a person keeps. Add your identity provider in Sign-in, then its line below to your embed code. A
page that keeps no token, with a session behind a cookie, adds token-url to its chat's element instead, naming a path
on its own origin (A signing key, below).
Let people connect their accounts tells the whole story: how your agents know your people, what a person meets as they connect their own accounts, what your own MCP server serves so they can, and how to set up each identity provider in its own console.
Give your identity provider its audience in Sign-in: the app your tokens are for. A token is judged by its aud,
which must hold it; a token with no aud, by its azp; one with neither, by its client_id. So a token your identity
provider signs for another of its apps opens no session, and that app's users never chat as yours. An identity provider
with no audience takes no token.
Auth0
Give your Auth0 client an audience, your API's identifier, so getTokenSilently() answers a signed token rather than
an opaque one, and give your identity provider the same audience in Sign-in.
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => auth0.getTokenSilently()
Okta
Register a custom authorization server's address, such as https://acme.okta.com/oauth2/default: your org's own
access tokens can't be checked. Sign-in reads the person from uid, Okta's user ID, which never changes: a token's
sub is their login, which can. The line renews the token when it's due.
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => oktaAuth.getOrRenewAccessToken()
Entra ID
Your API's access tokens must be version 2: Let people connect their accounts says how, under
Entra ID. Sign-in reads the person from oid, the same in every app of your tenant. MSAL needs the signed-in account
set as its active account.
// Your API's scope, as Expose an API shows it in its app registration
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
const result = await msal.acquireTokenSilent({
scopes: ['YOUR_API_SCOPE'],
})
return result.accessToken
}
Keycloak
The line renews the token first when it ends within 30 seconds.
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
await keycloak.updateToken(30)
return keycloak.token
}
Cognito
Hand over the ID token, whose audience is your app client's ID: Cognito's access tokens carry none.
// With Amplify: import { fetchAuthSession } from 'aws-amplify/auth'
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
const { tokens } = await fetchAuthSession()
return tokens?.idToken?.toString()
}
Clerk
Its audience is your site's address, its origin, such as https://acme.com: Clerk's session tokens carry no aud, and
name the site that asked for them in azp. With a JWT template that adds an aud, such as Convex's convex, its
audience is what that aud holds, since a token with an aud is judged by it alone.
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => Clerk.session.getToken()
Supabase
The project's tokens are checked against the keys it publishes, which it does once it signs with its asymmetric JWT signing keys; a project still on the legacy shared secret publishes none, and it can't be added.
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
const { data } = await supabase.auth.getSession()
return data.session.access_token
}
Firebase
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => firebase.auth().currentUser.getIdToken()
Logto
Give Sign-in your Logto tenant's address, such as https://acme.logto.app/oidc, or its custom domain's: one host
everywhere, since each of Logto's domains is an issuer of its own. Its audience is your API resource's indicator, the API
identifier your page asks Logto for a token for. Logto's access tokens carry no name or email: add them as custom token
claims in Logto, or have your server tell the agents through PUT /users/{id}.
// Your API resource’s indicator, as Logto’s API resources show it
const chat = document.querySelector('agent-chat')
chat.getUserToken = () =>
logtoClient.getAccessToken('https://api.acme.com')
Any OpenID Connect identity provider
// Any OpenID Connect identity provider: its ID or access token,
// here with oidc-client-ts
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => (await userManager.getUser())?.id_token
A signing key
For an app that keeps no token in the page, such as a session behind a cookie: make a signing key in Sign-in. Your
server signs a token for the signed-in user with it, HS256 with the key's ID as its kid and an hour at most, with the
key's secret as CHAT_SIGNING_KEY, and answers it at a path of your site. In Node:
// npm install jsonwebtoken
import jwt from 'jsonwebtoken'
// At /chat-token, for the signed-in user:
const token = jwt.sign(
{
sub: user.id,
name: user.name,
email: user.email,
exp: Math.floor(Date.now() / 1000) + 3600,
},
process.env.CHAT_SIGNING_KEY,
{ algorithm: 'HS256', keyid: 'YOUR_KEY_ID' },
)
In Python:
# pip install pyjwt
import os
import time
import jwt
# At /chat-token, for the signed-in user:
token = jwt.encode(
{
"sub": user.id,
"name": user.name,
"email": user.email,
"exp": int(time.time()) + 3600,
},
os.environ["CHAT_SIGNING_KEY"],
algorithm="HS256",
headers={"kid": "YOUR_KEY_ID"},
)
In PHP:
// composer require firebase/php-jwt
use Firebase\JWT\JWT;
// At /chat-token, for the signed-in user:
$token = JWT::encode(
[
'sub' => $user->id,
'name' => $user->name,
'email' => $user->email,
'exp' => time() + 3600,
],
getenv('CHAT_SIGNING_KEY'),
'HS256',
'YOUR_KEY_ID'
);
In Go:
// go get github.com/golang-jwt/jwt/v5
// At /chat-token, for the signed-in user:
t := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"sub": user.ID,
"name": user.Name,
"email": user.Email,
"exp": time.Now().Unix() + 3600,
})
t.Header["kid"] = "YOUR_KEY_ID"
token, err := t.SignedString([]byte(os.Getenv("CHAT_SIGNING_KEY")))
In Java:
// io.jsonwebtoken: jjwt-api, jjwt-impl and jjwt-jackson 0.12
// At /chat-token, for the signed-in user:
SecretKey key = Keys.hmacShaKeyFor(
System.getenv("CHAT_SIGNING_KEY").getBytes(StandardCharsets.UTF_8));
String token = Jwts.builder()
.header().keyId("YOUR_KEY_ID").and()
.subject(user.getId())
.claim("name", user.getName())
.claim("email", user.getEmail())
.expiration(new Date(System.currentTimeMillis() + 3600_000))
.signWith(key, Jwts.SIG.HS256)
.compact();
Then add token-url to your chat's element, naming that path, and keep its other attributes, such as mode="bubble".
The chat reads it with your page's cookies:
<agent-chat agent="YOUR_AGENT_ID" token-url="/chat-token"></agent-chat>
The chat reads it as it starts, before the session it made ends, and after a refusal, never cached. Answer the token
as plain text, or as {"token": "…"}. When no one is signed in, answer 200 with nothing: an error status, such as
401, counts as no one too, but the chat warns about it in the browser's console each time it asks. Only a path on
the page's own origin, its scheme, host and port, is read, and a page that also sets getUserToken is asked that
instead.
What goes wrong
The element tells your page with chat-error:
| Code | What it means | What to do |
|---|---|---|
site_not_allowed |
The page's origin isn't one of the agent's sites | List it on the agent's embed |
embed_off |
The agent's embed is off, or it has no version in use | Turn the embed on, or publish a version |
user_token_invalid |
Your page's token was refused | Test it in Sign-in, with Test a token; each identity provider and signing key says why it last refused one |
sign_in_not_accepted |
The agent doesn't take people signed in the way your page's token was: through that identity provider, or your signing keys | Choose the sign-ins it takes on the agent's embed, under Who chats; the chat tells the person it isn't available to their account, never to sign in again |
rate_limited |
Visitors sent more than the chat takes for now | Wait: the chat says when |
tenant_suspended |
The chat isn't available | Ask whoever runs your console |
unavailable |
The chat can't be reached now | Nothing: it's tried again |
A page only hears that a token was refused, so Sign-in in your console keeps the last reason each identity provider and signing key refused one, and tests any token you paste. Its reasons:
| Reason | What it means | What to do |
|---|---|---|
isn't a signed token |
Your page gave something else: an opaque access token, or a session's ID | Hand over the signed ID token or access token your identity provider issues |
no issuer or signing key it names |
Its iss, or its kid, is none of yours |
Add its identity provider, or check the signing key's ID |
signed with an algorithm it doesn't allow |
An issuer's token signed with HS256, or not signed at all | An issuer's tokens are RS256, PS256, ES256, ES384, ES512 or EdDSA; HS256 is for a signing key's |
a key it doesn't publish |
Its kid isn't one of the issuer's keys |
The issuer's keys are read again when a token names one they don't hold; a key retired from them can't be used |
its signature doesn't check |
It was signed with another key, or changed after | Sign it with the issuer's key, or the signing key's secret |
expired, no expiry |
Its exp has passed, or it has none |
Hand over a fresh token: the embed asks for one before the session it made ends |
not valid yet, issued in the future |
Its nbf or iat is ahead of the time, past a minute's leeway |
Check your server's clock |
lasts longer than a day |
Its exp is more than 24 hours on |
Make it shorter: an hour is enough |
wrong issuer |
Its iss isn't the issuer's, a final slash included |
Name the issuer exactly as its tokens do |
wrong audience |
Its aud doesn't hold the issuer's audience; with no aud, its azp isn't it; with neither, its client_id isn't |
Give the issuer the audience your tokens carry |
no audience set |
The identity provider names no app its tokens are for, kept from before one was needed | Give it your app's audience in Sign-in |
no user ID, its user ID isn't a string, its user ID is longer than 200 characters or holds a control character |
The claim that names the user is missing or isn't an ID | Point the issuer's user ID claim at your user's ID |