Step 1: Install the SDK
Step 2: Initialize the SDK
Import and initialize the SDK with your organization ID:Step 3: Track AI Interactions
Using begin() and end()
Track AI interactions using begin() to start tracking and end() to complete:
Track with Conversation Grouping
Group related messages usingconversationId:
Step 4: Track User Properties
Associate user characteristics with events:Advanced Features
Adding Properties with begin() and end()
You can add custom properties to track model parameters, metadata, or any other information:
Error Tracking
When tracking failed interactions, setsuccess=false and pass the error message as the output:
Custom Configuration
Configure the SDK with custom settings:API Reference
init()
Initialize the SDK with your organization ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
writeKey | string | Yes | Your organization ID |
config | object | No | Configuration options |
| Option | Type | Default | Description |
|---|---|---|---|
endpoint | string | "https://api.agnost.ai" | API endpoint URL |
debug | boolean | false | Enable debug logging |
identify()
Associate user characteristics with a user ID.
begin()
Begin a partial interaction for deferred completion. Returns an Interaction object.
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | User identifier |
agentName | string | Yes | Agent name |
input | string | No | Input text/prompt (can also use setInput() later) |
conversationId | string | No | Conversation ID (auto-generated if not provided) |
properties | object | No | Initial properties |
event | string | No | Optional event name |
interactionId | string | No | Custom interaction ID (auto-generated if not provided). Useful for retrieving the interaction later with getInteraction() |
| Method | Description |
|---|---|
setInput(text) | Set input text (optional if already passed to begin()) |
setProperties(obj) | Set multiple properties (chainable) |
setProperty(key, value) | Set single property (chainable) |
end(output, success?, latency?) | Complete interaction |
end() Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
output | string | Required | Response text. When success=false, this is the error message |
success | boolean | true | Whether successful |
latency | number | Auto | Automatically calculated if not provided |
getInteraction()
Retrieve an active interaction by its ID. Useful when you need to complete an interaction from a different context (e.g., callback, different function) without passing the Interaction object around.
null if the interaction is not found or has already been completed.
flush()
Manually flush all queued events.
shutdown()
Shutdown the SDK and flush remaining events.
setDebugLogs()
Enable or disable debug logging.
Complete Example
Here’s a complete example of a chatbot with conversation tracking:Using with Custom Client
For multiple clients or advanced use cases:Browser Support
This SDK works in both Node.js and browser environments. It uses the nativefetch API which is available in:
- Node.js 18+
- All modern browsers
Next Steps
- View your conversation analytics in the Agnost AI dashboard
- Check out Configuration for advanced settings
