naman1102 commited on
Commit
847c986
·
1 Parent(s): ccf10a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -151,6 +151,17 @@ def inspect_node(state: AgentState) -> AgentState:
151
  • Return {"final_answer": "<final>"} if done, OR
152
  • Return exactly one tool key to run next (wiki_query / web_search_query / ocr_path / excel_path & excel_sheet_name / audio_path).
153
  """
 
 
 
 
 
 
 
 
 
 
 
154
  messages_for_llm = []
155
 
156
  # 1) Re‐insert original user question
 
151
  • Return {"final_answer": "<final>"} if done, OR
152
  • Return exactly one tool key to run next (wiki_query / web_search_query / ocr_path / excel_path & excel_sheet_name / audio_path).
153
  """
154
+ # 0) If we've already called tools too many times, force a final answer:
155
+ if state.get("tool_counter", 0) >= 5:
156
+ # Preserve the last messages and finalize with the INTERIM_ANSWER
157
+ return {
158
+ "messages": state["messages"],
159
+ "final_answer": state.get("final_answer", "ERROR: no interim_answer to finalize.")
160
+ }
161
+
162
+
163
+
164
+
165
  messages_for_llm = []
166
 
167
  # 1) Re‐insert original user question