Spaces:
Runtime error
Runtime error
Update LG_agent.py
Browse files- LG_agent.py +15 -15
LG_agent.py
CHANGED
|
@@ -44,21 +44,21 @@ def build_graph(max_steps: int = 5):
|
|
| 44 |
graph = builder.compile()
|
| 45 |
|
| 46 |
def limited_invoke(state):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
return limited_invoke
|
| 64 |
|
|
|
|
| 44 |
graph = builder.compile()
|
| 45 |
|
| 46 |
def limited_invoke(state):
|
| 47 |
+
steps = 0
|
| 48 |
+
while steps < max_steps:
|
| 49 |
+
print(f"🔁 Step {steps + 1}")
|
| 50 |
+
state = graph.invoke(state)
|
| 51 |
+
latest_message = state["messages"][-1] if state["messages"] else None
|
| 52 |
+
|
| 53 |
+
# Print tool usage if any
|
| 54 |
+
for m in state["messages"]:
|
| 55 |
+
if hasattr(m, "tool_call_id"):
|
| 56 |
+
print(f"🔧 Tool Used: {m.tool_call_id} — {m.content}")
|
| 57 |
+
|
| 58 |
+
if latest_message and isinstance(latest_message, AIMessage):
|
| 59 |
+
break
|
| 60 |
+
steps += 1
|
| 61 |
+
return state
|
| 62 |
|
| 63 |
return limited_invoke
|
| 64 |
|