manu commited on
Commit
834e79b
·
verified ·
1 Parent(s): 6785135

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -184,11 +184,14 @@ def _build_image_parts_from_indices(indices: List[int]) -> List[Dict[str, Any]]:
184
 
185
  SYSTEM = (
186
  """
187
- You are a PDF research agent.
 
 
 
 
 
188
 
189
  Workflow:
190
- • When you need pages, call the tool: mcp_test_search(query: string, k: int).
191
- • The app will attach the images for the LAST search result you produced in this turn in a follow-up message.
192
  • Use ONLY the provided images for grounding and cite as (p.<page>).
193
  • If an answer is not present, say “Not found in the provided pages.”
194
 
@@ -236,7 +239,7 @@ def stream_agent(question: str,
236
 
237
  # Optional seeding: attach some likely pages on round 1
238
  try:
239
- seed_indices = search(question, k=5) or []
240
  except Exception as e:
241
  yield f"❌ Search failed: {e}", "", ""
242
  return
@@ -337,7 +340,7 @@ def stream_agent(question: str,
337
 
338
  # Capture tool RESULT text and try to parse indices
339
  elif etype.startswith("response.tool_result"):
340
- print("here")
341
  delta_text = getattr(event, "delta", "") or getattr(event, "output_text", "")
342
  if delta_text:
343
  tool_result_buffer += str(delta_text)
@@ -368,7 +371,7 @@ def stream_agent(question: str,
368
  pending_indices = list(seed_indices)
369
 
370
  while round_idx <= max_rounds:
371
- print(round_idx, pending_indices)
372
  for final_md, summary_md, log_md in run_round(round_idx, pending_indices):
373
  yield final_md, summary_md, log_md
374
 
 
184
 
185
  SYSTEM = (
186
  """
187
+ You are a PDF research agent with a single tool: mcp_test_search(query: string, k: int).
188
+ Act iteratively:
189
+ 1) Split the user question into 1–4 focused sub-queries. Subqueries should be asked as natural language questions in the english language, not just keywords.
190
+ 2) For each sub-query, call mcp_test_search (k=5 by default; increase to up to 10 if you need to go deep).
191
+ 3) You will receive the output of mcp_test_search as a list of indices correspondinf to page numbers. Print them out and stop generating. You will be fed the corresponding pages as images in a follow-up message.
192
+ 3) Stop early when confident; otherwise refine and repeat, up to 4 iterations and 20 searches in total. If info is missing, try to continue searching using new keywords and queries.
193
 
194
  Workflow:
 
 
195
  • Use ONLY the provided images for grounding and cite as (p.<page>).
196
  • If an answer is not present, say “Not found in the provided pages.”
197
 
 
239
 
240
  # Optional seeding: attach some likely pages on round 1
241
  try:
242
+ seed_indices = [] # search(question, k=5) or []
243
  except Exception as e:
244
  yield f"❌ Search failed: {e}", "", ""
245
  return
 
340
 
341
  # Capture tool RESULT text and try to parse indices
342
  elif etype.startswith("response.tool_result"):
343
+ print("A tool output was detected")
344
  delta_text = getattr(event, "delta", "") or getattr(event, "output_text", "")
345
  if delta_text:
346
  tool_result_buffer += str(delta_text)
 
371
  pending_indices = list(seed_indices)
372
 
373
  while round_idx <= max_rounds:
374
+ print("Round ", round_idx, ", Indices: ", pending_indices)
375
  for final_md, summary_md, log_md in run_round(round_idx, pending_indices):
376
  yield final_md, summary_md, log_md
377