You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to devise a workflow where one of the agent node's job is to verify the user. In the examples that langchain provided the node returned directly to the supervisor but what i am trying to do is to return to the supervisor only if verified. My current code has unnecessary self loops and a deterministic edge to the verification node. It so happens because of how I defined my conditional edge. Ill attach my Supervisor and Graph builder code below and the architecture I am trying to achieve with this. Thank you
Code:
Supervisor.py
def supervisor_node(state: OverallState) -> Command[Literal["qa", "verification", "end"]]:
messages = [
{"role": "system", "content": system_prompt},
] + state["messages"]
response = llm.with_structured_output(Router).invoke(messages)
print(response)
goto = response["next"]
if goto == "FINISH":
goto = END
#Adding Edges
chatbot.add_edge("verification", "collect_info")
chatbot.add_edge("collect_info", "verify_information")
chatbot.add_conditional_edges("verify_information", verified, "supervisor" , "verification") # problem is with this line
graph = chatbot.compile()
graph.get_graph().draw_mermaid_png(output_file_path="graph.png")
Current Graph:
Graph I am trying to achieve:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to devise a workflow where one of the agent node's job is to verify the user. In the examples that langchain provided the node returned directly to the supervisor but what i am trying to do is to return to the supervisor only if verified. My current code has unnecessary self loops and a deterministic edge to the verification node. It so happens because of how I defined my conditional edge. Ill attach my Supervisor and Graph builder code below and the architecture I am trying to achieve with this. Thank you
Code:
Supervisor.py
def supervisor_node(state: OverallState) -> Command[Literal["qa", "verification", "end"]]:
messages = [
{"role": "system", "content": system_prompt},
] + state["messages"]
response = llm.with_structured_output(Router).invoke(messages)
print(response)
goto = response["next"]
if goto == "FINISH":
goto = END
chatbot = StateGraph(OverallState)
#Adding Nodes
chatbot.add_edge(START, "supervisor")
chatbot.add_node("supervisor", supervisor_node)
chatbot.add_node("qa",qa_node)
chatbot.add_node("verification", verification_assistant)
chatbot.add_node('collect_info', collect_info)
chatbot.add_node("verify_information",verify_information)
#Adding Edges
chatbot.add_edge("verification", "collect_info")
chatbot.add_edge("collect_info", "verify_information")
chatbot.add_conditional_edges("verify_information", verified, "supervisor" , "verification") # problem is with this line
graph = chatbot.compile()
![image](https://private-user-images.githubusercontent.com/111465623/412108814-d0b00640-96a2-48c6-9eaf-fca1ee87eba6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjkwMDIsIm5iZiI6MTczOTQ2ODcwMiwicGF0aCI6Ii8xMTE0NjU2MjMvNDEyMTA4ODE0LWQwYjAwNjQwLTk2YTItNDhjNi05ZWFmLWZjYTFlZTg3ZWJhNi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QxNzQ1MDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kNGNiODM1M2M0NzE4NzUzMzQ5NmFiYTI4N2RkODQ1MTk3ZmFhOWM3NGE0NjgyZDdhMzBjOTE3ZmQ1Yzk1YmYyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.JTGOvBeHfYLmnIrh3nT29YgE1oW5j4AkXBbYtSHszzA)
![WhatsApp Image 2025-02-11 at 13 16 54_d212fae2](https://private-user-images.githubusercontent.com/111465623/412110949-0823f7fb-22cf-43a9-bdae-0bcfb7c906c3.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjkwMDIsIm5iZiI6MTczOTQ2ODcwMiwicGF0aCI6Ii8xMTE0NjU2MjMvNDEyMTEwOTQ5LTA4MjNmN2ZiLTIyY2YtNDNhOS1iZGFlLTBiY2ZiN2M5MDZjMy5qcGc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QxNzQ1MDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kZGQyMDY2YzcyYzAwOWEwOWU1M2RkMGYwMWYzZmVkNGVlZWZmNDUyYTU2M2VjMjRjMzkwNjk2ZGJjMGYxNWJmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Hiq7WrlV3kbxzONPvERE3DdU3TLvPpVqzGBJPF0GdJM)
graph.get_graph().draw_mermaid_png(output_file_path="graph.png")
Current Graph:
Graph I am trying to achieve:
Beta Was this translation helpful? Give feedback.
All reactions