The Pendo Python SDK lets you instrument Python-based AI agents to send conversation and trace data to Pendo directly from your backend, with no Pendo Web SDK required. This article covers installation, initialization, and enabling tracing with OpenTelemetry or LangChain.
For a conceptual overview of tracing and what trace data looks like in Pendo, see Understand and review agent traces
Prerequisites
Before you begin, you must have:
- Python 3.9 or later.
- Full conversations activated for your agent in Pendo. For setup steps, see Add and configure AI agents in Pendo.
- Your app's Public App ID. A subscription admin can find this in Settings > Subscription settings > Applications after opening the relevant app.
- Your Agent ID. To find it, go to Product > Agent Analytics, then select the settings icon next to the agent name.
Install the SDK
To install the Pendo Python SDK, run:
pip install pendo-server-sdk
Initialize the SDK
Call pendo_sdk.init() once at startup, before your agent handles any requests. Pass your Pendo Public App ID and a default visitor and account identity. Then use set_context() to update the context for each request.
import pendo_sdk # Initialize at app startup pendo_sdk.init( api_key="your-pendo-app-id", agent_id="your-agent-id", endpoint="https://app.pendo.io/", ) # Update context when the visitor, account, or conversation changes pendo_sdk.set_context( visitor_id="user@company.com", account_id="acme_corp", conversation_id="conversation_123456", )
Get tracing data
The Python SDK can capture conversation and trace data through both OpenTelemetry (OTel) and LangChain.
Set up traces with OpenTelemetry
To set up traces with OpenTelemetry, you must have OTel installed in your Python environment.
If OTel is running, the Pendo SDK captures trace data automatically, with no additional SDK configuration required.
Set up traces with LangChain
To set up traces with LangChain, you must have LangChain installed in your Python environment.
Add the PendoCallbackHandler to your LangChain configuration. The handler automatically captures each prompt, response, tool call, LLM call, and execution step as your agent runs. No additional tracking calls are required.
from pendo_sdk.langchain_callback import PendoCallbackHandler
handler = PendoCallbackHandler()
result = llm.invoke(prompt, config={"callbacks": [handler]})Verify your setup
After setting up the SDK, run your agent in your development or staging environment and submit a test prompt. Then confirm data is reaching Pendo:
- Check Agent Analytics. Conversation data is processed in hourly batches. After your code is live in production, new messages typically appear within 15 minutes after the start of the next batch. Go to Product > Agent Analytics, select your agent, and open the Conversations tab to confirm that prompts and responses appear.
- Check for trace data. Conversations with trace data display an activity icon next to the relevant prompt or response in the conversation view. Select it to open the Conversation trace view. For more information, see Understand and review agent traces.
Tip: If your application retries API calls or replays events, reuse the same messageId to avoid duplicate records in Pendo.
Record user reactions manually
The Python SDK automatically captures prompts, responses, and trace data through your chosen setup option.
If you also want to record user_reaction events, such as thumbs-up or thumbs-down feedback, you must send them manually using record_reaction:
# Record a user_reaction for a specific message
pendo_sdk.record_reaction(
conversation_id=conversation_id,
reaction_type=reaction_type, # 'thumbs_up', 'thumbs_down', or 'unreact'
message_span_id=message_id,# same id as the message this reaction is tied to
feedback_comment=feedback_comment, # optional array of text feedback
visitor_id=visitor_id,
account_id=account_id,
)Troubleshooting
If data isn't appearing in Pendo, review these checks in order:
| Check | What to look for |
|---|---|
Missing or incorrect agentId
|
agentId is required and must match the Agent ID configured in Pendo. |
init() called multiple times |
In hot-reload dev environments, init() might be invoked more than once. The SDK ignores subsequent calls and logs a warning. Confirm initialization is happening only once per process. |
| Wrong App ID or endpoint | The SDK sends data to https://app.pendo.io/data/agenticsdk/<apiKey>. Verify that the apiKey value matches your Pendo Public App ID and that outbound traffic to this endpoint is allowed. |