AgentPulse Documentation
Product analytics for AI-powered conversational products. Track sessions, not traces.
Installation
Requires Python 3.11+. The only required dependency is httpx. Provider integrations (OpenAI, Anthropic, LangChain) are optional extras.
Quick Start
Add AgentPulse to your AI bot in 5 lines:
After init, calls are batched and sent in the background every 5 seconds. The SDK never throws — all transport errors are silently logged.
Core Concepts
Session
A session is one complete user conversation with your AI agent. It's the primary unit of analysis. Sessions are keyed by user_id and auto-timeout after 30 minutes of inactivity.
Event
Something that happened within a session. Types: message.user, message.agent, action.llm_call, action.tool_call, action.cache_hit, outcome.artifact, outcome.payment, outcome.handoff, outcome.abandon, feedback.explicit, feedback.implicit.
Funnel
Configurable conversion stages that every session progresses through. Default: Reached → Engaged → Artifact → Converted.
Margin
revenue - total_cost per session. The unit economics of one conversation. This is what AgentPulse is built to answer.
agentpulse.init()
Initialize the SDK. Call once at application startup.
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Product API key (ap_prod_...) |
product | str | required | Product identifier |
base_url | str | https://agents-pulse.com | AgentPulse server URL |
funnel_stages | list[str] | 4 stages | Custom funnel stage names |
session_timeout_minutes | int | 30 | Inactivity timeout before auto-close |
flush_interval_seconds | float | 5.0 | How often to batch-send events |
max_queue_size | int | 10,000 | Max events in memory queue |
track_content | bool | False | Send message text (privacy-sensitive) |
debug | bool | False | Enable debug logging |
agentpulse.session()
Get or create a session for a user. If a session exists and hasn't timed out, returns it. Otherwise creates a new one.
Session API
session.message()
Track a user or agent message.
session.llm_call()
Track an LLM API call. Pass the raw response object for auto-extraction, or provide fields manually.
session.tool_call()
Track a tool/API call (search, database, external service).
session.cache_hit()
Track a cache hit that saved an LLM call.
session.outcome()
Record a business outcome for this session.
session.payment()
Track a payment event.
session.feedback()
Track explicit or implicit user feedback.
session.end()
Manually end a session. Optional — sessions auto-end on timeout.
Session Properties
| Property | Type | Description |
|---|---|---|
session.conversation_depth | int | Number of user messages |
session.total_cost | float | Sum of all LLM/tool costs (USD) |
session.revenue | float | Sum of all payments (USD) |
session.margin | float | revenue - total_cost |
session.is_ended | bool | Whether session is closed |
agentpulse.instrument()
Wrap an LLM client for automatic call tracking. The wrapped client behaves identically — it just records every call.
agentpulse.shutdown()
Flush pending events and stop background threads. Call before your app exits.
OpenAI Integration
Anthropic Integration
LangChain Integration
API Authentication
All API requests require an X-API-Key header. There are two key types:
| Key Type | Prefix | Scope | Used By |
|---|---|---|---|
| Product Key | ap_prod_ | Single product | Python SDK |
| Dashboard Key | ap_dash_ | All products in org | Dashboard UI |
POST /v1/events
Batch ingest events from the SDK. Typically you don't call this directly — the SDK handles it.
GET /v1/funnel
Returns conversion funnel data.
| Param | Type | Description |
|---|---|---|
from | date/datetime | Start of period (RFC3339 or YYYY-MM-DD) |
to | date/datetime | End of period |
topic | string | Filter by conversation topic |
product_id | string | Required for dashboard keys |
GET /v1/sessions
List sessions with filtering.
| Param | Type | Description |
|---|---|---|
topic | string | Filter by topic |
outcome | string | Filter by outcome |
limit | int | Page size (default 50) |
offset | int | Pagination offset |
product_id | string | Required for dashboard keys |
Get a single session with all events: GET /v1/sessions/{id}
GET /v1/economics
Returns unit economics: total revenue, total cost, gross margin, averages.
| Param | Type | Description |
|---|---|---|
from | date/datetime | Start of period |
to | date/datetime | End of period |
product_id | string | Required for dashboard keys |
GET /v1/topics
Returns topic breakdown with session counts, conversion rates, and revenue.
| Param | Type | Description |
|---|---|---|
from | date/datetime | Start of period |
to | date/datetime | End of period |
limit | int | Max topics returned (default 20) |
product_id | string | Required for dashboard keys |
Configuration Options
The SDK reads configuration from the init() call. For local development, use debug mode:
Privacy
By default, message content is NOT sent to AgentPulse servers. Only metadata is tracked:
- Message count and length
- LLM model, tokens, and cost
- Session duration and outcome
- Topic classification (runs locally)
To enable content tracking: agentpulse.init(..., track_content=True)
Multiple Environments
Use separate products for dev, staging, and production. Each product gets its own API key and isolated data.