from tools.base import Tool from tools.utils import load_prompt from typing import Any class RecommendDeescalationTool(Tool): def openai_spec(self, legacy=False): return { "name": self.name, "description": self.description, "parameters": self.args_schema } """ Tool to recommend narrowing (deescalation) of antibiotics based on culture and sensitivity results. This tool uses microbiology results and current antibiotic regimen to generate a prompt for an LLM or rules engine to recommend deescalation. """ def __init__(self) -> None: """ Initialize the RecommendDeescalationTool with its name, description, and argument schema. """ super().__init__() self.name = "recommend_deescalation" self.description = ( "Recommend narrowing antibiotics based on culture & sensitivity." ) self.args_schema = { "type": "object", "properties": { "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)"}, "known_allergies": {"type": "string", "description": "Known drug allergies (comma-separated or free text)"} }, "required": ["culture", "meds", "site_of_infection", "risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection", "known_allergies"] } async def run( self, culture: str, meds: str, site_of_infection: str, risk_of_biofilm: str, current_response: str, creatinine_clearance: str, severity_of_infection: str, known_allergies: str ) -> str: """ Generate a deescalation recommendation based on all relevant clinical variables. Args: culture (str): Culture & sensitivity results. meds (str): Current antibiotic regimen. site_of_infection (str): Site of infection. risk_of_biofilm (str): Risk or presence of biofilm. current_response (str): Current response to antibiotics. creatinine_clearance (str): Renal function. severity_of_infection (str): Severity of infection. Returns: str: The deescalation recommendation (placeholder). """ prompt: str = load_prompt( "deescalation.j2", 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, known_allergies=known_allergies ) # Placeholder for LLM call return ( f"Deescalation recommendation for: {culture}, {meds}, " f"Site: {site_of_infection}, Biofilm: {risk_of_biofilm}, Response: {current_response}, " f"CrCl: {creatinine_clearance}, Severity: {severity_of_infection}, Allergies: {known_allergies}" )