ShadowGard3n commited on
Commit
8a15edf
·
1 Parent(s): 11fbcc9

Agent bug

Browse files
Files changed (2) hide show
  1. agent/ALL_node.py +4 -0
  2. routes/chat.py +37 -7
agent/ALL_node.py CHANGED
@@ -43,6 +43,7 @@ def user_node(state:MYSTATE):
43
 
44
  if_image = bool(image_path)
45
  d=[{"query": query, "if_image": if_image, "image_path": image_path}]
 
46
  return {"user":d}
47
 
48
 
@@ -77,6 +78,7 @@ def coordinator_node(state:MYSTATE):
77
  "user_input": state["user"][0]["query"],
78
  "image_status": imagestatus
79
  })
 
80
  return {"coordinator":[coordinator_output]}
81
 
82
 
@@ -121,6 +123,7 @@ def router_node(state: MYSTATE):
121
  short_term_output=short_term_checking(state,False)
122
 
123
  router_output["short_term_memory"] = short_term_output
 
124
  return {"router":[router_output]}
125
 
126
 
@@ -182,6 +185,7 @@ def main_llm_node(state:MYSTATE):
182
  main_history_dict = retrieve_dict("main_history")
183
  main_history_dict[str(change_index)]["llm_remark"] = main_llm_output
184
  save_dict("main_history", main_history_dict)
 
185
 
186
  return {"main_llm":[main_llm_output]}
187
 
 
43
 
44
  if_image = bool(image_path)
45
  d=[{"query": query, "if_image": if_image, "image_path": image_path}]
46
+ print({"user":d})
47
  return {"user":d}
48
 
49
 
 
78
  "user_input": state["user"][0]["query"],
79
  "image_status": imagestatus
80
  })
81
+ print({"coordinator":[coordinator_output]})
82
  return {"coordinator":[coordinator_output]}
83
 
84
 
 
123
  short_term_output=short_term_checking(state,False)
124
 
125
  router_output["short_term_memory"] = short_term_output
126
+ print(router_output)
127
  return {"router":[router_output]}
128
 
129
 
 
185
  main_history_dict = retrieve_dict("main_history")
186
  main_history_dict[str(change_index)]["llm_remark"] = main_llm_output
187
  save_dict("main_history", main_history_dict)
188
+ print(main_llm_output)
189
 
190
  return {"main_llm":[main_llm_output]}
191
 
routes/chat.py CHANGED
@@ -40,13 +40,43 @@ async def chat_with_agent(
40
  # Clean up the temporary image file
41
  if image_path and os.path.exists(image_path):
42
  os.remove(image_path)
 
 
 
 
 
 
43
 
44
- # Extract the final JSON response from the main_llm node
45
- final_response_str = result.get("main_llm", ["{}"])[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- try:
48
- final_response = json.loads(final_response_str)
49
- except json.JSONDecodeError:
50
- final_response = {"message_to_user": final_response_str, "navigate_to": None}
51
 
52
- return final_response
 
40
  # Clean up the temporary image file
41
  if image_path and os.path.exists(image_path):
42
  os.remove(image_path)
43
+
44
+ # --- FIX STARTS HERE ---
45
+
46
+ # 1. Check if the graph ended early (Coordinator decided to reply directly to user)
47
+ if result.get("coordinator") and result["coordinator"][0].get("return_to") == "user":
48
+ coordinator_data = result["coordinator"][0]
49
 
50
+ # Extract the direct message from the coordinator
51
+ final_response = {
52
+ "message_to_user": coordinator_data.get("message", {}).get("message_user", ""),
53
+ "llm_remarks": coordinator_data.get("llm_remarks", "Responded directly from coordinator."),
54
+ "navigate_to": None
55
+ }
56
+
57
+ # 2. Otherwise, the graph went all the way to the end (main_llm)
58
+ else:
59
+ final_response_str = result.get("main_llm", ["{}"])[0]
60
+ try:
61
+ final_response = json.loads(final_response_str)
62
+ except json.JSONDecodeError:
63
+ # Fallback if the LLM output isn't perfect JSON
64
+ final_response = {
65
+ "message_to_user": final_response_str,
66
+ "llm_remarks": "JSON parse failed",
67
+ "navigate_to": None
68
+ }
69
+
70
+ # --- FIX ENDS HERE ---
71
+
72
+ return final_response
73
+
74
+ # # Extract the final JSON response from the main_llm node
75
+ # final_response_str = result.get("main_llm", ["{}"])[0]
76
 
77
+ # try:
78
+ # final_response = json.loads(final_response_str)
79
+ # except json.JSONDecodeError:
80
+ # final_response = {"message_to_user": final_response_str, "navigate_to": None}
81
 
82
+ # return final_response