SentrialCallbackHandler to the runnable or compiled graph your application already invokes. Keep its model, tools and prompts. The handler observes callbacks emitted by that invocation; it cannot observe calls made outside it or expose hidden model reasoning.
Install
langchain-core; you do not need to replace a working graph with AgentExecutor or create a new model to add telemetry.
Connect an existing agent
This helper accepts your existing runnable/compiled graph, its normal input and its existing config. It copies the callback collection before adding Sentrial, including when the caller uses a callback manager.{"messages": [("user", user_query)]}; an older executor may expect {"input": user_query}. Preserve configurable values such as the graph’s thread ID, tags, metadata, recursion limit and other callbacks in config.
fail_silently=False makes telemetry failures visible during setup. Decide how monitoring failures should affect your production application; the SDK’s default is True. The helper owns and closes its client per invocation. A long-lived service can reuse a client and flush after a run, then shut it down at process exit.
Final answer and completion
handler.finish() completes the session and attaches accumulated usage, timing and captured output. When no agent-finish callback was emitted, it falls back to the last LLM output. If your graph transforms that output or selects a different final answer, assign the actual customer-visible text before finishing:
success=True describes successful execution of the invocation. It does not prove that a claim was submitted, a refund settled or another business action completed. Keep the tool’s actual receipt and pending/rejected status in the trace.
Streaming and async calls
Pass the handler through the graph’s existingconfig for stream, astream or ainvoke too. Preserve the caller’s callback manager type for async execution. Consume the stream before finishing the Sentrial session, and finish with failure when the application reports an error or cancellation.
Graph-update streaming and provider-token streaming are different: inspect the events your selected stream mode actually emits. Do not mark a stream complete merely because its iterator or response object was created. Keep telemetry draining in the application’s supported completion lifecycle.
Coverage and sensitive data
The handler records available model callbacks, tool inputs/results, errors and usage. It does not guarantee that every internal operation in an arbitrary graph emits callbacks. Cost is an estimate based on returned model/usage metadata and pricing coverage, not a provider invoice. Sethandler.set_input() to the input you want retained, and review PII configuration before collecting sensitive content. Do not add private chain-of-thought expectations to a signal: inspect available messages, tool evidence and the final response.
Verify the integration
- Invoke a test request through the instrumented path. Note the printed Sentrial session ID.
- Open Telemetry and compare the captured tool results and final answer with the real invocation.
- Confirm that existing callbacks still fired and your graph’s thread/configuration was preserved.
- Inspect completion and delivery before evaluating a signal.
Insurance agent walkthrough
Inspect a recorded claims workflow, including rejected and pending outcomes.
Python SDK reference
Sessions, events, callbacks and client lifecycle.

