Integrations
LangChain
Gate top-level chains with repository callback handler and record accepted output or abandon errors.
Repository example provides IntentLayerCallbackHandler. It gates each top-level chain/agent input, records completed output as accept, and records top-level errors as abandon. Nested runs are ignored.
#Install and run example
python3 -m venv .venv-langchain
source .venv-langchain/bin/activate
pip install -e sdk -r examples/langchain/requirements.txt
python examples/langchain/demo.py --message "Where is order ABC123?"#Add callback
from intentlayer_callback import IntentLayerCallbackHandler
handler = IntentLayerCallbackHandler(session_id="customer-session-42")
result = chain.invoke(user_input, config={"callbacks": [handler]})Handler sends context {"framework": "langchain"} with gate.
#Lifecycle mapping
| LangChain callback | IntentLayer action |
|---|---|
on_chain_start on root | intentlayer.gate(request, session_id, context=...) |
on_chain_end on tracked root | intentlayer.record_outcome(..., "accept", detail=str(outputs)) |
on_chain_error on tracked root | intentlayer.record_outcome(..., "abandon", detail=str(error)) |
One handler instance represents one user session. Input/output objects are converted with str, so customize extraction before production if messages contain unnecessary data.
Source truth
examples/langchain/README.mdexamples/langchain/intentlayer_callback.py