Bridges the active langsmith traceable run tree into LangChain callbacks.
LangChain v1 objects (ChatOpenAI, createAgent, RunnableSequence) do NOT
reliably inherit the surrounding traceable context on their own, so without
this their .invoke() calls open their own top-level traces instead of
nesting under the active run. Passing these callbacks into the invoke config
attaches each LangChain run to the current span.
When there is no active run tree (tracing disabled, or called outside a
traceable — e.g. unit tests), returns the config untouched. getCurrentRunTree
must be checked first because getLangchainCallbacks THROWS rather than
no-ops when the run tree is absent.
The callback resolution is guarded by a timeout so a slow/unreachable
LangSmith API never blocks the LLM call — trace nesting degrades gracefully
while the underlying work keeps running.
Bridges the active langsmith
traceablerun tree into LangChain callbacks.LangChain v1 objects (
ChatOpenAI,createAgent,RunnableSequence) do NOT reliably inherit the surroundingtraceablecontext on their own, so without this their.invoke()calls open their own top-level traces instead of nesting under the active run. Passing these callbacks into the invoke config attaches each LangChain run to the current span.When there is no active run tree (tracing disabled, or called outside a traceable — e.g. unit tests), returns the config untouched.
getCurrentRunTreemust be checked first becausegetLangchainCallbacksTHROWS rather than no-ops when the run tree is absent.The callback resolution is guarded by a timeout so a slow/unreachable LangSmith API never blocks the LLM call — trace nesting degrades gracefully while the underlying work keeps running.