Skip to main content

Python SDK for tracking AI conversations and events

Project description

Agnost Conversation SDK

PyPI version Python

Python SDK for tracking AI conversations and events. Monitor your AI agent interactions, track user conversations, and gain insights into how your AI applications are performing.

Installation

pip install agnost

Basic Usage

import agnost

# Initialize with your write key
agnost.init("your-write-key")

# Track an AI interaction
agnost.track_ai(
    user_id="user_123",
    event="chat_completion",
    input="What is the weather?",
    output="The weather is sunny.",
    agent_name="weather-agent"
)

API Reference

init(write_key, **config)

Initialize the SDK with your write key.

agnost.init("your-write-key")

# With custom configuration
agnost.init(
    "your-write-key",
    endpoint="https://api.agnost.ai",
    debug=True
)

track_ai(user_id, event, ...)

Record an AI interaction event.

event_id = agnost.track_ai(
    user_id="user_123",         # Required: User identifier
    event="chat_completion",     # Required: Event name
    input="What is the weather?",
    output="The weather is sunny.",
    agent_name="weather-agent",
    convo_id="conv_abc",         # Group related events
    properties={"temperature": "0.7"},
    latency=1500                 # Execution time in ms
)
Parameter Type Required Description
user_id str Yes User identifier
event str Yes Event name
input str No Input text/prompt
output str No Output/response text
agent_name str No Agent name (e.g., "weather-agent", "support-bot")
convo_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)
latency int No Execution time in milliseconds

identify(user_id, traits)

Associate user characteristics with a user ID.

agnost.identify("user_123", {
    "name": "John Doe",
    "email": "john@example.com",
    "age": 30,
    "plan": "paid"
})

begin(user_id, event, ...)

Begin a partial interaction for deferred completion. Use this when the output is not immediately available.

interaction = agnost.begin(
    user_id="user_123",
    event="chat_completion",
    agent_name="weather-agent"
)

interaction.set_input("What is the weather?")
interaction.set_property("temperature", "0.7")

# ... do async work ...

interaction.finish(
    output="The weather is sunny.",
    latency=1500
)

Interaction Methods:

Method Description
set_input(text) Set the input text
set_properties(dict) Set multiple properties
set_property(key, value) Set a single property
finish(output, success, latency) Complete the interaction

flush()

Manually flush all queued events.

agnost.flush()

shutdown()

Shutdown the SDK and flush remaining events.

agnost.shutdown()

set_debug_logs(enabled)

Enable or disable debug logging.

agnost.set_debug_logs(True)  # See queued events

Configuration

You can customize the SDK behavior using the configuration object:

import agnost_conversation as agnost
from agnost_conversation import ConversationConfig

# Create a custom configuration
config = ConversationConfig(
    endpoint="https://api.agnost.ai",
    debug=False
)

# Apply the configuration
agnost.init("your-write-key", config=config)

Configuration Options

Option Type Default Description
endpoint str "https://api.agnost.ai" API endpoint URL
debug bool False Enable debug logging

Advanced Usage

Conversation Tracking

Group related events using convo_id:

convo_id = "conv_" + str(uuid.uuid4())

# First message
agnost.track_ai(
    user_id="user_123",
    event="chat_completion",
    input="Hello!",
    output="Hi there! How can I help?",
    agent_name="support-bot",
    convo_id=convo_id
)

# Follow-up message
agnost.track_ai(
    user_id="user_123",
    event="chat_completion",
    input="What's the weather?",
    output="The weather is sunny.",
    agent_name="support-bot",
    convo_id=convo_id
)

Direct Client Instantiation

For multiple clients or advanced use cases:

from agnost_conversation import ConversationClient

client = ConversationClient()
client.init("your-write-key")

client.track_ai(
    user_id="user_123",
    event="chat_completion",
    output="Hello!",
    agent_name="greeting-bot"
)

client.shutdown()

Error Handling

# Track failed interactions
agnost.track_ai(
    user_id="user_123",
    event="chat_completion",
    input="Generate an image",
    success=False,
    agent_name="image-agent",
    properties={"error": "Rate limit exceeded"}
)

Contact

For support or questions, contact the founders: founders@agnost.ai

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agnost-0.1.10.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agnost-0.1.10-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file agnost-0.1.10.tar.gz.

File metadata

  • Download URL: agnost-0.1.10.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for agnost-0.1.10.tar.gz
Algorithm Hash digest
SHA256 56a84ccba3a727cfe233411f1dd756634f217ee831b230347f3bfa66944fff34
MD5 369ce75f58a08e12794a361215b27e3d
BLAKE2b-256 b606dc4aec02a59c45e0311678e5b73d447d9c11b1dae0df1315bfbc24a9e2dd

See more details on using hashes here.

File details

Details for the file agnost-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: agnost-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for agnost-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 277ee961bd874b9eee0da774821a99c1c40d005c4331ed6eea537cc07b7c7ba1
MD5 cd7cfba5b5905418d7641ed49755c297
BLAKE2b-256 d7cf19743afd37949942d1dcdb19b58ffcc44807a9f5b8840a75cfd40c242fcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page