DynamicRunnable Class — langchain Architecture
Architecture documentation for the DynamicRunnable class in configurable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 362fbd14_1215_07f6_f808_35a613dfc00b["DynamicRunnable"] 362fbd14_1215_07f6_f808_35a613dfc00b["DynamicRunnable"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|extends| 362fbd14_1215_07f6_f808_35a613dfc00b 3e4f3163_58be_ee5e_f841_ae0bd0577190["configurable.py"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|defined in| 3e4f3163_58be_ee5e_f841_ae0bd0577190 959b2dbf_cb30_ef51_c8ed_286f29e4b3a6["is_lc_serializable()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 959b2dbf_cb30_ef51_c8ed_286f29e4b3a6 08ff5826_a6c3_183c_2124_767a362f0bd6["get_lc_namespace()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 08ff5826_a6c3_183c_2124_767a362f0bd6 0cf2c555_3dd9_6c29_bef4_b35f12f50c26["InputType()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 0cf2c555_3dd9_6c29_bef4_b35f12f50c26 437b2093_4426_6106_ae14_8cb2ced039ad["OutputType()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 437b2093_4426_6106_ae14_8cb2ced039ad 248ca6fd_e22f_526e_f252_f7a2c997d6ec["get_input_schema()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 248ca6fd_e22f_526e_f252_f7a2c997d6ec b6bb4444_c935_aeb5_67e1_a841dfa846cc["get_output_schema()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| b6bb4444_c935_aeb5_67e1_a841dfa846cc 9435bb2f_f83c_18e7_280f_f06fab12b7c9["get_graph()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 9435bb2f_f83c_18e7_280f_f06fab12b7c9 72ec291d_a8c9_f256_0140_bae8f933fafa["with_config()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 72ec291d_a8c9_f256_0140_bae8f933fafa 6c8c0cc1_0a40_0783_8101_190958516082["prepare()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 6c8c0cc1_0a40_0783_8101_190958516082 8b757577_57b1_e339_365a_8b77f7fb67ee["_prepare()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 8b757577_57b1_e339_365a_8b77f7fb67ee d2daec15_b363_e821_e6c5_fd596970406d["invoke()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| d2daec15_b363_e821_e6c5_fd596970406d 36db5f71_2723_a4d9_b1dc_bca712e26207["ainvoke()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 36db5f71_2723_a4d9_b1dc_bca712e26207 8521cf9a_986c_818c_2bc6_6bd0a10e4e47["batch()"] 362fbd14_1215_07f6_f808_35a613dfc00b -->|method| 8521cf9a_986c_818c_2bc6_6bd0a10e4e47
Relationship Graph
Source Code
libs/core/langchain_core/runnables/configurable.py lines 49–315
class DynamicRunnable(RunnableSerializable[Input, Output]):
"""Serializable `Runnable` that can be dynamically configured.
A `DynamicRunnable` should be initiated using the `configurable_fields` or
`configurable_alternatives` method of a `Runnable`.
"""
default: RunnableSerializable[Input, Output]
"""The default `Runnable` to use."""
config: RunnableConfig | None = None
"""The configuration to use."""
model_config = ConfigDict(
arbitrary_types_allowed=True,
)
@classmethod
@override
def is_lc_serializable(cls) -> bool:
"""Return `True` as this class is serializable."""
return True
@classmethod
@override
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the LangChain object.
Returns:
`["langchain", "schema", "runnable"]`
"""
return ["langchain", "schema", "runnable"]
@property
@override
def InputType(self) -> type[Input]:
return self.default.InputType
@property
@override
def OutputType(self) -> type[Output]:
return self.default.OutputType
@override
def get_input_schema(self, config: RunnableConfig | None = None) -> type[BaseModel]:
runnable, config = self.prepare(config)
return runnable.get_input_schema(config)
@override
def get_output_schema(
self, config: RunnableConfig | None = None
) -> type[BaseModel]:
runnable, config = self.prepare(config)
return runnable.get_output_schema(config)
@override
def get_graph(self, config: RunnableConfig | None = None) -> Graph:
runnable, config = self.prepare(config)
return runnable.get_graph(config)
@override
def with_config(
self,
config: RunnableConfig | None = None,
# Sadly Unpack is not well supported by mypy so this will have to be untyped
**kwargs: Any,
) -> Runnable[Input, Output]:
return self.__class__(
**{**self.__dict__, "config": ensure_config(merge_configs(config, kwargs))} # type: ignore[arg-type]
)
def prepare(
self, config: RunnableConfig | None = None
) -> tuple[Runnable[Input, Output], RunnableConfig]:
"""Prepare the `Runnable` for invocation.
Args:
config: The configuration to use.
Returns:
The prepared `Runnable` and configuration.
Extends
Source
Frequently Asked Questions
What is the DynamicRunnable class?
DynamicRunnable is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/configurable.py.
Where is DynamicRunnable defined?
DynamicRunnable is defined in libs/core/langchain_core/runnables/configurable.py at line 49.
What does DynamicRunnable extend?
DynamicRunnable extends DynamicRunnable.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free