from tools.base import Tool from tools.utils import load_prompt, ToolExecutionError, logger from typing import Any class RecommendEmpiricTherapyTool(Tool): def openai_spec(self, legacy=False): return { "name": self.name, "description": self.description, "parameters": self.args_schema } """ Tool to recommend empiric antibiotic therapy based on a patient's profile. This tool uses patient age, allergies, and laboratory results to generate a prompt for an LLM or rules engine to recommend empiric therapy. """ def __init__(self) -> None: """ Initialize the RecommendEmpiricTherapyTool with its name, description, and argument schema. """ super().__init__() self.name = "recommend_empiric_therapy" self.description = ( "Recommend empiric antibiotic therapy based on patient profile." ) self.args_schema = { "type": "object", "properties": { "age": {"type": "string", "description": "Patient age or age bracket"}, "allergies": {"type": "string", "description": "List of known drug allergies"}, "labs": {"type": "string", "description": "Relevant laboratory results"}, "culture": {"type": "string", "description": "Culture & sensitivity results"}, "meds": {"type": "string", "description": "Current antibiotic regimen"}, "site_of_infection": {"type": "string", "description": "Site of infection (e.g., lung, urine, blood, etc.)"}, "risk_of_biofilm": {"type": "string", "description": "Risk or presence of biofilm (e.g., prosthetic material, indwelling device, etc.)"}, "current_response": {"type": "string", "description": "Current response to antibiotics (e.g., improving, stable, worsening)"}, "creatinine_clearance": {"type": "string", "description": "Current creatinine clearance or renal function"}, "severity_of_infection": {"type": "string", "description": "Severity of infection (e.g., mild, moderate, severe, septic shock)"}, }, "required": ["age", "allergies", "labs", "culture", "meds", "site_of_infection", "risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection"] } async def run(self, age: str, allergies: str, labs: str, culture: str, meds: str, site_of_infection: str, risk_of_biofilm: str, current_response: str, creatinine_clearance: str, severity_of_infection: str) -> str: """ Generate an empiric therapy recommendation based on patient data. Args: age (str): Patient age or age bracket. allergies (str): List of known drug allergies. labs (str): Relevant laboratory results. Returns: str: The empiric therapy recommendation (placeholder). """ try: prompt: str = load_prompt( "empiric_therapy.j2", age=age, allergies=allergies, labs=labs, culture=culture, meds=meds, site_of_infection=site_of_infection, risk_of_biofilm=risk_of_biofilm, current_response=current_response, creatinine_clearance=creatinine_clearance, severity_of_infection=severity_of_infection ) # Placeholder for LLM call return f"Empiric therapy recommendation for: {age}, {allergies}, {labs}, {culture}, {meds}, {site_of_infection}, {risk_of_biofilm}, {current_response}, {creatinine_clearance}, {severity_of_infection}" except Exception as e: logger.error(f"EmpiricTherapyTool failed: {e}", exc_info=True) raise ToolExecutionError( message=f"EmpiricTherapyTool failed: {e}", code="EMPIRIC_THERAPY_ERROR", user_message="Unable to generate empiric therapy recommendation. Please try again or contact support.", original_exception=e )