Closed drewmacneil closed 1 day ago
Hey @drewmacneil! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together!
The issue you're encountering seems to be related to how the LangSmith
logging system is classifying the logger
chain as a sibling node rather than an independent root when executed within a callback. This behavior might be due to the way AsyncLocalStorage
is managing the execution context and not clearing it properly when callbacks are invoked.
In LangChain.js, AsyncLocalStorage
is used to manage context variables that are scoped to the execution context of runnables. This allows for context isolation and inheritance, which is useful in asynchronous environments [1]. However, if the context is not cleared or reset when entering a new execution context, such as a callback, it might lead to unexpected behavior in how nodes are logged or classified.
To address this, you might need to ensure that the context is explicitly cleared or reset when entering the callback execution. This can be done by managing the AsyncLocalStorage
context manually or by ensuring that the callback execution is treated as a new root context. This would help in correctly classifying the logger
chain as an independent root in the logging system.
If this approach does not resolve the issue, further investigation into how the LangSmith
system determines the hierarchy of nodes and chains might be necessary, as this information is not fully detailed in the available context.
To continue talking to Dosu, mention @dosu.
Checked other resources
Example Code
Given the following graph and callbacks:
Error Message and Stack Trace (if applicable)
No response
Description
If you execute the above code the following way:
I observe that the
logger
chain is reported by LangSmith as a sibling node to theLangGraph
node and not as its own independent root. Given that chain is executed within a callback, I'd have expected it to be logged as its own root.System Info
Platform: macOS Node:
v20.15.0
Yarn:1.22.22