Multiple States, 1 Conditional Edge, but 2 Results... #2197
Replies: 1 comment 1 reply
-
Not sure if you found an answer in the past month, but returning dictionaries in a node will overwrite that field in the state. So, by returning if you are wanting to add these values to the state object, the correct syntax should be:
relevant question (see response): #1788 |
Beta Was this translation helpful? Give feedback.
-
Hi there!
I was learning how to work with graphs in LangGraph, and I stumbled across a perplexing issue while working with conditional edges.
Graph Summary
I have 3 nodes. The first node,
node_1
, is only connected tonode_2
, whilenode_2
is connected to bothnode_3
andEND
via a conditional edge.States Summary
I have 3 different states. Both
PersonState
andPurchasesState
has unique attributes (seen below). On the other hand,OverallState
combines the aforementioned states.The Issue
node_2
issues an update to the state, which is not reflected correctly in the routing function (that controls the conditional edge).Code
Code Output
The output line that I can't understand
How does
money
have a value of -100? In the methodpay_salary
, themoney
attribute is set to 1000. Then, in thesubtract_expenses
method, I subtract 100 from it. So, themoney
attribute should have a value of 900, not -100.The line that is causing the weird output (after debugging)
How is it causing the issue?
When I change the inputted state from
PurchasesState
toOverallState
, it works as expected, i.e. the output printed in the routing functioncheck_if_poor
is:What's my question?
Why does changing the type of the inputted state in the function
subtract_expenses
lead me to receive different values for themoney
attribute in the routing functioncheck_if_poor
?Thanks in advance!
P.S. Please don't mind how inefficient the graph setup is for the problem I'm trying to solve. I had simplified my original code a good bit of my code to make it easier to pinpoint what the issue was.
Beta Was this translation helpful? Give feedback.
All reactions