langchain - ✅(Solved) Fix Runtime not exported from langchain.agents.middleware [5 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35972Fetched 2026-04-08 00:47:49
View on GitHub
Comments
1
Participants
1
Timeline
16
Reactions
0
Participants
Assignees
Timeline (top)
cross-referenced ×5referenced ×4labeled ×3assigned ×1

Runtime (from langgraph.runtime) is used in after_model callback signatures (state: AgentState, runtime: Runtime) but is not exported from langchain.agents.middleware. Users implementing @after_model hooks need Runtime for the type annotation but must know to import it from langgraph.runtime directly.

This is the same class of issue as #33453 (ModelResponse missing from exports), fixed in #33454.

Runtime is already imported at runtime in multiple middleware modules (human_in_the_loop.py, summarization.py), so there is no circular import concern. It is simply missing from the import list and __all__ in langchain/agents/middleware/__init__.py.

Error Message

from langchain.agents.middleware import after_model, AgentState, Runtime

ImportError: cannot import name 'Runtime' from 'langchain.agents.middleware'

Root Cause

Runtime (from langgraph.runtime) is used in after_model callback signatures (state: AgentState, runtime: Runtime) but is not exported from langchain.agents.middleware. Users implementing @after_model hooks need Runtime for the type annotation but must know to import it from langgraph.runtime directly.

This is the same class of issue as #33453 (ModelResponse missing from exports), fixed in #33454.

Runtime is already imported at runtime in multiple middleware modules (human_in_the_loop.py, summarization.py), so there is no circular import concern. It is simply missing from the import list and __all__ in langchain/agents/middleware/__init__.py.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

aiohttp: 3.13.3 anthropic: 0.84.0 bedrock-agentcore: 1.2.0 blockbuster: 1.5.26 boto3: 1.42.67 click: 8.3.1 cloudpickle: 3.1.2 croniter: 6.2.2 cryptography: 46.0.4 filetype: 1.2.0 google-genai: 1.60.0 grpcio: 1.78.0 grpcio-health-checking: 1.78.0 grpcio-tools: 1.78.0 httpx: 0.28.1 jsonpatch: 1.33 jsonschema-rs: 0.44.1 langgraph: 1.1.2 langgraph-checkpoint: 4.0.1 mcp: 1.26.0 numpy: 2.4.1 opentelemetry-api: 1.40.0 opentelemetry-exporter-otlp-proto-http: 1.40.0 opentelemetry-sdk: 1.40.0 orjson: 3.11.5 packaging: 25.0 protobuf: 6.33.5 pydantic: 2.12.5 pyjwt: 2.10.1 pytest: 9.0.2 python-dotenv: 1.2.1 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.3 sse-starlette: 3.2.0 starlette: 0.52.1 structlog: 25.5.0 tenacity: 9.1.2 truststore: 0.10.4 typing-extensions: 4.15.0 typing_extensions: 4.15.0 uuid-utils: 0.14.0 uvicorn: 0.40.0 watchfiles: 1.1.1 wcmatch: 10.1 zstandard: 0.25.0

PR fix notes

PR #35975: fix(langchain): export Runtime from agents.middleware

Description (problem / solution / changelog)

Fixes #35972

Export Runtime from langchain.agents.middleware. It is used in after_model callback signatures but was missing from the imports and __all__, requiring users to import from langgraph.runtime directly.

Changed files

  • libs/langchain_v1/langchain/agents/middleware/__init__.py (modified, +3/-0)

PR #35986: fix: export Runtime from langchain.agents.middleware

Description (problem / solution / changelog)

Summary

Exports Runtime from langchain.agents.middleware to fix an ImportError when users try to import it directly.

Problem

Runtime (from langgraph.runtime) is used in after_model callback signatures (state: AgentState, runtime: Runtime) but was not exported from langchain.agents.middleware. Users implementing @after_model hooks need Runtime for the type annotation but had to import it from langgraph.runtime directly.

Solution

Added Runtime to the imports and __all__ list in langchain/agents/middleware/__init__.py.

Fixes #35972

Similar PR

This is the same class of fix as #33454 which added ModelResponse to exports.

Changed files

  • libs/langchain_v1/langchain/agents/middleware/__init__.py (modified, +2/-0)

PR #35987: fix: export Runtime from langchain.agents.middleware

Description (problem / solution / changelog)

Summary

Exports Runtime from langchain.agents.middleware to fix an ImportError when users try to import it directly.

Problem

Runtime (from langgraph.runtime) is used in after_model callback signatures (state: AgentState, runtime: Runtime) but was not exported from langchain.agents.middleware. Users implementing @after_model hooks need Runtime for the type annotation but had to import it from langgraph.runtime directly.

Solution

Added Runtime to the imports and __all__ list in langchain/agents/middleware/__init__.py.

Fixes #35972

Similar PR

This is the same class of fix as #33454 which added ModelResponse to exports.

Changed files

  • libs/langchain_v1/langchain/agents/middleware/__init__.py (modified, +2/-0)

PR #35992: fix(agents): export Runtime from langchain.agents.middleware

Description (problem / solution / changelog)

Problem

Runtime (from langgraph.runtime) is used in @after_model and @before_model callback type annotations — e.g.:

@after_model
async def my_hook(state: AgentState, runtime: Runtime) -> AgentState: ...

However, Runtime was not exported from langchain.agents.middleware, forcing users to import it directly from langgraph.runtime instead of the standard single-import entrypoint.

from langchain.agents.middleware import after_model, AgentState, Runtime
# ImportError: cannot import name Runtime from langchain.agents.middleware

Solution

Add from langgraph.runtime import Runtime to langchain/agents/middleware/__init__.py and include "Runtime" in __all__.

Users can now use the expected pattern:

from langchain.agents.middleware import after_model, AgentState, Runtime

Fixes #35972

Changed files

  • libs/langchain_v1/langchain/agents/middleware/__init__.py (modified, +2/-0)

PR #36008: fix(agents): export Runtime from langchain.agents.middleware

Description (problem / solution / changelog)

Fixes #35972

The "Runtime" type from langgraph.runtime is used in AgentMiddleware callback signatures (e.g., "after_model(state, runtime)") but was not re-exported from the middleware module. This caused import errors for users trying to type hint their middleware implementations.

Changes:

  • Added import: "from langgraph.runtime import Runtime"
  • Added "Runtime" to all list

Changed files

  • libs/langchain_v1/langchain/agents/middleware/__init__.py (modified, +3/-0)

Code Example

from langchain.agents.middleware import after_model, AgentState, Runtime
# ImportError: cannot import name 'Runtime' from 'langchain.agents.middleware'

---

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'Runtime' from 'langchain.agents.middleware'
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

#33453 - same class of missing export, fixed in #33454

Reproduction Steps / Example Code (Python)

from langchain.agents.middleware import after_model, AgentState, Runtime
# ImportError: cannot import name 'Runtime' from 'langchain.agents.middleware'

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'Runtime' from 'langchain.agents.middleware'

Description

Runtime (from langgraph.runtime) is used in after_model callback signatures (state: AgentState, runtime: Runtime) but is not exported from langchain.agents.middleware. Users implementing @after_model hooks need Runtime for the type annotation but must know to import it from langgraph.runtime directly.

This is the same class of issue as #33453 (ModelResponse missing from exports), fixed in #33454.

Runtime is already imported at runtime in multiple middleware modules (human_in_the_loop.py, summarization.py), so there is no circular import concern. It is simply missing from the import list and __all__ in langchain/agents/middleware/__init__.py.

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 24.6.0: Mon Jan 19 22:00:10 PST 2026; root:xnu-11417.140.69.708.3~1/RELEASE_X86_64 Python Version: 3.12.9 (v3.12.9:fdb81425a9a, Feb 4 2025, 12:21:36) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information

langchain_core: 1.2.18 langchain: 1.2.12 langsmith: 0.6.6 deepagents: 0.4.11 langchain_anthropic: 1.3.4 langchain_aws: 1.4.0 langchain_google_genai: 4.2.0 langchain_mcp_adapters: 0.2.1 langchain_tavily: 0.2.17 langgraph_api: 0.7.73 langgraph_checkpoint_aws: 1.0.6 langgraph_cli: 0.4.18 langgraph_runtime_inmem: 0.26.0 langgraph_sdk: 0.3.11

Optional packages not installed

deepagents-cli

Other Dependencies

aiohttp: 3.13.3 anthropic: 0.84.0 bedrock-agentcore: 1.2.0 blockbuster: 1.5.26 boto3: 1.42.67 click: 8.3.1 cloudpickle: 3.1.2 croniter: 6.2.2 cryptography: 46.0.4 filetype: 1.2.0 google-genai: 1.60.0 grpcio: 1.78.0 grpcio-health-checking: 1.78.0 grpcio-tools: 1.78.0 httpx: 0.28.1 jsonpatch: 1.33 jsonschema-rs: 0.44.1 langgraph: 1.1.2 langgraph-checkpoint: 4.0.1 mcp: 1.26.0 numpy: 2.4.1 opentelemetry-api: 1.40.0 opentelemetry-exporter-otlp-proto-http: 1.40.0 opentelemetry-sdk: 1.40.0 orjson: 3.11.5 packaging: 25.0 protobuf: 6.33.5 pydantic: 2.12.5 pyjwt: 2.10.1 pytest: 9.0.2 python-dotenv: 1.2.1 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.3 sse-starlette: 3.2.0 starlette: 0.52.1 structlog: 25.5.0 tenacity: 9.1.2 truststore: 0.10.4 typing-extensions: 4.15.0 typing_extensions: 4.15.0 uuid-utils: 0.14.0 uvicorn: 0.40.0 watchfiles: 1.1.1 wcmatch: 10.1 zstandard: 0.25.0

extent analysis

Fix Plan

To fix the issue, we need to add Runtime to the exports in langchain/agents/middleware/__init__.py.

Here are the steps:

  • Open langchain/agents/middleware/__init__.py and add Runtime to the __all__ list.
  • Add from langgraph.runtime import Runtime to the imports.

Example code:

# langchain/agents/middleware/__init__.py
from langgraph.runtime import Runtime
__all__ = [
    # existing exports
    'after_model',
    'AgentState',
    'Runtime',  # add this line
]

Verification

To verify that the fix worked, try importing Runtime from langchain.agents.middleware:

from langchain.agents.middleware import Runtime

If the import succeeds, the fix was successful.

Extra Tips

Make sure to update the __init__.py file in the correct branch and to follow the standard pull request process for the LangChain project. Also, consider adding a test to ensure that Runtime is correctly exported in the future.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING