wt002 commited on
Commit
02e0a0a
·
verified ·
1 Parent(s): 3f9a023

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -287,29 +287,37 @@ class BasicAgent:
287
  document_qa,
288
  python_execution
289
  ]
290
-
291
-
292
 
293
  def __call__(self, question: str) -> str:
294
  print(f"Agent received question: {question[:50]}{'...' if len(question) > 50 else ''}")
295
-
296
- # Ensure proper HumanMessage in history
297
- state = init_state(question)
298
-
 
 
 
 
 
 
299
  final_state = self.workflow.invoke(state)
300
-
301
  print(f"Final state keys: {list(final_state.keys())}")
302
  if 'history' in final_state:
303
  print(f"History length: {len(final_state['history'])}")
304
  for i, msg in enumerate(final_state['history']):
305
- print(f"Message {i}: {type(msg).__name__} - {msg.content[:100]}...")
306
-
307
- for msg in reversed(final_state['history']):
 
 
 
 
308
  if isinstance(msg, AIMessage) and "FINAL ANSWER:" in msg.content:
309
  answer = msg.content.split("FINAL ANSWER:")[1].strip()
310
  print(f"Agent returning answer: {answer}")
311
  return answer
312
-
313
  raise ValueError("No FINAL ANSWER found in agent history.")
314
 
315
 
 
287
  document_qa,
288
  python_execution
289
  ]
 
 
290
 
291
  def __call__(self, question: str) -> str:
292
  print(f"Agent received question: {question[:50]}{'...' if len(question) > 50 else ''}")
293
+
294
+ # Initialize state with proper structure
295
+ state = {
296
+ "question": question,
297
+ "context": {}, # Ensure it's a dict
298
+ "reasoning": "",
299
+ "iterations": 0,
300
+ "history": [HumanMessage(content=question)]
301
+ }
302
+
303
  final_state = self.workflow.invoke(state)
304
+
305
  print(f"Final state keys: {list(final_state.keys())}")
306
  if 'history' in final_state:
307
  print(f"History length: {len(final_state['history'])}")
308
  for i, msg in enumerate(final_state['history']):
309
+ if isinstance(msg, dict):
310
+ print(f"Message {i}: dict - {msg}")
311
+ else:
312
+ print(f"Message {i}: {type(msg).__name__} - {msg.content[:100]}...")
313
+
314
+ # Extract the FINAL ANSWER from history
315
+ for msg in reversed(final_state["history"]):
316
  if isinstance(msg, AIMessage) and "FINAL ANSWER:" in msg.content:
317
  answer = msg.content.split("FINAL ANSWER:")[1].strip()
318
  print(f"Agent returning answer: {answer}")
319
  return answer
320
+
321
  raise ValueError("No FINAL ANSWER found in agent history.")
322
 
323