Skip to content

How to get the return value of multiple parallel nodes #1403

Answered by vbarda
cyberelf asked this question in Q&A
Discussion options

You must be logged in to vote

@cyberelf actually, you can do this:

from typing import TypedDict, Annotated

from langgraph.graph.state import StateGraph, START, END
from langgraph.channels.topic import Topic

class Message(TypedDict):
    message: Annotated[str, Topic(str, accumulate=False)]

def answer_node1(state: Message):
    print("---Answer Node 1---")
    print(state.get("message"))
    return {"message": "node1"}

def answer_node2(message: Message):
    print("---Answer Node 2---")
    print(message.get("message"))
    return {"message": "node2"}

def answer_node3(message: Message):
    print("---Answer Node 3---")
    print(message.get("message"))
    return {"message": "node3"}

def answer_node4(message: Mes…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@cyberelf
Comment options

@vbarda
Comment options

@cyberelf
Comment options

@vbarda
Comment options

Answer selected by cyberelf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants