Skip to main content

Install the package

Choose the install command that matches the LLM provider you use. If you use multiple providers, you can combine extras.
pip install agentvista

Initialize the SDK

Call agentvista.init() once at the start of your application — before any agents run.
import agentvista

agentvista.init(api_key="av_xxxxx")
Call init() once at app startup. All subsequent calls to record(), trace_agent, run(), and span() automatically use the initialized client. Calling init() a second time shuts down the existing client and starts a fresh one.
Load your API key from an environment variable rather than hardcoding it:
import os
import agentvista

agentvista.init(api_key=os.environ["AGENTVISTA_API_KEY"])

Parameters

api_key
str
required
Your AgentVista API key. Keys start with av_. Find yours in the AgentVista dashboard under Settings → API Keys.
endpoint
str
default:"https://api.agentvista.dev/api/v1/traces/batch"
The telemetry ingestion endpoint. Override this only if you are self-hosting AgentVista or routing through a proxy.
flush_interval
float
default:"2.0"
Seconds between automatic batch flushes. Events are buffered in memory and sent in the background on this interval. Lowering this value reduces the maximum age of buffered events but increases the number of network requests.

Flushing and shutting down

The SDK batches events in memory and sends them asynchronously every flush_interval seconds. In long-running services this happens automatically. In short-lived scripts or serverless functions you need to flush explicitly before the process exits.

agentvista.flush()

Blocks until all queued events have been delivered to the AgentVista backend.
import agentvista

agentvista.init(api_key="av_xxxxx")

# ... run your agent ...

# Ensure events are delivered before the script exits
agentvista.flush()

agentvista.shutdown()

Flushes all queued events and stops the background transport thread. Call this on application exit in long-running servers.
import atexit
import agentvista

agentvista.init(api_key="av_xxxxx")
atexit.register(agentvista.shutdown)
If your process exits without calling flush() or shutdown(), any events still buffered in memory will be lost. This is most likely to affect short-lived CLI scripts and serverless functions.