-
I know that if my state has a property like this:
Then it means whenever my node returns:
it will append the values to the 'lines' property of my state. This is important and useful for branching, where more than 1 node may be writing to this property. But I want to ask if it is possible for a node to 'reset' this 'lines' property so it does not append but clearly rewrites it? We can assume that there can be only one such operation at any time. So
Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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"]}
Lots a flexibilities! :) |
Beta Was this translation helpful? Give feedback.
Good q! You can write your own reducer
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! :)