Step 1: Install the SDK
Step 2: Initialize the SDK
Import and initialize the SDK with your organization ID:Step 3: Track AI Interactions
Primary Method: begin() and end()
The recommended way to track AI interactions is using begin() to start tracking and end() to complete:
Alternative: track() for Simple Cases
For simple cases where input and output are immediately available, use the track() method:
Track with Conversation Grouping
Group related messages usingconversation_id:
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
track()
Record an AI interaction event.
| Parameter | Type | Required | Description |
|---|---|---|---|
user_id | str | No | User identifier (default: "") |
input | str | No | Input text/prompt |
output | str | No | Output/response text. When success=False, this is treated as the error message |
agent_name | str | No | Agent identifier (defaults to “default”) |
conversation_id | str | No | Conversation ID for grouping |
properties | dict | No | Additional event properties |
timestamp | datetime | No | Event timestamp (defaults to now) |
success | bool | No | Whether successful (default: True). Set to False for errors |
latency | int | No | Execution time in milliseconds |
success=False, the output parameter should contain the error message.
identify()
Associate user characteristics with a user ID.
begin()
Begin a partial interaction for deferred completion. Returns an Interaction object.
Parameters:
user_id(str, optional): User identifier (defaults to "")agent_name(str, optional): Agent name (defaults to “default”)input(str, optional): Input text/prompt (can also useset_input()later)conversation_id(str, optional): Conversation IDproperties(dict, optional): Initial properties
set_input(text)- Set input text (optional if already passed tobegin())set_properties(dict)- Set multiple propertiesset_property(key, value)- Set single propertyend(output, success, latency)- Complete interactionoutput- Response text. Whensuccess=False, this is the error messagesuccess- Whether successful (default:True)latency- Automatically calculated if not provided
flush()
Manually flush all queued events.
shutdown()
Shutdown the SDK and flush remaining events.
Complete Example
Here’s a complete example of a chatbot with conversation tracking:Next Steps
- View your conversation analytics in the Agnost AI dashboard
- Check out Configuration for advanced settings
