Replies: 3 comments
-
Yes, you can create a parallel edge in LangGraph to execute two independent nodes at the same time using the Here is an example of how to use from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableParallel
from langchain_openai import ChatOpenAI
model = ChatOpenAI()
joke_chain = ChatPromptTemplate.from_template("tell me a joke about {topic}") | model
poem_chain = ChatPromptTemplate.from_template("write a 2-line poem about {topic}") | model
map_chain = RunnableParallel(joke=joke_chain, poem=poem_chain)
map_chain.invoke({"topic": "bear"}) In this example, Additionally, LangGraph provides a more detailed structure for managing nodes and edges, including support for conditional edges and various node types. You can define nodes and edges using the
|
Beta Was this translation helpful? Give feedback.
-
Also interested :) Edit: Did this answer your question ? https://langchain-ai.github.io/langgraph/how-tos/branching/ |
Beta Was this translation helpful? Give feedback.
-
As of current langgraph documentation, there is no seperate parallel edge method. But langgraph does provide a way to call two independent nodes branching off from one node or two in some cases. To do that u can follow this
Also while doing something similar, the state should be edited as well to handle the state changes. For example if node_1 and node_2 both make changes to same attribute in graph state, then u must handle it (could be by appending the values from each node) properly so that the values don't override each other. If u have any other questions related to topic, I am open to discuss. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I'd like to have something like a parallel edge with two nodes. This would allow to execute the two nodes in parallel at the same time, without waiting one node to finish
System Info
langchain==0.1.13
langchain-chroma==0.1.0
langchain-cli==0.0.21
langchain-community==0.0.29
langchain-core==0.1.50
langchain-google-genai==0.0.9
langchain-google-vertexai==0.1.1
langchain-groq==0.1.3
langchain-mistralai==0.0.5
langchain-mongodb==0.1.1
langchain-openai==0.1.0
langchain-text-splitters==0.0.1
Beta Was this translation helpful? Give feedback.
All reactions