Skip to content
Discussion options

You must be logged in to vote

Good q! You can write your own reducer

def add_or_rewrite(existing, new):
    existing = existing or []
    if isinstance(new, dict) and new["kind"] == "rewrite":
        return new["value"]
    return existing + new

class State(TypedDict):
    lines: Annotated[List[str], add_or_rewrite]

...
 def regular_node(state):
     ....
    return {"lines": ["my name is john"]}
    
def rewriting_node(state):
    ....
    return {"lines": {"kind": "rewrite", "value": ["this is the wonderful wizard of oz"]}

operator.add only a function that adds a and b. Your function can either add a and b OR do something different depending on the value of b.

Lots a flexibilities! :)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ziqizhang
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