DOC: Pregel constructor has too many parameters #663

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

Originally created by @YassinNouh21 on GitHub (Jun 4, 2025).

Issue with current documentation:

The Pregel.__init__ method currently takes 24 parameters, which makes it pretty unwieldy to use and maintain. While all these config options are useful, having this many parameters in a single constructor is a code smell.

Current state:

def __init__(
    self,
    *,
    nodes: dict[str, PregelNode | NodeBuilder],
    channels: dict[str, BaseChannel | ManagedValueSpec] | None,
    auto_validate: bool = True,
    stream_mode: StreamMode = "values",
    stream_eager: bool = False,
    output_channels: str | Sequence[str],
    stream_channels: str | Sequence[str] | None = None,
    interrupt_after_nodes: All | Sequence[str] = (),
    interrupt_before_nodes: All | Sequence[str] = (),
    input_channels: str | Sequence[str],
    step_timeout: float | None = None,
    debug: bool | None = None,
    checkpointer: BaseCheckpointSaver | None = None,
    store: BaseStore | None = None,
    cache: BaseCache | None = None,
    retry_policy: RetryPolicy | Sequence[RetryPolicy] = (),
    cache_policy: CachePolicy | None = None,
    config_type: type[Any] | None = None,
    input_model: type[BaseModel] | None = None,
    config: RunnableConfig | None = None,
    trigger_to_nodes: Mapping[str, Sequence[str]] | None = None,
    name: str = "LangGraph",
) -> None:

Problems:

  1. Hard to remember parameter order
  2. IDE autocomplete becomes messy
  3. Easy to miss required vs optional params

Suggestion:
Group related parameters into config objects:

@dataclass
class StreamConfig:
    mode: StreamMode = "values"
    eager: bool = False
    channels: str | Sequence[str] | None = None

@dataclass 
class InterruptConfig:
    after_nodes: All | Sequence[str] = ()
    before_nodes: All | Sequence[str] = ()

# Then:
def __init__(
    self,
    *,
    nodes: dict[str, PregelNode | NodeBuilder],
    channels: dict[str, BaseChannel | ManagedValueSpec] | None,
    input_channels: str | Sequence[str],
    output_channels: str | Sequence[str],
    stream_config: StreamConfig | None = None,
    interrupt_config: InterruptConfig | None = None,
    # ... other grouped configs
):
Originally created by @YassinNouh21 on GitHub (Jun 4, 2025). ### Issue with current documentation: The `Pregel.__init__` method currently takes 24 parameters, which makes it pretty unwieldy to use and maintain. While all these config options are useful, having this many parameters in a single constructor is a code smell. **Current state:** ```python def __init__( self, *, nodes: dict[str, PregelNode | NodeBuilder], channels: dict[str, BaseChannel | ManagedValueSpec] | None, auto_validate: bool = True, stream_mode: StreamMode = "values", stream_eager: bool = False, output_channels: str | Sequence[str], stream_channels: str | Sequence[str] | None = None, interrupt_after_nodes: All | Sequence[str] = (), interrupt_before_nodes: All | Sequence[str] = (), input_channels: str | Sequence[str], step_timeout: float | None = None, debug: bool | None = None, checkpointer: BaseCheckpointSaver | None = None, store: BaseStore | None = None, cache: BaseCache | None = None, retry_policy: RetryPolicy | Sequence[RetryPolicy] = (), cache_policy: CachePolicy | None = None, config_type: type[Any] | None = None, input_model: type[BaseModel] | None = None, config: RunnableConfig | None = None, trigger_to_nodes: Mapping[str, Sequence[str]] | None = None, name: str = "LangGraph", ) -> None: ``` **Problems:** 1. Hard to remember parameter order 2. IDE autocomplete becomes messy 3. Easy to miss required vs optional params **Suggestion:** Group related parameters into config objects: ```python @dataclass class StreamConfig: mode: StreamMode = "values" eager: bool = False channels: str | Sequence[str] | None = None @dataclass class InterruptConfig: after_nodes: All | Sequence[str] = () before_nodes: All | Sequence[str] = () # Then: def __init__( self, *, nodes: dict[str, PregelNode | NodeBuilder], channels: dict[str, BaseChannel | ManagedValueSpec] | None, input_channels: str | Sequence[str], output_channels: str | Sequence[str], stream_config: StreamConfig | None = None, interrupt_config: InterruptConfig | None = None, # ... other grouped configs ): ```
yindo closed this issue 2026-02-20 17:41:10 -05:00
Author
Owner

@sydney-runkle commented on GitHub (Jun 11, 2025):

Thanks for your concern. Indeed, Pregel is a bit overloaded. I'm not convinced that nesting would help much here, unfortunately.

We can definitely consider adding some utility methods to initialize with minimal settings (so basically just building from nodes). Going to close for now, we're going to work on solidifying this API for v1. I think revisiting this after that point would make sense.

@sydney-runkle commented on GitHub (Jun 11, 2025): Thanks for your concern. Indeed, `Pregel` is a bit overloaded. I'm not convinced that nesting would help much here, unfortunately. We can definitely consider adding some utility methods to initialize with minimal settings (so basically just building from nodes). Going to close for now, we're going to work on solidifying this API for v1. I think revisiting this after that point would make sense.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#663