What You’ll Build
A simple web page where you can:- Send messages to your AGO agent
- See responses stream in real time, word by word
- Continue past conversations
- (Optional) Drop in a pre-built React chat widget
Prerequisites
- An AGO instance with at least one published agent
- Your workspace’s API URL:
https://YOUR-WORKSPACE.api.useago.com, whereYOUR-WORKSPACEis the part before.useago.comin your AGO URL - The domain where you run the SDK added under Allowed Domains in Support > Settings > Your channels > Widget & SDK (if the list is empty, every domain is allowed)
- Node.js 20.19+ or 22.12+ installed
1
Install the SDK
Create a new project and install the SDK:The package includes both plain JavaScript helpers and React bindings. Vite serves the browser example in a later step.
2
Create the Client
Create a file called Run it to confirm that the client can be created (this does not make a network request):You should see:The
index.mjs and set up the AGO client:baseUrl points the SDK at your workspace’s API. All calls go through this URL.3
Send Your First Message
Add a few lines to Run it again:You should see your agent’s reply printed to the terminal — something like:
index.mjs to send a message and print the response:client.destroy() cleans up open connections when you are done. Always call it before your app exits.4
Stream Responses in Real Time
Waiting for the full response is fine for scripts, but users expect to see text appear as the agent types. The SDK fires events you can listen to:Run
Create an
index.html file with a minimal chat UI:npx vite from the project directory and open the local URL printed in the terminal. Vite resolves the @useago/sdk import used in the HTML; opening the file directly or using a plain static server does not. If you restrict Allowed Domains, add localhost to the list, then type a question and click Send.5
Add Conversation History
By default, each The agent remembers the earlier context, so it knows “And on weekends?” refers to business hours.You can also list and retrieve past conversations:This is useful when you want to show a sidebar with conversation history, or let users pick up where they left off.
sendMessage call starts a new conversation. To continue an existing one, pass a conversationId:6
Drop-in React Chat Component
If you use React, the SDK ships with ready-made components.
ChatWidget renders a chat interface where you place it in your page; it does not add a floating launcher.Option A: Pre-built widget
AgoProvider creates the client and shares it with every AGO component below it. ChatWidget renders the full chat UI — input field, message list, streaming, and conversation management are all built in.Option B: Custom chat with hooks
When you need full control over the UI, use theuseMessages hook instead:useMessages reads the client from the enclosing AgoProvider and returns a messages array, a sendMessage function, and an isLoading flag. Streaming is handled for you — messages updates as each chunk arrives.Other hooks you can use:useAgoClient()— returns the client from the enclosingAgoProvideruseConversation()— manages the conversation list (load, switch, create)
Next Steps
You now have a working chat powered by your AGO agent. Here are some directions to explore:- SDK Integration — full reference for
AgoClientconfiguration and auto-detection viawindow.AGO,<meta>tags, ordata-ago-*attributes - Client Functions — register browser-side functions for your agent
- Widget Deployment — embed the chat widget on your website without writing code
- Public API v1 — use scoped API keys for server-to-server integrations
