Spaces:
Runtime error
Runtime error
Update LG_agent.py
Browse files- LG_agent.py +10 -0
LG_agent.py
CHANGED
|
@@ -132,6 +132,16 @@ def build_graph(max_steps: int = 5):
|
|
| 132 |
else:
|
| 133 |
reasoning_steps_since_last_tool += 1
|
| 134 |
print(f"🧠 No tool call — reasoning step #{reasoning_steps_since_last_tool}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
if reasoning_steps_since_last_tool >= max_reasoning_steps_after_tool:
|
| 137 |
print("✅ Final answer assumed after sufficient reasoning.")
|
|
|
|
| 132 |
else:
|
| 133 |
reasoning_steps_since_last_tool += 1
|
| 134 |
print(f"🧠 No tool call — reasoning step #{reasoning_steps_since_last_tool}")
|
| 135 |
+
|
| 136 |
+
# 🛠️ Handle reverse_sentence manually
|
| 137 |
+
if "reverse_sentence" in latest_message.content.lower():
|
| 138 |
+
# Try to find the ToolMessage output
|
| 139 |
+
tool_outputs = [msg for msg in state["messages"] if msg.type == "tool"]
|
| 140 |
+
if tool_outputs:
|
| 141 |
+
reversed_text = tool_outputs[-1].content.strip()
|
| 142 |
+
print(f"🔁 Re-feeding reversed message:\n{reversed_text}")
|
| 143 |
+
state["messages"].append(HumanMessage(content=reversed_text))
|
| 144 |
+
continue # loop again with new input
|
| 145 |
|
| 146 |
if reasoning_steps_since_last_tool >= max_reasoning_steps_after_tool:
|
| 147 |
print("✅ Final answer assumed after sufficient reasoning.")
|