Passing StreamWriter explicitly with python 3.9.17 fails with "RuntimeError: Called get_config outside of a runnable context" #924

Closed
opened 2026-02-20 17:42:23 -05:00 by yindo · 1 comment
Owner

Originally created by @jayasoo on GitHub (Aug 18, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

import asyncio
from typing import TypedDict
from langgraph.types import StreamWriter
from langgraph.graph import StateGraph, START

class State(TypedDict):
  topic: str
  joke: str

async def generate_joke(state: State, writer: StreamWriter): 
  writer({"custom_key": "Streaming custom data while generating a joke"})
  return {"joke": f"This is a joke about {state['topic']}"}

async def main():
  graph = (
    StateGraph(State)
    .add_node(generate_joke)
    .add_edge(START, "generate_joke")
    .compile()
  )
  async for chunk in graph.astream(
      {"topic": "ice cream"},
      stream_mode="custom", 
  ):
    print(chunk)

if __name__ == "__main__":
  asyncio.run(main())

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/test.py", line 28, in <module>
    asyncio.run(main())
  File "/Users/jayasooryankv/.pyenv/versions/3.9.17/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/jayasooryankv/.pyenv/versions/3.9.17/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/test.py", line 21, in main
    async for chunk in graph.astream(
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/main.py", line 2939, in astream
    async for _ in runner.atick(
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/_runner.py", line 401, in atick
    _panic_or_proceed(
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/_runner.py", line 511, in _panic_or_proceed
    raise exc
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/_retry.py", line 137, in arun_with_retry
    return await task.proc.ainvoke(task.input, config)
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/_internal/_runnable.py", line 710, in ainvoke
    input = await step.ainvoke(input, config, **kwargs)
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/_internal/_runnable.py", line 474, in ainvoke
    ret = await self.afunc(*args, **kwargs)
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/test.py", line 11, in generate_joke
    writer({"custom_key": "Streaming custom data while generating a joke"})
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/main.py", line 2854, in stream_writer
    get_config()[CONF][CONFIG_KEY_CHECKPOINT_NS].split(
  File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/config.py", line 29, in get_config
    raise RuntimeError("Called get_config outside of a runnable context")
RuntimeError: Called get_config outside of a runnable context

Description

Using the sample code from the documentation. I expect the code to run and print the custom stream that I have written using the StreamWriter. But I'm getting an error stating "RuntimeError: Called get_config outside of a runnable context".

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:55 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6031
Python Version: 3.9.17 (main, May 13 2024, 12:37:24)
[Clang 15.0.0 (clang-1500.3.9.4)]

Package Information

langchain_core: 0.3.74
langsmith: 0.4.14
langgraph_sdk: 0.2.0

Optional packages not installed

langserve

Other Dependencies

httpx<1,>=0.23.0: Installed. No version info available.
httpx>=0.25.2: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langsmith-pyo3>=0.1.0rc2;: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
openai-agents>=0.0.3;: Installed. No version info available.
opentelemetry-api>=1.30.0;: Installed. No version info available.
opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available.
opentelemetry-sdk>=1.30.0;: Installed. No version info available.
orjson>=3.10.1: Installed. No version info available.
orjson>=3.9.14;: Installed. No version info available.
packaging>=23.2: Installed. No version info available.
pydantic<3,>=1: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pytest>=7.0.0;: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests-toolbelt>=1.0.0: Installed. No version info available.
requests>=2.0.0: Installed. No version info available.
rich>=13.9.4;: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
vcrpy>=7.0.0;: Installed. No version info available.
zstandard>=0.23.0: Installed. No version info available.

Originally created by @jayasoo on GitHub (Aug 18, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python import asyncio from typing import TypedDict from langgraph.types import StreamWriter from langgraph.graph import StateGraph, START class State(TypedDict): topic: str joke: str async def generate_joke(state: State, writer: StreamWriter): writer({"custom_key": "Streaming custom data while generating a joke"}) return {"joke": f"This is a joke about {state['topic']}"} async def main(): graph = ( StateGraph(State) .add_node(generate_joke) .add_edge(START, "generate_joke") .compile() ) async for chunk in graph.astream( {"topic": "ice cream"}, stream_mode="custom", ): print(chunk) if __name__ == "__main__": asyncio.run(main()) ``` ### Error Message and Stack Trace (if applicable) ```shell Traceback (most recent call last): File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/test.py", line 28, in <module> asyncio.run(main()) File "/Users/jayasooryankv/.pyenv/versions/3.9.17/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Users/jayasooryankv/.pyenv/versions/3.9.17/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/test.py", line 21, in main async for chunk in graph.astream( File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/main.py", line 2939, in astream async for _ in runner.atick( File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/_runner.py", line 401, in atick _panic_or_proceed( File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/_runner.py", line 511, in _panic_or_proceed raise exc File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/_retry.py", line 137, in arun_with_retry return await task.proc.ainvoke(task.input, config) File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/_internal/_runnable.py", line 710, in ainvoke input = await step.ainvoke(input, config, **kwargs) File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/_internal/_runnable.py", line 474, in ainvoke ret = await self.afunc(*args, **kwargs) File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/test.py", line 11, in generate_joke writer({"custom_key": "Streaming custom data while generating a joke"}) File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/pregel/main.py", line 2854, in stream_writer get_config()[CONF][CONFIG_KEY_CHECKPOINT_NS].split( File "/Users/jayasooryankv/Documents/workspace/projects/converse_agent/.venv/lib/python3.9/site-packages/langgraph/config.py", line 29, in get_config raise RuntimeError("Called get_config outside of a runnable context") RuntimeError: Called get_config outside of a runnable context ``` ### Description Using the sample code from the [documentation](https://langchain-ai.github.io/langgraph/how-tos/streaming/#async). I expect the code to run and print the custom stream that I have written using the StreamWriter. But I'm getting an error stating "RuntimeError: Called get_config outside of a runnable context". ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:55 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6031 > Python Version: 3.9.17 (main, May 13 2024, 12:37:24) [Clang 15.0.0 (clang-1500.3.9.4)] Package Information ------------------- > langchain_core: 0.3.74 > langsmith: 0.4.14 > langgraph_sdk: 0.2.0 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > httpx<1,>=0.23.0: Installed. No version info available. > httpx>=0.25.2: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langsmith-pyo3>=0.1.0rc2;: Installed. No version info available. > langsmith>=0.3.45: Installed. No version info available. > openai-agents>=0.0.3;: Installed. No version info available. > opentelemetry-api>=1.30.0;: Installed. No version info available. > opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available. > opentelemetry-sdk>=1.30.0;: Installed. No version info available. > orjson>=3.10.1: Installed. No version info available. > orjson>=3.9.14;: Installed. No version info available. > packaging>=23.2: Installed. No version info available. > pydantic<3,>=1: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pytest>=7.0.0;: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests-toolbelt>=1.0.0: Installed. No version info available. > requests>=2.0.0: Installed. No version info available. > rich>=13.9.4;: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > vcrpy>=7.0.0;: Installed. No version info available. > zstandard>=0.23.0: Installed. No version info available.
yindo added the bugpending labels 2026-02-20 17:42:23 -05:00
yindo closed this issue 2026-02-20 17:42:23 -05:00
Author
Owner

@sydney-runkle commented on GitHub (Sep 8, 2025):

Unfortunately async context management doesn't work with Python's asyncio library. Python 3.9 is at EOL in a few days -- should work with Python 3.11+

@sydney-runkle commented on GitHub (Sep 8, 2025): Unfortunately async context management doesn't work with Python's asyncio library. Python 3.9 is at EOL in a few days -- should work with Python 3.11+
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#924