LangChain

Integrate Spooled with LangChain using the callback handler.

Install

pip install spooled-ai[integrations]

Setup

my_langchain_agent.py
import spooled
from spooled.integrations.langchain import SpooledLangChainCallbackHandler

recorder = spooled.init(agent_id="my_langchain_agent")
handler = SpooledLangChainCallbackHandler(recorder)

# Pass the handler to your chain
chain = LLMChain(llm=llm, prompt=prompt, callbacks=[handler])
result = chain.invoke({"input": "What is the return policy?"})

spooled.shutdown(success=True)
Note
The callback handler requires a recorder instance. Pass the return value of spooled.init().

LCEL chains

For LangChain Expression Language (LCEL) chains, pass the handler via RunnableConfig:

from langchain_core.runnables import RunnableConfig

config = RunnableConfig(callbacks=[handler])
result = chain.invoke({"input": "..."}, config=config)

What's captured

  • LLM start/end (model, tokens, latency)
  • Tool start/end (function name, argument shapes)
  • Chain start/end (chain type, inputs)
  • Retriever queries (query text shape, result count)
  • Errors and exceptions
Note
Content (prompts, responses, retrieval results) is stripped to hashes. Only structural metadata is recorded.