document query tool pausable

linuztx committed Oct 11, 2025 at 18:14 UTC 587b06ed33b1769c909147520b69b5f234082e9e
1 file changed +11
python/helpers/document_query.py
+11
@@ -364,12 +364,15 @@ class DocumentQueryHelper:
364 self, document_uri: str, questions: Sequence[str]
365 ) -> Tuple[bool, str]:
366 self.progress_callback(f"Starting Q&A process")
367 + await self.agent.handle_intervention()
368
369 # index document
370 _ = await self.document_get_content(document_uri, True)
371 + await self.agent.handle_intervention()
372 selected_chunks = {}
373 for question in questions:
374 self.progress_callback(f"Optimizing query: {question}")
375 + await self.agent.handle_intervention()
376 human_content = f'Search Query: "{question}"'
377 system_content = self.agent.parse_prompt(
378 "fw.document_query.optmimize_query.md"
@@ -381,6 +384,7 @@ class DocumentQueryHelper:
384 )
385 ).strip()
386
387 + await self.agent.handle_intervention()
388 self.progress_callback(f"Searching document with query: {optimized_query}")
389
390 normalized_uri = self.store.normalize_uri(document_uri)
@@ -404,6 +408,7 @@ class DocumentQueryHelper:
408 self.progress_callback(
409 f"Processing {len(questions)} questions in context of {len(selected_chunks)} chunks"
410 )
411 + await self.agent.handle_intervention()
412
413 questions_str = "\n".join([f" * {question}" for question in questions])
414 content = "\n\n----\n\n".join(
@@ -430,6 +435,7 @@ class DocumentQueryHelper:
435 self, document_uri: str, add_to_db: bool = False
436 ) -> str:
437 self.progress_callback(f"Fetching document content")
438 + await self.agent.handle_intervention()
439 url = urlparse(document_uri)
440 scheme = url.scheme or "file"
441 mimetype, encoding = mimetypes.guess_type(document_uri)
@@ -455,6 +461,7 @@ class DocumentQueryHelper:
461 await asyncio.sleep(1)
462 last_error = str(e)
463 retries += 1
464 + await self.agent.handle_intervention()
465
466 if not response:
467 raise ValueError(
@@ -492,9 +499,11 @@ class DocumentQueryHelper:
499 # Use the store's normalization method
500 document_uri_norm = self.store.normalize_uri(document_uri)
501
502 + await self.agent.handle_intervention()
503 exists = await self.store.document_exists(document_uri_norm)
504 document_content = ""
505 if not exists:
506 + await self.agent.handle_intervention()
507 if mimetype.startswith("image/"):
508 document_content = self.handle_image_document(document_uri, scheme)
509 elif mimetype == "text/html":
@@ -509,6 +518,7 @@ class DocumentQueryHelper:
518 )
519 if add_to_db:
520 self.progress_callback(f"Indexing document")
521 + await self.agent.handle_intervention()
522 success, ids = await self.store.add_document(
523 document_content, document_uri_norm
524 )
@@ -519,6 +529,7 @@ class DocumentQueryHelper:
529 )
530 self.progress_callback(f"Indexed {len(ids)} chunks")
531 else:
532 + await self.agent.handle_intervention()
533 doc = await self.store.get_document(document_uri_norm)
534 if doc:
535 document_content = doc.page_content