Secureagentics integrates with LangChain through a custom callback handler. The handler extends LangChain’sDocumentation Index
Fetch the complete documentation index at: https://docs.adrian.secureagentics.ai/llms.txt
Use this file to discover all available pages before exploring further.
BaseCallbackHandler and automatically forwards LLM and tool events to Secureagentics whenever your chain or agent runs. You add it once and all activity is captured without modifying your chain logic.
Prerequisites
- A Secureagentics account with an API key. Find your key in Settings → API Keys.
- LangChain installed in your Python environment.
Steps
Register your LangChain agent
Register the agent with Secureagentics to receive an Save the
agent_id. Pass "langchain" as the framework value.id value from the response:Create the SecureagenicsCallbackHandler
Create a class that extends
BaseCallbackHandler. Each callback method sends the appropriate event type to the Secureagentics events API.The handler uses a
trace_id tied to each LLM run’s run_id so that start and end events for the same invocation are linked in the Secureagentics event log.python
Attach the handler to your chain or agent
Pass an instance of
SecureagenicsCallbackHandler to your chain’s callbacks parameter. The handler runs automatically for every LLM and tool invocation.python
Complete example
The
_post_event method wraps the HTTP call in a try/except block. This ensures that a network error or a Secureagentics outage never raises an exception inside your LangChain agent.