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 (Settings > Widget)
- Node.js 18 or later installed
1
Install the SDK
Create a new project and install the SDK:This adds
@useago/sdk (version 0.1.2) to your project. The package includes both vanilla JavaScript helpers and React bindings.2
Create the Client
Create a file called Run it to confirm everything is connected: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:Open
Create an
index.html file with a minimal chat UI:index.html in your browser (you can use a local dev server like npx serve .). Type a question, click Send, and watch the response stream in character by character.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. The fastest option is
ChatWidget, which gives you a floating chat bubble with no extra code.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:useAgo()— returns the underlyingAgoClientinstanceuseConversation({ 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 — complete list of SDK methods
- Widget Deployment — embed the chat widget on your website without writing code
- API Integration — use the REST API directly for server-side or non-JavaScript integrations
