wt002 commited on
Commit
55ec576
·
verified ·
1 Parent(s): 3d99e57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -270,16 +270,29 @@ class BasicAgent:
270
 
271
 
272
  def __call__(self, question: str) -> str:
 
 
 
273
  state = init_state(question)
 
 
274
  final_state = self.workflow.invoke(state)
275
 
276
- # Extract final answer
 
 
 
 
 
 
 
277
  for msg in reversed(final_state['history']):
278
  if isinstance(msg, AIMessage) and "FINAL ANSWER:" in msg.content:
279
- return msg.content.split("FINAL ANSWER:")[1].strip()
280
-
281
- return "No final answer found"
282
-
 
283
 
284
 
285
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
270
 
271
 
272
  def __call__(self, question: str) -> str:
273
+ print(f"Agent received question: {question[:50]}{'...' if len(question) > 50 else ''}")
274
+
275
+ # Initialize state with the question
276
  state = init_state(question)
277
+
278
+ # Execute the workflow
279
  final_state = self.workflow.invoke(state)
280
 
281
+ # Debug: Print the final state structure
282
+ print(f"Final state keys: {list(final_state.keys())}")
283
+ if 'history' in final_state:
284
+ print(f"History length: {len(final_state['history'])}")
285
+ for i, msg in enumerate(final_state['history']):
286
+ print(f"Message {i}: {type(msg).__name__} - {msg.content[:100]}...")
287
+
288
+ # Extract final answer from history
289
  for msg in reversed(final_state['history']):
290
  if isinstance(msg, AIMessage) and "FINAL ANSWER:" in msg.content:
291
+ # Extract and clean the final answer
292
+ answer = msg.content.split("FINAL ANSWER:")[1].strip()
293
+ print(f"Agent returning answer: {answer}")
294
+ return answer
295
+
296
 
297
 
298
  def run_and_submit_all( profile: gr.OAuthProfile | None):