setContextVariable tries setting undefined runTree when used with createReactAgent #7680
Open
5 tasks done
Labels
auto:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
/node_modules/@langchain/core/dist/singletons/async_local_storage/index.js:50
runTree[_CONTEXT_VARIABLES_KEY] =
^
TypeError: Cannot set properties of undefined (setting 'Symbol(lc:context_variables)')
at AsyncLocalStorageProvider.runWithConfig (/node_modules/@langchain/core/dist/singletons/async_local_storage/index.js:50:45)
at /node_modules/@langchain/core/dist/utils/stream.js:218:53
at new Promise ()
at new AsyncGeneratorWithSetup (/node_modules/@langchain/core/dist/utils/stream.js:217:22)
at CompiledStateGraph.stream (/node_modules/@langchain/core/dist/runnables/base.js:170:34)
at CompiledStateGraph.stream (/node_modules/@langchain/langgraph/dist/pregel/index.js:778:22)
at CompiledStateGraph.invoke (/node_modules/@langchain/langgraph/dist/pregel/index.js:992:35)
at RunnableLambda.func (/src/test.ts:21:24)
at /node_modules/@langchain/core/dist/runnables/base.js:1677:45
at AsyncLocalStorage.run (node:internal/async_local_storage/async_hooks:91:14)
Node.js v22.13.1
Description
Looking at the async_local_storage/index.ts implementation,
runTree
does not always get initialized and there is no check forundefined
before theSymbol(lc:context_variables)
key is tried to be set.Passing a runtime value is both documented this way in the LangChain documentation as well as referenced in the LangGraph documentation.
Based on my understanding of the documentation, I thus would expect this code to run on Node.js v22. It might of course be possible that there is an issue with either LangGraph, the documentation, or my example code above, but going through the stack trace and seeing no checks before setting (to either handle the case or inform the user that they did something wrong) currently lets me assume a bug or at least an improvement opportunity in LangChain.
System Info
Linux
Node.js v22.13.1
@langchain/community v0.3.29
@langchain/core v0.3.39
@langchain/langgraph v0.2.45
@langchain/openai v0.4.3
langchain v0.3.15
The text was updated successfully, but these errors were encountered: