RunnableEach Class — langchain Architecture
Architecture documentation for the RunnableEach class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1139a370_9595_466c_68d2_71cd39407824["RunnableEach"] 5f3c1f1c_6f8a_e293_7cb5_97c21b4bf214["base.py"] 1139a370_9595_466c_68d2_71cd39407824 -->|defined in| 5f3c1f1c_6f8a_e293_7cb5_97c21b4bf214 df0597b4_dc67_1241_db66_5413675fb57c["get_name()"] 1139a370_9595_466c_68d2_71cd39407824 -->|method| df0597b4_dc67_1241_db66_5413675fb57c a8b9a6ee_20d7_5ed7_8ab2_00ad2373630c["bind()"] 1139a370_9595_466c_68d2_71cd39407824 -->|method| a8b9a6ee_20d7_5ed7_8ab2_00ad2373630c 6ed9020f_9c07_bc20_a2bb_22f1e9e47a32["with_config()"] 1139a370_9595_466c_68d2_71cd39407824 -->|method| 6ed9020f_9c07_bc20_a2bb_22f1e9e47a32 44cb970f_700c_28a3_fe67_6ab2de531255["with_listeners()"] 1139a370_9595_466c_68d2_71cd39407824 -->|method| 44cb970f_700c_28a3_fe67_6ab2de531255 04608465_b44d_96c2_8cfc_158837274475["with_alisteners()"] 1139a370_9595_466c_68d2_71cd39407824 -->|method| 04608465_b44d_96c2_8cfc_158837274475
Relationship Graph
Source Code
libs/core/langchain_core/runnables/base.py lines 5413–5527
class RunnableEach(RunnableEachBase[Input, Output]):
"""RunnableEach class.
`Runnable` that calls another `Runnable` for each element of the input sequence.
It allows you to call multiple inputs with the bounded `Runnable`.
`RunnableEach` makes it easy to run multiple inputs for the `Runnable`.
In the below example, we associate and run three inputs
with a `Runnable`:
```python
from langchain_core.runnables.base import RunnableEach
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
prompt = ChatPromptTemplate.from_template("Tell me a short joke about
{topic}")
model = ChatOpenAI()
output_parser = StrOutputParser()
runnable = prompt | model | output_parser
runnable_each = RunnableEach(bound=runnable)
output = runnable_each.invoke([{'topic':'Computer Science'},
{'topic':'Art'},
{'topic':'Biology'}])
print(output) # noqa: T201
```
"""
@override
def get_name(self, suffix: str | None = None, *, name: str | None = None) -> str:
name = name or self.name or f"RunnableEach<{self.bound.get_name()}>"
return super().get_name(suffix, name=name)
@override
def bind(self, **kwargs: Any) -> RunnableEach[Input, Output]:
return RunnableEach(bound=self.bound.bind(**kwargs))
@override
def with_config(
self, config: RunnableConfig | None = None, **kwargs: Any
) -> RunnableEach[Input, Output]:
return RunnableEach(bound=self.bound.with_config(config, **kwargs))
@override
def with_listeners(
self,
*,
on_start: Callable[[Run], None]
| Callable[[Run, RunnableConfig], None]
| None = None,
on_end: Callable[[Run], None]
| Callable[[Run, RunnableConfig], None]
| None = None,
on_error: Callable[[Run], None]
| Callable[[Run, RunnableConfig], None]
| None = None,
) -> RunnableEach[Input, Output]:
"""Bind lifecycle listeners to a `Runnable`, returning a new `Runnable`.
The `Run` object contains information about the run, including its `id`,
`type`, `input`, `output`, `error`, `start_time`, `end_time`, and
any tags or metadata added to the run.
Args:
on_start: Called before the `Runnable` starts running, with the `Run`
object.
on_end: Called after the `Runnable` finishes running, with the `Run`
object.
on_error: Called if the `Runnable` throws an error, with the `Run`
object.
Returns:
A new `Runnable` with the listeners bound.
"""
return RunnableEach(
bound=self.bound.with_listeners(
on_start=on_start, on_end=on_end, on_error=on_error
)
Defined In
Source
Frequently Asked Questions
What is the RunnableEach class?
RunnableEach is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/base.py.
Where is RunnableEach defined?
RunnableEach is defined in libs/core/langchain_core/runnables/base.py at line 5413.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free