alisamak commited on
Commit
0a3b4fb
Β·
verified Β·
1 Parent(s): 6cb286c

Update LG_agent.py

Browse files
Files changed (1) hide show
  1. LG_agent.py +32 -32
LG_agent.py CHANGED
@@ -76,37 +76,37 @@ def build_graph(max_steps: int = 5):
76
  graph = builder.compile()
77
 
78
  def limited_invoke(state, max_steps: int = 5, max_reasoning_steps_after_tool: int = 2):
79
- steps = 0
80
- reasoning_steps_since_last_tool = 0
81
-
82
- while steps < max_steps:
83
- print(f"\U0001f501 Step {steps + 1}")
84
- state = graph.invoke(state)
85
-
86
- for msg in state["messages"]:
87
- if isinstance(msg, AIMessage):
88
- print("\nπŸ€– Assistant says:")
89
- print("-" * 40)
90
- print(msg.content.strip())
91
- print("-" * 40)
92
-
93
- latest_message = state["messages"][-1] if state["messages"] else None
94
-
95
- if isinstance(latest_message, AIMessage):
96
- if latest_message.tool_calls:
97
- print("πŸ”„ Tool call detected β€” continuing loop.")
98
- reasoning_steps_since_last_tool = 0 # reset counter
99
- else:
100
- reasoning_steps_since_last_tool += 1
101
- print(f"🧠 No tool call β€” reasoning step #{reasoning_steps_since_last_tool}")
102
-
103
- if reasoning_steps_since_last_tool >= max_reasoning_steps_after_tool:
104
- print("βœ… Final answer assumed after sufficient reasoning.")
105
- break
106
-
107
- steps += 1
108
-
109
- return state
110
 
111
  # def limited_invoke(state):
112
  # steps = 0
@@ -132,7 +132,7 @@ def build_graph(max_steps: int = 5):
132
  # steps += 1
133
  # return state
134
 
135
- # return limited_invoke
136
 
137
  # 5. BasicAgent class
138
 
 
76
  graph = builder.compile()
77
 
78
  def limited_invoke(state, max_steps: int = 5, max_reasoning_steps_after_tool: int = 2):
79
+ steps = 0
80
+ reasoning_steps_since_last_tool = 0
81
+
82
+ while steps < max_steps:
83
+ print(f"\U0001f501 Step {steps + 1}")
84
+ state = graph.invoke(state)
85
+
86
+ for msg in state["messages"]:
87
+ if isinstance(msg, AIMessage):
88
+ print("\nπŸ€– Assistant says:")
89
+ print("-" * 40)
90
+ print(msg.content.strip())
91
+ print("-" * 40)
92
+
93
+ latest_message = state["messages"][-1] if state["messages"] else None
94
+
95
+ if isinstance(latest_message, AIMessage):
96
+ if latest_message.tool_calls:
97
+ print("πŸ”„ Tool call detected β€” continuing loop.")
98
+ reasoning_steps_since_last_tool = 0 # reset counter
99
+ else:
100
+ reasoning_steps_since_last_tool += 1
101
+ print(f"🧠 No tool call β€” reasoning step #{reasoning_steps_since_last_tool}")
102
+
103
+ if reasoning_steps_since_last_tool >= max_reasoning_steps_after_tool:
104
+ print("βœ… Final answer assumed after sufficient reasoning.")
105
+ break
106
+
107
+ steps += 1
108
+
109
+ return state
110
 
111
  # def limited_invoke(state):
112
  # steps = 0
 
132
  # steps += 1
133
  # return state
134
 
135
+ return limited_invoke
136
 
137
  # 5. BasicAgent class
138