Zeggai Abdellah commited on
Commit
c06c6fb
·
1 Parent(s): 11ba922

update tool descrition to not overlaping

Browse files
Files changed (1) hide show
  1. prepare_env.py +92 -75
prepare_env.py CHANGED
@@ -225,98 +225,100 @@ def create_section_tools(embedding_function, llm):
225
  guide_retriever = create_retriever(guide_vstore, guide_docs, llm)
226
  else:
227
  guide_retriever = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  # General-purpose tool (entire Algerian guide)
229
  def guide_retrieval_tool(query: str) -> str:
230
  """
231
  General-purpose retrieval tool for the entire Algerian National Vaccination Guide (2023).
232
 
233
- Use this tool when a query spans multiple sections or cannot be routed confidently to a specific tool.
234
- This is the fallback and all-encompassing tool to retrieve any vaccination-related information
235
- from the national guide.
236
 
237
- Secondary source: The WHO Immunization Guide can be queried separately via `Immunization_in_Practice_tool`.
 
 
 
238
 
239
  Args:
240
- query (str): A general or complex question related to vaccination policy, schedules, or practice.
241
 
242
  Returns:
243
- str: Synthesized response based on the full Algerian guide.
244
  """
245
  if not guide_retriever:
246
  return "Guide retriever not available"
247
  return section_tool_wrapper(guide_retriever, guide_path, query)
248
 
249
- # Primary + Secondary Document Paths
250
- immunization_path = './data/Immunization in Practice_WHO_eng_2015.json'
251
-
252
- # WHO Immunization in Practice Tool
253
- if os.path.exists(immunization_path):
254
- immunization_vstore, immunization_docs = create_vectorstore_from_json(
255
- immunization_path,
256
- "Immunization_in_Practice_WHO_eng_2015",
257
- embedding_function
258
- )
259
- immunization_retriever = create_retriever(immunization_vstore, immunization_docs, llm)
260
- else:
261
- immunization_retriever = None
262
 
263
  def immunization_tool(query: str) -> str:
264
  """
265
  WHO Immunization in Practice 2015 retrieval tool.
266
 
267
- Use this tool to provide global best practices and operational guidance on immunization,
268
- especially when context or clarification is needed beyond the Algerian national guide.
269
- This can serve as a secondary source for training, logistics, and procedural reference.
 
 
270
 
271
  Args:
272
- query (str): A question related to immunization practice in general.
273
 
274
  Returns:
275
- str: Retrieved guidance from the WHO Immunization in Practice manual (2015).
276
  """
277
  if not immunization_retriever:
278
  return "Immunization in Practice retriever not available"
279
  return section_tool_wrapper(immunization_retriever, immunization_path, query)
280
 
281
 
282
-
283
- # Section-Specific Tools (Primary: Algerian National Vaccination Guide)
284
 
285
  def section_one_tool(query: str) -> str:
286
  """
287
  Section 1: Programme Élargi de Vaccination (PEV)
288
 
289
- Use this tool to retrieve information about the Algerian immunization program:
290
- its objectives, historical background, strengths and weaknesses, and justification
291
- for calendar updates.
292
 
293
- Primary source: Algerian National Vaccination Guide, Section 1.
294
- Secondary source for operational benchmarks: WHO Immunization in Practice (optional).
295
 
296
  Args:
297
- query (str): A question about Algeria’s national immunization strategy.
298
 
299
  Returns:
300
- str: Relevant content from Section 1 of the guide.
301
  """
302
  return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
303
 
304
 
305
  def section_two_tool(query: str) -> str:
306
  """
307
- Section 2: Maladies Ciblées par la Vaccination
308
 
309
- Use this tool for questions about the diseases targeted by the national vaccination calendar:
310
- symptoms, transmission, complications, and prevention strategies.
311
 
312
- Primary source: Algerian National Guide, Section 2.
313
- Secondary source: WHO guide may support contextual insights.
314
 
315
  Args:
316
- query (str): A question about a vaccine-preventable disease (e.g. polio, rougeole).
317
 
318
  Returns:
319
- str: Disease-specific guidance from Section 2.
320
  """
321
  return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
322
 
@@ -325,14 +327,16 @@ def create_section_tools(embedding_function, llm):
325
  """
326
  Section 3: Vaccins du Calendrier
327
 
328
- Use this tool to retrieve technical and procedural information about the vaccines used in the calendar:
329
- names, contents, administration method, and dosing details.
 
 
330
 
331
  Args:
332
- query (str): A question about a specific vaccine's type or method of use.
333
 
334
  Returns:
335
- str: Vaccine information from Section 3.
336
  """
337
  return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
338
 
@@ -341,30 +345,34 @@ def create_section_tools(embedding_function, llm):
341
  """
342
  Section 4: Rattrapage Vaccinal
343
 
344
- Use this tool to determine catch-up strategies for children who missed or delayed one or more doses.
345
- It provides age-adjusted rescheduling rules and justifications.
 
 
346
 
347
  Args:
348
- query (str): A question about how to manage missed vaccinations.
349
 
350
  Returns:
351
- str: Catch-up guidelines from Section 4.
352
  """
353
  return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
354
 
355
 
356
  def section_five_tool(query: str) -> str:
357
  """
358
- Section 5: Vaccination des Populations Particulières
 
 
 
359
 
360
- Use this tool to retrieve recommendations for specific medical contexts:
361
- preterm infants, immunocompromised children, allergies (e.g. eggs), and chronic diseases.
362
 
363
  Args:
364
- query (str): A question about vaccination adaptations for vulnerable groups.
365
 
366
  Returns:
367
- str: Guidelines from Section 5.
368
  """
369
  return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
370
 
@@ -373,14 +381,16 @@ def create_section_tools(embedding_function, llm):
373
  """
374
  Section 6: Chaîne du Froid
375
 
376
- Use this tool for logistics, storage conditions, temperature monitoring,
377
- and emergency procedures in case of cold chain failure.
 
 
378
 
379
  Args:
380
- query (str): A question about how vaccines should be stored and transported.
381
 
382
  Returns:
383
- str: Operational cold chain standards from Section 6.
384
  """
385
  return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
386
 
@@ -389,30 +399,34 @@ def create_section_tools(embedding_function, llm):
389
  """
390
  Section 7: Sécurité des Injections
391
 
392
- Use this tool to ensure injection safety: handling equipment, preventing needle-stick injuries,
393
- and disposing of biomedical waste.
 
 
394
 
395
  Args:
396
- query (str): A question about safe injection practices.
397
 
398
  Returns:
399
- str: Procedures and guidelines from Section 7.
400
  """
401
  return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
402
 
403
 
404
  def section_eight_tool(query: str) -> str:
405
  """
406
- Section 8: Tenue d'une Séance de Vaccination & Vaccinovigilance
407
 
408
- Use this tool to plan and monitor vaccination sessions, including material preparation,
409
- injection recording, and handling of adverse events post-immunization (AEFI).
 
 
410
 
411
  Args:
412
- query (str): A question about session operations or vaccine side effect monitoring.
413
 
414
  Returns:
415
- str: Guidelines from Section 8.
416
  """
417
  return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
418
 
@@ -421,14 +435,16 @@ def create_section_tools(embedding_function, llm):
421
  """
422
  Section 9: Planification des Séances de Vaccination
423
 
424
- Use this tool to support logistical planning: mapping, resource estimation,
425
- scheduling, and stock management.
 
 
426
 
427
  Args:
428
- query (str): A question about planning and organizing vaccination sessions.
429
 
430
  Returns:
431
- str: Recommendations from Section 9.
432
  """
433
  return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
434
 
@@ -437,17 +453,18 @@ def create_section_tools(embedding_function, llm):
437
  """
438
  Section 10: Mobilisation Sociale
439
 
440
- Use this tool for strategies to increase public engagement, combat vaccine hesitancy,
441
- and manage misinformation.
 
 
442
 
443
  Args:
444
- query (str): A question about public communication and trust-building around vaccines.
445
 
446
  Returns:
447
- str: Social mobilization approaches from Section 10.
448
  """
449
  return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
450
-
451
  # Create FunctionTool objects
452
  tools = [
453
  FunctionTool.from_defaults(name="Guide_vector_tool", fn=guide_retrieval_tool),
 
225
  guide_retriever = create_retriever(guide_vstore, guide_docs, llm)
226
  else:
227
  guide_retriever = None
228
+ # Primary + Secondary Document Paths
229
+ immunization_path = './data/Immunization in Practice_WHO_eng_2015.json'
230
+
231
+ # WHO Immunization in Practice Tool
232
+ if os.path.exists(immunization_path):
233
+ immunization_vstore, immunization_docs = create_vectorstore_from_json(
234
+ immunization_path,
235
+ "Immunization_in_Practice_WHO_eng_2015",
236
+ embedding_function
237
+ )
238
+ immunization_retriever = create_retriever(immunization_vstore, immunization_docs, llm)
239
+ else:
240
+ immunization_retriever = None
241
+
242
  # General-purpose tool (entire Algerian guide)
243
  def guide_retrieval_tool(query: str) -> str:
244
  """
245
  General-purpose retrieval tool for the entire Algerian National Vaccination Guide (2023).
246
 
247
+ Use ONLY when a query spans multiple unrelated sections or cannot be confidently routed
248
+ to a more specific tool. This tool provides a fallback when the intent is ambiguous
249
+ or multi-topic (e.g., combining schedule, cold chain, and public outreach in one query).
250
 
251
+ Do NOT use this tool for clearly scoped questions related to vaccination schedules, disease profiles,
252
+ vaccine logistics, or procedural workflows — use the specific section tools instead.
253
+
254
+ Secondary source: WHO Immunization Guide (use `immunization_tool` when broader context is required).
255
 
256
  Args:
257
+ query (str): A general, complex, or cross-sectional vaccination query.
258
 
259
  Returns:
260
+ str: Synthesized answer from the entire national guide.
261
  """
262
  if not guide_retriever:
263
  return "Guide retriever not available"
264
  return section_tool_wrapper(guide_retriever, guide_path, query)
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  def immunization_tool(query: str) -> str:
268
  """
269
  WHO Immunization in Practice 2015 retrieval tool.
270
 
271
+ Use ONLY when global guidance or procedural context is needed that is not covered or
272
+ is unclear in the Algerian guide. This is a secondary reference for training standards,
273
+ general immunization logistics, and vaccine delivery practices.
274
+
275
+ Do NOT use this tool to answer country-specific policy or scheduling questions.
276
 
277
  Args:
278
+ query (str): A question seeking global immunization practices.
279
 
280
  Returns:
281
+ str: Content from the WHO Immunization in Practice guide.
282
  """
283
  if not immunization_retriever:
284
  return "Immunization in Practice retriever not available"
285
  return section_tool_wrapper(immunization_retriever, immunization_path, query)
286
 
287
 
288
+ # Section-Specific Tools
 
289
 
290
  def section_one_tool(query: str) -> str:
291
  """
292
  Section 1: Programme Élargi de Vaccination (PEV)
293
 
294
+ Use for queries about the national immunization program structure: its objectives,
295
+ history, evaluation, and rationale for updates to the Algerian calendar.
 
296
 
297
+ Do NOT use for vaccine schedules, disease information, or administration techniques.
 
298
 
299
  Args:
300
+ query (str): A question about the foundation or evolution of the PEV.
301
 
302
  Returns:
303
+ str: Response from Section 1.
304
  """
305
  return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
306
 
307
 
308
  def section_two_tool(query: str) -> str:
309
  """
310
+ Section 2: Maladies Ciblées
311
 
312
+ Use ONLY for questions about the characteristics of vaccine-preventable diseases:
313
+ symptoms, transmission, complications, and prevention.
314
 
315
+ Do NOT use for questions about vaccines, administration schedules, or procedures.
 
316
 
317
  Args:
318
+ query (str): A question about a disease covered by the national vaccination program.
319
 
320
  Returns:
321
+ str: Disease-specific content from Section 2.
322
  """
323
  return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
324
 
 
327
  """
328
  Section 3: Vaccins du Calendrier
329
 
330
+ Use ONLY for questions about the vaccines themselves: their types, compositions,
331
+ methods of administration, and how they work.
332
+
333
+ Do NOT use for schedule timing, catch-up protocols, or disease information.
334
 
335
  Args:
336
+ query (str): A question about a vaccine's formulation or method of delivery.
337
 
338
  Returns:
339
+ str: Vaccine info from Section 3.
340
  """
341
  return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
342
 
 
345
  """
346
  Section 4: Rattrapage Vaccinal
347
 
348
+ Use ONLY when the question involves missed or delayed vaccinations and how to reschedule them
349
+ based on the child’s current age.
350
+
351
+ Do NOT use for standard schedules (on-time), vaccine properties, or cold chain issues.
352
 
353
  Args:
354
+ query (str): A question about catch-up vaccination based on delay or omission.
355
 
356
  Returns:
357
+ str: Catch-up guidance from Section 4.
358
  """
359
  return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
360
 
361
 
362
  def section_five_tool(query: str) -> str:
363
  """
364
+ Section 5: Populations Particulières
365
+
366
+ Use ONLY for vaccination questions concerning special populations:
367
+ preterm infants, immunosuppressed patients, chronic illness, or allergy conditions.
368
 
369
+ Do NOT use for general population, standard calendar, or vaccine preparation.
 
370
 
371
  Args:
372
+ query (str): A question about tailored vaccination for vulnerable groups.
373
 
374
  Returns:
375
+ str: Custom recommendations from Section 5.
376
  """
377
  return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
378
 
 
381
  """
382
  Section 6: Chaîne du Froid
383
 
384
+ Use ONLY for questions about vaccine storage, transport, cold chain equipment,
385
+ temperature monitoring, or cold chain failures.
386
+
387
+ Do NOT use for dose timing, administration methods, or disease information.
388
 
389
  Args:
390
+ query (str): A logistics-related question about vaccine temperature management.
391
 
392
  Returns:
393
+ str: Cold chain instructions from Section 6.
394
  """
395
  return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
396
 
 
399
  """
400
  Section 7: Sécurité des Injections
401
 
402
+ Use ONLY for questions related to the safe administration of vaccines:
403
+ equipment use, technique, safety precautions, and waste disposal.
404
+
405
+ Do NOT use for vaccine types, schedules, or cold chain issues.
406
 
407
  Args:
408
+ query (str): A question about how to inject vaccines safely.
409
 
410
  Returns:
411
+ str: Best practices from Section 7.
412
  """
413
  return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
414
 
415
 
416
  def section_eight_tool(query: str) -> str:
417
  """
418
+ Section 8: Séance de Vaccination & Vaccinovigilance
419
 
420
+ Use ONLY for questions about running a vaccination session, preparing the setting,
421
+ recording injections, and monitoring for adverse events (AEFI).
422
+
423
+ Do NOT use for disease, vaccine, or scheduling details.
424
 
425
  Args:
426
+ query (str): A question about operational conduct during vaccination.
427
 
428
  Returns:
429
+ str: Workflow and safety monitoring details from Section 8.
430
  """
431
  return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
432
 
 
435
  """
436
  Section 9: Planification des Séances de Vaccination
437
 
438
+ Use ONLY for planning and logistics questions: session scheduling, stock estimation,
439
+ and operational preparation at the facility level.
440
+
441
+ Do NOT use for vaccine info, schedules, or injection techniques.
442
 
443
  Args:
444
+ query (str): A question about how to plan or organize vaccination services.
445
 
446
  Returns:
447
+ str: Planning and stock guidance from Section 9.
448
  """
449
  return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
450
 
 
453
  """
454
  Section 10: Mobilisation Sociale
455
 
456
+ Use ONLY for questions about communication strategies, overcoming vaccine hesitancy,
457
+ rumor management, or community outreach.
458
+
459
+ Do NOT use for medical, logistical, or procedural topics.
460
 
461
  Args:
462
+ query (str): A question about public engagement or communication for vaccination.
463
 
464
  Returns:
465
+ str: Public mobilization strategies from Section 10.
466
  """
467
  return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
 
468
  # Create FunctionTool objects
469
  tools = [
470
  FunctionTool.from_defaults(name="Guide_vector_tool", fn=guide_retrieval_tool),