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 AGO domain (e.g.,
acme.useago.com) - The domain where you run the SDK added to your allowed domains list (Channels > Widget & SDK)
- Node.js 20.19+ or 22.12+ installed for the Vite 7 browser example
1
Install the SDK
Create a new project and install the SDK:These examples use
@useago/sdk 1.9.0 and Vite 7.3.1. The package includes both vanilla JavaScript helpers and React bindings.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 AGO instance. All API calls go through this domain.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 package import used in the HTML; opening the file directly or using a plain static server does not. Add that local origin to your workspace’s allowed origins, 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 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({ client })— 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
