Zeggai Abdellah commited on
Commit
eca53f4
·
1 Parent(s): 9e56f1b

update tools discription

Browse files
Files changed (2) hide show
  1. prepare_env.py +119 -223
  2. rag_pipeline.py +2 -2
prepare_env.py CHANGED
@@ -269,13 +269,15 @@ def section_tool_wrapper(retriever, section_path_chunks, query):
269
  return f"Error retrieving documents: {str(e)}"
270
 
271
  def create_section_tools(embedding_function, llm):
272
- """Create all section-specific retrieval tools"""
273
- print("🛠️ Creating section-specific retrieval tools...")
274
-
 
 
275
  # Define section paths - Fixed path structure
276
  section_paths = {
277
  'one': './data/section_one_chunks.json',
278
- 'two': './data/section_two_chunks.json',
279
  'three': './data/section_three_chunks.json',
280
  'four': './data/section_four_chunks.json',
281
  'five': './data/section_five_chunks.json',
@@ -285,7 +287,7 @@ def create_section_tools(embedding_function, llm):
285
  'nine': './data/section_nine_chunks.json',
286
  'ten': './data/section_ten_chunks.json'
287
  }
288
-
289
  # Create retrievers for each section
290
  section_retrievers = {}
291
  for section, path in section_paths.items():
@@ -301,7 +303,7 @@ def create_section_tools(embedding_function, llm):
301
  except Exception as e:
302
  print(f"❌ Error creating retriever for section {section}: {e}")
303
  section_retrievers[section] = None
304
-
305
  # Create main guide retriever
306
  guide_path = './data/Guide-pratique-de-mise-en-oeuvre-du-calendrier-national-de-vaccination-2023.json'
307
  guide_retriever = None
@@ -334,77 +336,48 @@ def create_section_tools(embedding_function, llm):
334
  except Exception as e:
335
  print(f"❌ Error creating immunization retriever: {e}")
336
 
337
- # General-purpose tool (entire Algerian guide)
338
- def guide_retrieval_tool(query: str) -> str:
 
339
  """
340
- General-purpose retrieval tool that searches across the entire Algerian National Vaccination Guide (2023).
341
- This tool is used to handle broad or ambiguous queries that may span multiple sections, or when no specific
342
- section tool is confidently matched.
343
-
344
- It can respond to questions covering all major topics in the guide, including:
345
- - The national vaccination program (PEV)
346
- - Targeted vaccine-preventable diseases
347
- - Vaccine types and administration methods
348
- - Catch-up vaccination schedules
349
- - Vaccination of special populations (e.g., premature, immunocompromised)
350
- - Cold chain logistics and storage protocols
351
- - Injection safety practices
352
- - Session planning and vaccine stock management
353
- - Community mobilization and vaccine hesitancy
354
- - Operational workflows and vaccinovigilance procedures
355
-
356
- This tool provides coverage across Sections 1 to 10 and complements the section-specific tools.
357
- It is especially useful when:
358
- - A question involves content from multiple sections
359
- - Tool routing is uncertain or ambiguous
360
- - A complete or exploratory answer is needed from the full document
361
 
362
  Args:
363
- query (str): A question related to any topic within the Algerian National Vaccination Guide.
364
 
365
  Returns:
366
- str: A synthesized response generated from relevant content retrieved across all sections.
367
  """
368
- print(f"🏥 GUIDE TOOL CALLED: {query[:50]}...")
369
  if not guide_retriever:
370
- print("❌ Guide retriever not available - main guide file may be missing")
371
  return "Guide retriever not available - main guide file may be missing"
372
- try:
373
- return section_tool_wrapper(guide_retriever, guide_path, query)
374
- except Exception as e:
375
- print(f"❌ Error accessing guide retriever: {str(e)}")
376
- return f"Error accessing guide retriever: {str(e)}"
377
 
378
- def immunization_tool(query: str) -> str:
379
  """
380
- A comprehensive tool for querying global immunization practices, based on the 2015 WHO 'Immunization in Practice: A Practical Guide for Health Staff'. This tool provides detailed information on vaccine-preventable diseases (e.g., diphtheria, measles, polio, hepatitis B, Hib), vaccination schedules, cold chain management, safe injection practices, microplanning, immunization session management, monitoring, surveillance, and community engagement strategies. It is ideal for questions about global immunization programs, disease prevention, vaccine administration, and operational guidelines for health workers, with a focus on practical implementation at health facility and sub-national levels
381
-
 
382
 
383
  Args:
384
- query (str): A question seeking global immunization practices.
385
 
386
  Returns:
387
  str: Content from the WHO Immunization in Practice guide.
388
  """
389
  print(f"🌍 WHO TOOL CALLED: {query[:50]}...")
390
  if not immunization_retriever:
391
- print("❌ Immunization in Practice retriever not available - WHO guide file may be missing")
392
  return "Immunization in Practice retriever not available - WHO guide file may be missing"
393
- try:
394
- return section_tool_wrapper(immunization_retriever, immunization_path, query)
395
- except Exception as e:
396
- print(f"❌ Error accessing immunization retriever: {str(e)}")
397
- return f"Error accessing immunization retriever: {str(e)}"
398
 
399
- # Section-Specific Tools - Fixed implementation
400
- def section_one_tool(query: str) -> str:
401
  """
402
- Section 1: Programme Élargi de Vaccination (PEV) from the Algerian National Vaccination Guide
403
-
404
- Use for queries about the national immunization program structure: its objectives,
405
- history, evaluation, and rationale for updates to the Algerian calendar.
406
-
407
- Do NOT use for vaccine schedules, disease information, or administration techniques.
408
 
409
  Args:
410
  query (str): A question about the foundation or evolution of the PEV.
@@ -412,24 +385,16 @@ def create_section_tools(embedding_function, llm):
412
  Returns:
413
  str: Response from Section 1.
414
  """
415
- print(f"📋 SECTION 1 TOOL CALLED: {query[:50]}...")
416
  if not section_retrievers.get('one'):
417
- print("Section 1 retriever not available - file may be missing")
418
- return "Section 1 retriever not available - file may be missing"
419
- try:
420
- return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
421
- except Exception as e:
422
- print(f"❌ Error accessing section 1: {str(e)}")
423
- return f"Error accessing section 1: {str(e)}"
424
 
425
- def section_two_tool(query: str) -> str:
426
  """
427
- Section 2: Maladies Ciblées from the Algerian National Vaccination Guide
428
-
429
- Use ONLY for questions about the characteristics of vaccine-preventable diseases:
430
- symptoms, transmission, complications, and prevention.
431
-
432
- Do NOT use for questions about vaccines, administration schedules, or procedures.
433
 
434
  Args:
435
  query (str): A question about a disease covered by the national vaccination program.
@@ -437,99 +402,67 @@ def create_section_tools(embedding_function, llm):
437
  Returns:
438
  str: Disease-specific content from Section 2.
439
  """
440
- print(f"🦠 SECTION 2 TOOL CALLED: {query[:50]}...")
441
  if not section_retrievers.get('two'):
442
- print("Section 2 retriever not available - file may be missing")
443
- return "Section 2 retriever not available - file may be missing"
444
- try:
445
- return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
446
- except Exception as e:
447
- print(f"❌ Error accessing section 2: {str(e)}")
448
- return f"Error accessing section 2: {str(e)}"
449
 
450
- def section_three_tool(query: str) -> str:
451
  """
452
- Section 3: Vaccins du Calendrier from the Algerian National Vaccination Guide
453
-
454
- Use ONLY for questions about the vaccines themselves: their types, compositions,
455
- methods of administration, and how they work.
456
-
457
- Do NOT use for schedule timing, catch-up protocols, or disease information.
458
 
459
  Args:
460
- query (str): A question about a vaccine's formulation or method of delivery.
461
 
462
  Returns:
463
- str: Vaccine info from Section 3.
464
  """
465
- print(f"💉 SECTION 3 TOOL CALLED: {query[:50]}...")
466
  if not section_retrievers.get('three'):
467
- print("Section 3 retriever not available - file may be missing")
468
- return "Section 3 retriever not available - file may be missing"
469
- try:
470
- return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
471
- except Exception as e:
472
- print(f"❌ Error accessing section 3: {str(e)}")
473
- return f"Error accessing section 3: {str(e)}"
474
 
475
- def section_four_tool(query: str) -> str:
476
  """
477
- Section 4: Rattrapage Vaccinal from the Algerian National Vaccination Guide
478
-
479
- Use ONLY when the question involves missed or delayed vaccinations and how to reschedule them
480
- based on the child's current age.
481
-
482
- Do NOT use for standard schedules (on-time), vaccine properties, or cold chain issues.
483
 
484
  Args:
485
- query (str): A question about catch-up vaccination based on delay or omission.
486
 
487
  Returns:
488
- str: Catch-up guidance from Section 4.
489
  """
490
- print(f"🔄 SECTION 4 TOOL CALLED: {query[:50]}...")
491
  if not section_retrievers.get('four'):
492
- print("Section 4 retriever not available - file may be missing")
493
- return "Section 4 retriever not available - file may be missing"
494
- try:
495
- return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
496
- except Exception as e:
497
- print(f"❌ Error accessing section 4: {str(e)}")
498
- return f"Error accessing section 4: {str(e)}"
499
 
500
- def section_five_tool(query: str) -> str:
501
  """
502
- Section 5: Populations Particulières from the Algerian National Vaccination Guide
503
-
504
- Use ONLY for vaccination questions concerning special populations:
505
- preterm infants, immunosuppressed patients, chronic illness, or allergy conditions.
506
-
507
- Do NOT use for general population, standard calendar, or vaccine preparation.
508
 
509
  Args:
510
- query (str): A question about tailored vaccination for vulnerable groups.
511
 
512
  Returns:
513
  str: Custom recommendations from Section 5.
514
  """
515
- print(f"👥 SECTION 5 TOOL CALLED: {query[:50]}...")
516
  if not section_retrievers.get('five'):
517
- print("Section 5 retriever not available - file may be missing")
518
- return "Section 5 retriever not available - file may be missing"
519
- try:
520
- return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
521
- except Exception as e:
522
- print(f"❌ Error accessing section 5: {str(e)}")
523
- return f"Error accessing section 5: {str(e)}"
524
 
525
- def section_six_tool(query: str) -> str:
526
  """
527
- Section 6: Chaîne du Froid from the Algerian National Vaccination Guide
528
-
529
- Use ONLY for questions about vaccine storage, transport, cold chain equipment,
530
- temperature monitoring, or cold chain failures.
531
-
532
- Do NOT use for dose timing, administration methods, or disease information.
533
 
534
  Args:
535
  query (str): A logistics-related question about vaccine temperature management.
@@ -537,99 +470,67 @@ def create_section_tools(embedding_function, llm):
537
  Returns:
538
  str: Cold chain instructions from Section 6.
539
  """
540
- print(f"❄️ SECTION 6 TOOL CALLED: {query[:50]}...")
541
  if not section_retrievers.get('six'):
542
- print("Section 6 retriever not available - file may be missing")
543
- return "Section 6 retriever not available - file may be missing"
544
- try:
545
- return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
546
- except Exception as e:
547
- print(f"❌ Error accessing section 6: {str(e)}")
548
- return f"Error accessing section 6: {str(e)}"
549
-
550
- def section_seven_tool(query: str) -> str:
551
- """
552
- Section 7: Sécurité des Injections from the Algerian National Vaccination Guide
553
-
554
- Use ONLY for questions related to the safe administration of vaccines:
555
- equipment use, technique, safety precautions, and waste disposal.
556
 
557
- Do NOT use for vaccine types, schedules, or cold chain issues.
 
 
 
 
558
 
559
  Args:
560
- query (str): A question about how to inject vaccines safely.
561
 
562
  Returns:
563
  str: Best practices from Section 7.
564
  """
565
- print(f"🛡️ SECTION 7 TOOL CALLED: {query[:50]}...")
566
  if not section_retrievers.get('seven'):
567
- print("Section 7 retriever not available - file may be missing")
568
- return "Section 7 retriever not available - file may be missing"
569
- try:
570
- return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
571
- except Exception as e:
572
- print(f"❌ Error accessing section 7: {str(e)}")
573
- return f"Error accessing section 7: {str(e)}"
574
 
575
- def section_eight_tool(query: str) -> str:
576
  """
577
- Section 8: Séance de Vaccination & Vaccinovigilance from the Algerian National Vaccination Guide
578
-
579
- Use ONLY for questions about running a vaccination session, preparing the setting,
580
- recording injections, and monitoring for adverse events (AEFI).
581
-
582
- Do NOT use for disease, vaccine, or scheduling details.
583
 
584
  Args:
585
- query (str): A question about operational conduct during vaccination.
586
 
587
  Returns:
588
  str: Workflow and safety monitoring details from Section 8.
589
  """
590
- print(f"📊 SECTION 8 TOOL CALLED: {query[:50]}...")
591
  if not section_retrievers.get('eight'):
592
- print("Section 8 retriever not available - file may be missing")
593
- return "Section 8 retriever not available - file may be missing"
594
- try:
595
- return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
596
- except Exception as e:
597
- print(f"❌ Error accessing section 8: {str(e)}")
598
- return f"Error accessing section 8: {str(e)}"
599
 
600
- def section_nine_tool(query: str) -> str:
601
  """
602
- Section 9: Planification des Séances de Vaccination from the Algerian National Vaccination Guide
603
-
604
- Use ONLY for planning and logistics questions: session scheduling, stock estimation,
605
- and operational preparation at the facility level.
606
-
607
- Do NOT use for vaccine info, schedules, or injection techniques.
608
 
609
  Args:
610
- query (str): A question about how to plan or organize vaccination services.
611
 
612
  Returns:
613
  str: Planning and stock guidance from Section 9.
614
  """
615
- print(f"📅 SECTION 9 TOOL CALLED: {query[:50]}...")
616
  if not section_retrievers.get('nine'):
617
- print("Section 9 retriever not available - file may be missing")
618
- return "Section 9 retriever not available - file may be missing"
619
- try:
620
- return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
621
- except Exception as e:
622
- print(f"❌ Error accessing section 9: {str(e)}")
623
- return f"Error accessing section 9: {str(e)}"
624
 
625
- def section_ten_tool(query: str) -> str:
626
  """
627
- Section 10: Mobilisation Sociale from the Algerian National Vaccination Guide
628
-
629
- Use ONLY for questions about communication strategies, overcoming vaccine hesitancy,
630
- rumor management, or community outreach.
631
-
632
- Do NOT use for medical, logistical, or procedural topics.
633
 
634
  Args:
635
  query (str): A question about public engagement or communication for vaccination.
@@ -637,34 +538,29 @@ def create_section_tools(embedding_function, llm):
637
  Returns:
638
  str: Public mobilization strategies from Section 10.
639
  """
640
- print(f"📢 SECTION 10 TOOL CALLED: {query[:50]}...")
641
  if not section_retrievers.get('ten'):
642
- print("Section 10 retriever not available - file may be missing")
643
- return "Section 10 retriever not available - file may be missing"
644
- try:
645
- return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
646
- except Exception as e:
647
- print(f"❌ Error accessing section 10: {str(e)}")
648
- return f"Error accessing section 10: {str(e)}"
649
 
650
- # Create FunctionTool objects
651
  tools = [
652
- FunctionTool.from_defaults(name="Guide_vector_tool", fn=guide_retrieval_tool),
653
- FunctionTool.from_defaults(name="Immunization_in_Practice_tool", fn=immunization_tool),
654
  # Section-specific tools
655
- FunctionTool.from_defaults(name="section_one_vector_query_tool", fn=section_one_tool),
656
- FunctionTool.from_defaults(name="section_two_vector_query_tool", fn=section_two_tool),
657
- FunctionTool.from_defaults(name="section_three_vector_query_tool", fn=section_three_tool),
658
- FunctionTool.from_defaults(name="section_four_vector_query_tool", fn=section_four_tool),
659
- FunctionTool.from_defaults(name="section_five_vector_query_tool", fn=section_five_tool),
660
- FunctionTool.from_defaults(name="section_six_vector_query_tool", fn=section_six_tool),
661
- FunctionTool.from_defaults(name="section_seven_vector_query_tool", fn=section_seven_tool),
662
- FunctionTool.from_defaults(name="section_eight_vector_query_tool", fn=section_eight_tool),
663
- FunctionTool.from_defaults(name="section_nine_vector_query_tool", fn=section_nine_tool),
664
- FunctionTool.from_defaults(name="section_ten_vector_query_tool", fn=section_ten_tool),
665
  ]
666
-
667
- print(f"✅ Created {len(tools)} section tools")
668
  return tools
669
 
670
  def prepare_environment():
 
269
  return f"Error retrieving documents: {str(e)}"
270
 
271
  def create_section_tools(embedding_function, llm):
272
+ """
273
+ Create all section-specific retrieval tools with improved descriptions for accurate routing.
274
+ """
275
+ print("🛠️ Creating section-specific retrieval tools with enhanced descriptions...")
276
+
277
  # Define section paths - Fixed path structure
278
  section_paths = {
279
  'one': './data/section_one_chunks.json',
280
+ 'two': './data/section_two_chunks.json',
281
  'three': './data/section_three_chunks.json',
282
  'four': './data/section_four_chunks.json',
283
  'five': './data/section_five_chunks.json',
 
287
  'nine': './data/section_nine_chunks.json',
288
  'ten': './data/section_ten_chunks.json'
289
  }
290
+
291
  # Create retrievers for each section
292
  section_retrievers = {}
293
  for section, path in section_paths.items():
 
303
  except Exception as e:
304
  print(f"❌ Error creating retriever for section {section}: {e}")
305
  section_retrievers[section] = None
306
+
307
  # Create main guide retriever
308
  guide_path = './data/Guide-pratique-de-mise-en-oeuvre-du-calendrier-national-de-vaccination-2023.json'
309
  guide_retriever = None
 
336
  except Exception as e:
337
  print(f"❌ Error creating immunization retriever: {e}")
338
 
339
+ # --- Tool Definitions with Improved Descriptions ---
340
+
341
+ def general_guide_tool(query: str) -> str:
342
  """
343
+ A general-purpose tool for the Algerian National Vaccination Guide.
344
+ **Use this tool as a fallback** if no other specific tool seems appropriate, or for very broad, multi-topic questions
345
+ (e.g., 'Summarize the Algerian vaccination policy and its safety measures').
346
+ **Always prefer a more specific tool if the query matches its description** (e.g., use 'cold_chain_tool' for temperature questions).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
 
348
  Args:
349
+ query (str): A broad or ambiguous question about the Algerian National Vaccination Guide.
350
 
351
  Returns:
352
+ str: Content retrieved from the entire guide.
353
  """
354
+ print(f"🏥 GENERAL GUIDE TOOL CALLED (FALLBACK): {query[:50]}...")
355
  if not guide_retriever:
 
356
  return "Guide retriever not available - main guide file may be missing"
357
+ return section_tool_wrapper(guide_retriever, guide_path, query)
 
 
 
 
358
 
359
+ def who_immunization_tool(query: str) -> str:
360
  """
361
+ Provides information from the WHO's 'Immunization in Practice' guide. Use this for questions about
362
+ **global immunization standards**, international best practices, or for comparing Algerian policy to
363
+ general WHO recommendations on topics like cold chain, safety, and disease control.
364
 
365
  Args:
366
+ query (str): A question seeking global or general immunization practices.
367
 
368
  Returns:
369
  str: Content from the WHO Immunization in Practice guide.
370
  """
371
  print(f"🌍 WHO TOOL CALLED: {query[:50]}...")
372
  if not immunization_retriever:
 
373
  return "Immunization in Practice retriever not available - WHO guide file may be missing"
374
+ return section_tool_wrapper(immunization_retriever, immunization_path, query)
 
 
 
 
375
 
376
+ def program_overview_tool(query: str) -> str:
 
377
  """
378
+ (Section 1) The primary tool for questions about the **history, objectives, and structure** of Algeria's
379
+ national immunization program (PEV - Programme Élargi de Vaccination). Use this for topics like
380
+ the program's rationale, key achievements, and the reasons for updates to the vaccination calendar.
 
 
 
381
 
382
  Args:
383
  query (str): A question about the foundation or evolution of the PEV.
 
385
  Returns:
386
  str: Response from Section 1.
387
  """
388
+ print(f"📋 PROGRAM OVERVIEW (S1) TOOL CALLED: {query[:50]}...")
389
  if not section_retrievers.get('one'):
390
+ return "Section 1 retriever not available"
391
+ return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
 
 
 
 
 
392
 
393
+ def disease_info_tool(query: str) -> str:
394
  """
395
+ (Section 2) The definitive tool for information on **specific vaccine-preventable diseases**.
396
+ Use this to find details on **symptoms, transmission methods, complications**, and prevention
397
+ strategies for diseases like Diphtheria, Measles, Polio, Tetanus, etc.
 
 
 
398
 
399
  Args:
400
  query (str): A question about a disease covered by the national vaccination program.
 
402
  Returns:
403
  str: Disease-specific content from Section 2.
404
  """
405
+ print(f"🦠 DISEASE INFO (S2) TOOL CALLED: {query[:50]}...")
406
  if not section_retrievers.get('two'):
407
+ return "Section 2 retriever not available"
408
+ return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
 
 
 
 
 
409
 
410
+ def vaccine_properties_tool(query: str) -> str:
411
  """
412
+ (Section 3) The specific tool for questions about the **vaccines themselves**: their types (e.g., BCG, ROR,
413
+ DTCaVPI), composition, whether they are live or inactivated, and the correct **method of administration**
414
+ (e.g., intradermal, intramuscular, oral).
 
 
 
415
 
416
  Args:
417
+ query (str): A question about a vaccine's formulation or how it is administered.
418
 
419
  Returns:
420
+ str: Vaccine-specific info from Section 3.
421
  """
422
+ print(f"💉 VACCINE PROPERTIES (S3) TOOL CALLED: {query[:50]}...")
423
  if not section_retrievers.get('three'):
424
+ return "Section 3 retriever not available"
425
+ return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
 
 
 
 
 
426
 
427
+ def catch_up_vaccination_tool(query: str) -> str:
428
  """
429
+ (Section 4) Specialized tool for **missed or delayed vaccinations (rattrapage vaccinal)**.
430
+ Use this for questions about creating a **catch-up schedule** for a child who is behind
431
+ on their shots, based on their age and vaccination history.
 
 
 
432
 
433
  Args:
434
+ query (str): A question about catch-up vaccination due to a delay or missed dose.
435
 
436
  Returns:
437
+ str: Catch-up schedule guidance from Section 4.
438
  """
439
+ print(f"🔄 CATCH-UP (S4) TOOL CALLED: {query[:50]}...")
440
  if not section_retrievers.get('four'):
441
+ return "Section 4 retriever not available"
442
+ return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
 
 
 
 
 
443
 
444
+ def special_populations_tool(query: str) -> str:
445
  """
446
+ (Section 5) The designated tool for vaccination guidelines concerning **special populations**.
447
+ Use for questions about vaccinating preterm infants, allergic children, or patients with
448
+ immunosuppression, chronic illnesses (cardiac, pulmonary), or other specific health conditions.
 
 
 
449
 
450
  Args:
451
+ query (str): A question about tailored vaccination for a vulnerable or special group.
452
 
453
  Returns:
454
  str: Custom recommendations from Section 5.
455
  """
456
+ print(f"👥 SPECIAL POPULATIONS (S5) TOOL CALLED: {query[:50]}...")
457
  if not section_retrievers.get('five'):
458
+ return "Section 5 retriever not available"
459
+ return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
 
 
 
 
 
460
 
461
+ def cold_chain_tool(query: str) -> str:
462
  """
463
+ (Section 6) The definitive tool for all questions about the **cold chain**, including vaccine **storage
464
+ temperatures**, transport protocols, refrigerators, temperature monitoring (like PCV pastilles),
465
+ and procedures for handling cold chain failures or power outages.
 
 
 
466
 
467
  Args:
468
  query (str): A logistics-related question about vaccine temperature management.
 
470
  Returns:
471
  str: Cold chain instructions from Section 6.
472
  """
473
+ print(f"❄️ COLD CHAIN (S6) TOOL CALLED: {query[:50]}...")
474
  if not section_retrievers.get('six'):
475
+ return "Section 6 retriever not available"
476
+ return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
+ def injection_safety_tool(query: str) -> str:
479
+ """
480
+ (Section 7) The primary tool for questions related to the **safe administration of injections**.
481
+ Use for topics like sterile equipment, proper injection techniques, preventing needlestick injuries,
482
+ and safe disposal of medical waste (DASRI).
483
 
484
  Args:
485
+ query (str): A question about how to perform vaccine injections safely.
486
 
487
  Returns:
488
  str: Best practices from Section 7.
489
  """
490
+ print(f"🛡️ INJECTION SAFETY (S7) TOOL CALLED: {query[:50]}...")
491
  if not section_retrievers.get('seven'):
492
+ return "Section 7 retriever not available"
493
+ return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
 
 
 
 
 
494
 
495
+ def session_management_tool(query: str) -> str:
496
  """
497
+ (Section 8) Use this tool for questions about the **operational conduct of a vaccination session**
498
+ and **vaccinovigilance**. This includes preparing the session, material setup, registering vaccination
499
+ acts, and monitoring/reporting adverse events post-vaccination (MPVI).
 
 
 
500
 
501
  Args:
502
+ query (str): A question about running a vaccination session or post-vaccine monitoring.
503
 
504
  Returns:
505
  str: Workflow and safety monitoring details from Section 8.
506
  """
507
+ print(f"📊 SESSION MGMT (S8) TOOL CALLED: {query[:50]}...")
508
  if not section_retrievers.get('eight'):
509
+ return "Section 8 retriever not available"
510
+ return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
 
 
 
 
 
511
 
512
+ def planning_and_logistics_tool(query: str) -> str:
513
  """
514
+ (Section 9) This tool is for **planning vaccination sessions and managing logistics**. Use it for
515
+ questions about creating operational maps, estimating vaccine and supply needs, managing stock,
516
+ and reducing vaccine wastage.
 
 
 
517
 
518
  Args:
519
+ query (str): A question about organizing vaccination services or managing stock.
520
 
521
  Returns:
522
  str: Planning and stock guidance from Section 9.
523
  """
524
+ print(f"📅 PLANNING & LOGISTICS (S9) TOOL CALLED: {query[:50]}...")
525
  if not section_retrievers.get('nine'):
526
+ return "Section 9 retriever not available"
527
+ return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
 
 
 
 
 
528
 
529
+ def communication_tool(query: str) -> str:
530
  """
531
+ (Section 10) The specific tool for **social mobilization and communication**. Use this for
532
+ questions about communication strategies, addressing **vaccine hesitancy**, managing rumors,
533
+ and community outreach to promote vaccination.
 
 
 
534
 
535
  Args:
536
  query (str): A question about public engagement or communication for vaccination.
 
538
  Returns:
539
  str: Public mobilization strategies from Section 10.
540
  """
541
+ print(f"📢 COMMUNICATION (S10) TOOL CALLED: {query[:50]}...")
542
  if not section_retrievers.get('ten'):
543
+ return "Section 10 retriever not available"
544
+ return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
 
 
 
 
 
545
 
546
+ # Create FunctionTool objects with new, clearer names
547
  tools = [
548
+ FunctionTool.from_defaults(name="general_guide_tool", fn=general_guide_tool),
549
+ FunctionTool.from_defaults(name="who_immunization_tool", fn=who_immunization_tool),
550
  # Section-specific tools
551
+ FunctionTool.from_defaults(name="program_overview_tool", fn=program_overview_tool),
552
+ FunctionTool.from_defaults(name="disease_info_tool", fn=disease_info_tool),
553
+ FunctionTool.from_defaults(name="vaccine_properties_tool", fn=vaccine_properties_tool),
554
+ FunctionTool.from_defaults(name="catch_up_vaccination_tool", fn=catch_up_vaccination_tool),
555
+ FunctionTool.from_defaults(name="special_populations_tool", fn=special_populations_tool),
556
+ FunctionTool.from_defaults(name="cold_chain_tool", fn=cold_chain_tool),
557
+ FunctionTool.from_defaults(name="injection_safety_tool", fn=injection_safety_tool),
558
+ FunctionTool.from_defaults(name="session_management_tool", fn=session_management_tool),
559
+ FunctionTool.from_defaults(name="planning_and_logistics_tool", fn=planning_and_logistics_tool),
560
+ FunctionTool.from_defaults(name="communication_tool", fn=communication_tool),
561
  ]
562
+
563
+ print(f"✅ Created {len(tools)} tools with improved routing descriptions")
564
  return tools
565
 
566
  def prepare_environment():
rag_pipeline.py CHANGED
@@ -122,7 +122,7 @@ You provide evidence-based guidance using only information from official vaccine
122
  Answer the doctor's question accurately and concisely using only the provided information.
123
 
124
  ## FALLBACK MODE INSTRUCTIONS
125
- - You have access to only 2 powerful tools: Guide_vector_tool (Algerian National Vaccination Guide) and Immunization_in_Practice_tool (WHO global guidance).
126
  - **MANDATORY TOOL USAGE**: Always use the relevant tool(s) to search for information before answering, even if you initially think no information is available.
127
  - Be direct and efficient - search once with each tool if needed, then provide your answer.
128
  - Do not overthink or search repeatedly - these tools are comprehensive.
@@ -237,7 +237,7 @@ def create_fallback_tools(all_tools):
237
 
238
  for tool in all_tools:
239
  tool_name = tool.metadata.name if hasattr(tool, 'metadata') else str(tool)
240
- if tool_name in ["Guide_vector_tool", "Immunization_in_Practice_tool"]:
241
  fallback_tools.append(tool)
242
  tool_names_found.append(tool_name)
243
 
 
122
  Answer the doctor's question accurately and concisely using only the provided information.
123
 
124
  ## FALLBACK MODE INSTRUCTIONS
125
+ - You have access to only 2 powerful tools: general_guide_tool (Algerian National Vaccination Guide) and who_immunization_tool (WHO global guidance).
126
  - **MANDATORY TOOL USAGE**: Always use the relevant tool(s) to search for information before answering, even if you initially think no information is available.
127
  - Be direct and efficient - search once with each tool if needed, then provide your answer.
128
  - Do not overthink or search repeatedly - these tools are comprehensive.
 
237
 
238
  for tool in all_tools:
239
  tool_name = tool.metadata.name if hasattr(tool, 'metadata') else str(tool)
240
+ if tool_name in ["general_guide_tool", "who_immunization_tool"]:
241
  fallback_tools.append(tool)
242
  tool_names_found.append(tool_name)
243