Skip to main content
The AGO JavaScript SDK (@useago/sdk) lets you integrate AGO agents into any web application. Use it to build fully custom chat interfaces, handle streaming responses, manage conversations, and register client-side functions that agents can invoke.

Installation

For React applications, the SDK also exports hooks and pre-built components:

Quick Start

Vanilla JavaScript

Zero-Config Setup

If your page already includes the AGO widget script or meta tags, use createAgo to auto-detect configuration:
The SDK looks for configuration in this order:
  1. window.AGO.basepath global variable
  2. <meta name="ago-base-url"> tag
  3. data-ago-base-url attribute on the body or a script tag
Explicit options override the detected values:

React

Vue.js

Then use composables in your components:

Angular

Then inject in any component or service:

Configuration

Create a client instance with the following options:
You can update configuration after initialization:

Sending Messages

Basic Message

Message with Options

Speech to Text

Use the audio transcription endpoint to turn a recording into an editable draft. This endpoint works with the SDK’s message flow; the example below uses fetch for the audio upload. Speech to text is off by default and must be enabled in the tenant configuration. Read permissions[].speech_to_text_enabled from GET /api/sdk/v1/config to decide whether to show a microphone. Audio uploads return 403 while the setting is disabled. Use the same user identifier and authentication as your SDK client:
For JWT authentication, include Authorization: Bearer <token> as you do for other SDK requests. Keep permission headers consistent with your message requests. Do not manually set Content-Type when uploading FormData. Record audio on HTTPS (or localhost) after the user grants microphone access. WebM, MP4/M4A, OGG, WAV, MP3, MPEG/MPGA, and FLAC files up to 25 MB are accepted. For an iframe, delegate access with allow="microphone" and check that the host page’s Permissions Policy permits it.

Streaming Events

Listen to events for real-time updates as the agent responds:

Conversations

List Conversations

Load a Conversation

Get Messages


Feedback

Submit thumbs-up or thumbs-down feedback on agent responses:

Tool Call Interactions

When an agent invokes a tool that requires user input (such as a form or a confirmation), the SDK emits events you can handle:

Events Reference


Defining Reusable Functions

Use defineFunction to create reusable function definitions that agents can invoke on the client side:
In React, use the useAgoFunction hook:
See Client Functions for more details on how agents invoke client-side functions.

Page Context

Give the agent awareness of what the user is currently looking at — the active order, the visible dashboard filter, the open ticket. Context entries are attached to every message and surfaced to the agent as a structured prompt section.

Vanilla JavaScript

For context that lives outside your application state (global stores, refs, computed values), register a provider function that runs at each message send so the agent always receives the freshest value:

React

Use the useAgoContext hook to attach context declaratively. It registers when the component mounts and cleans up on unmount:
Pass a function instead of an object for values that aren’t captured in React state:
Each entry carries three optional fields:

SSE Streaming Helpers

The SDK provides helper functions for working with streaming responses:

React Components

The SDK provides pre-built React components for common use cases.

AgoProvider

Provides the AgoClient to your entire React app via context:
Access the client from any child component:

ChatWidget

A complete, ready-to-use chat interface:

Message

Renders a single message with markdown formatting and sources. For the last message, enable follow-up suggestions and provide your click handler:
The Message component supports:
  • Markdown rendering, including GitHub-flavored markdown: bold, italic, headings, lists, code blocks, links, blockquotes, tables, task lists, and strikethrough
  • Agent name display for assistant messages when showAgentName={true}; names are hidden by default
  • Knowledge source citations with links
  • Follow-up reply buttons when the message has suggestions and isLast={true}; onFollowUpClick receives the selected reply text, and buttons are disabled when this handler is omitted
  • Streaming indicator while a response is in progress

Markdown

Renders a raw markdown string the same way Message renders assistant content. Use it when you build a fully custom chat UI but still want consistent markdown output:

React Hooks

useAgo

Creates and manages the SDK client lifecycle:
The hook handles client creation, cleanup on unmount, and dynamic config updates.

useMessages

Manages messages within a conversation:

useConversation

Manages the conversation list and selection:

Custom Chat UI Example

Build a fully custom interface using hooks:

Cleanup

Always destroy the client when it is no longer needed to free resources:
In React, the useAgo hook handles cleanup automatically on unmount.