Quickstart
Get started with AgentSight in seconds. With just a few lines of code, you can start monitoring your AI agent's conversations, questions, answers, and more. No setup or infrastructure required.
AgentSight is designed to be lightweight and developer-friendly. Instantiate the client with your API key, and you're ready to track your data.
Installation
First, install the AgentSight SDK. We also recommend installing python-dotenv to manage your API key securely via environment variables.
pip install agentsight python-dotenvInitial setup
- Add your API key to a .env file.
- Initialize the tracker in your code using the key.
# Load API key and initialize AgentSight
import os
from agentsight import ConversationTracker
from dotenv import load_dotenv
load_dotenv() # Load environment variables from .env file
# Retrieve the API key
api_key = os.getenv("AGENTSIGHT_API_KEY")
# Initialize the conversation tracker
tracker = ConversationTracker(api_key=api_key)Setting Your AgentSight API Key
You need an AgentSight API key to send data to your AgentSight dashboard. Get your API key from the AgentSight Dashboard. For security and convenience, we recommend setting it as an environment variable.
export AGENTSIGHT_API_KEY="your_agentsight_api_key_here"Note: If you're using a
.envfile, make sure to callload_dotenv()before initializing ConversationTracker
This code will automatically use the API key from the .env:
from dotenv import load_dotenv
load_dotenv()
tracker = ConversationTracker()Conversation Tracking
Conversations are uniquely identified to help you maintain context across multiple interactions. Once you create a conversation with your ID, use that same ID to reference your tracking methods with that conversation.
Here is how to specify a conversation and conversation_id:
conversation_id="your_conversation_id"
tracker.get_or_create_conversation(
conversation_id=conversation_id
)Conversation ID Priority
You can only pass conversation ID in get_or_create_conversation. If the conversation_id is not set, we will create one automatically for you which could result in creating new conversation in each iteration.
You can use
generate_conversation_idfunctionfrom agentsight.helpers import generate_conversation_id
How to pass tracking data about the conversation like geographical data, source and other, visit Tracking conversation
Tracking Data
Track Question
Capture only the user's question without an immediate answer.
tracker.track_question("How does machine learning work?")Read more Track Question
Track Answer
Log an AI response independently of a question.
tracker.track_answer("Machine learning involves training algorithms...")Read more Track Answer
Track Token Usage
Track usage tokens for your workflows.
tracker.track_token_usage(
prompt_tokens=100,
completion_tokens=25,
total_tokens=125
)Read more Track Token Usage
Track Action
Record specific actions or tool usage during an interaction.
tracker.track_action(
action_name="data_retrieval",
duration_ms=250,
tools_used={"database": "PostgreSQL"},
response="Data successfully retrieved"
)Read more Track Action
Track Button
Log user interface interactions and button clicks.
tracker.track_button(
button_event="user_selection",
label="Confirm Order",
value="order_id_123"
)Read more Track Button
Track Attachments
Send file attachments separately or with other tracking methods.
tracker.track_attachments(
attachments=[{
'filename': 'report.pdf',
'content': base64_encoded_content,
'mime_type': 'application/pdf'
}],
mode='base64' # default
)Attachment Modes:
- Base64: Encode files directly in payload
- Form Data: Send files as multipart form data
Read more Track Attachment
Next Steps
Now that you’ve set up the basics, let’s continue with looking into Core Concepts