Skip to main content
This tutorial takes you from zero to a working chat page that sends messages to your AGO agent and displays streaming responses. You will start with plain JavaScript, then optionally add a React component.

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 index.mjs and set up the AGO client:
Run it to confirm everything is connected:
You should see:
The 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 index.mjs to send a message and print the response:
Run it again:
You should see your agent’s reply printed to the terminal — something like:
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:Create an index.html file with a minimal chat UI:
Open 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 sendMessage call starts a new conversation. To continue an existing one, pass a conversationId:
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.
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 the useMessages 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 underlying AgoClient instance
  • useConversation({ 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 AgoClient configuration and auto-detection via window.AGO, <meta> tags, or data-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