[PR #5194] Feat/internal typed config structure 5069 #4288

Closed
opened 2026-02-20 17:49:57 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/5194

State: closed
Merged: No


Internal Typed Config Structure

Problem

We currently use RunnableConfig from langchain_core to type our config argument throughout LangGraph. While we use ensure_config() to guarantee that certain fields are present at runtime, RunnableConfig is defined with total=False, making all fields optional from the type system's perspective. This leads to frequent type checker errors when accessing fields that we know are guaranteed to be present after calling ensure_config().

Solution

This PR introduces EnsuredConfig, a new TypedDict that accurately represents the runtime guarantees provided by ensure_config():

class EnsuredConfig(TypedDict):
    # Required fields - guaranteed by ensure_config()
    tags: Required[list[str]]
    metadata: Required[ChainMap[str, Any]]
    recursion_limit: Required[int]
    configurable: Required[dict[str, Any]]
    
    # Optional fields - may be missing or None
    callbacks: BaseCallbackManager | None
    run_name: str | None
    max_concurrency: int | None
    run_id: str | None
    # ... other optional fields

Key Changes

  1. New Type Definition: EnsuredConfig provides stronger type guarantees for internal use
  2. Updated Return Type: ensure_config() now returns EnsuredConfig instead of RunnableConfig
  3. Internal Type Safety: Functions that receive output from ensure_config() now use EnsuredConfig for parameter types
  4. Compatibility Layer: External APIs still accept RunnableConfig | None with proper casting when needed

Files Modified

  • libs/langgraph/langgraph/utils/config.py: Added EnsuredConfig type and updated ensure_config()
  • libs/langgraph/langgraph/utils/runnable.py: Updated internal usage to use EnsuredConfig
  • libs/langgraph/langgraph/pregel/__init__.py: Updated core execution methods to use EnsuredConfig

Relevant Issue

Fixes #5069

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/5194 **State:** closed **Merged:** No --- # Internal Typed Config Structure ## Problem We currently use `RunnableConfig` from `langchain_core` to type our config argument throughout LangGraph. While we use `ensure_config()` to guarantee that certain fields are present at runtime, `RunnableConfig` is defined with `total=False`, making all fields optional from the type system's perspective. This leads to frequent type checker errors when accessing fields that we know are guaranteed to be present after calling `ensure_config()`. ## Solution This PR introduces `EnsuredConfig`, a new `TypedDict` that accurately represents the runtime guarantees provided by `ensure_config()`: ```python class EnsuredConfig(TypedDict): # Required fields - guaranteed by ensure_config() tags: Required[list[str]] metadata: Required[ChainMap[str, Any]] recursion_limit: Required[int] configurable: Required[dict[str, Any]] # Optional fields - may be missing or None callbacks: BaseCallbackManager | None run_name: str | None max_concurrency: int | None run_id: str | None # ... other optional fields ``` ## Key Changes 1. **New Type Definition**: `EnsuredConfig` provides stronger type guarantees for internal use 2. **Updated Return Type**: `ensure_config()` now returns `EnsuredConfig` instead of `RunnableConfig` 3. **Internal Type Safety**: Functions that receive output from `ensure_config()` now use `EnsuredConfig` for parameter types 4. **Compatibility Layer**: External APIs still accept `RunnableConfig | None` with proper casting when needed ## Files Modified - `libs/langgraph/langgraph/utils/config.py`: Added `EnsuredConfig` type and updated `ensure_config()` - `libs/langgraph/langgraph/utils/runnable.py`: Updated internal usage to use `EnsuredConfig` - `libs/langgraph/langgraph/pregel/__init__.py`: Updated core execution methods to use `EnsuredConfig` ## Relevant Issue Fixes #5069
yindo added the pull-request label 2026-02-20 17:49:57 -05:00
yindo closed this issue 2026-02-20 17:49:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#4288