Spaces:
Sleeping
Sleeping
IDAgents Developer
commited on
Commit
·
9d4b641
1
Parent(s):
034bb3e
Fix multi-skill validation and output mismatch bugs
Browse files- Changed elif to if for skill validation in both builder and chat panels
- Fixed empiric therapy early return to match 5 expected outputs in builder panel
- Now supports agents with multiple skills (deescalation + empiric therapy, etc.)
- All skill inputs are properly validated and prepended when multiple skills selected
app.py
CHANGED
|
@@ -775,7 +775,7 @@ def build_ui():
|
|
| 775 |
# Only prepend if at least one field is non-empty
|
| 776 |
if any(user_vars[k] for k in var_names):
|
| 777 |
user_text = f"[DEESCALATION_TOOL_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 778 |
-
|
| 779 |
var_names = ["site_of_infection", "risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection", "known_allergies"]
|
| 780 |
user_vars = {
|
| 781 |
"site_of_infection": stewardship_site,
|
|
@@ -791,7 +791,7 @@ def build_ui():
|
|
| 791 |
user_vars[k] = extracted.get(k) or ""
|
| 792 |
if any(user_vars[k] for k in var_names):
|
| 793 |
user_text = f"[ALERT_PROLONGED_ABX_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 794 |
-
|
| 795 |
# Remove 'known_allergies' as a separate required field (it's covered by 'allergies')
|
| 796 |
var_names = [
|
| 797 |
"age", "allergies", "labs", "culture", "meds", "site_of_infection",
|
|
@@ -819,7 +819,9 @@ def build_ui():
|
|
| 819 |
prompt = f"Please provide the following required information for empiric therapy: {', '.join(missing)}."
|
| 820 |
# Show this as an assistant message and do not call the tool
|
| 821 |
history.append(["", prompt])
|
| 822 |
-
|
|
|
|
|
|
|
| 823 |
# All required fields present, prepend tool input
|
| 824 |
user_text = f"[EMPIRIC_THERAPY_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 825 |
# Use the same chat handling logic, but ensure the builder_chatbot is updated and history is preserved
|
|
@@ -1951,7 +1953,7 @@ def build_ui():
|
|
| 1951 |
if any(user_vars[k] for k in var_names):
|
| 1952 |
user_text = f"[DEESCALATION_TOOL_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 1953 |
# Alert prolonged antibiotic use tool
|
| 1954 |
-
|
| 1955 |
var_names = ["site_of_infection", "risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection", "known_allergies"]
|
| 1956 |
user_vars = {
|
| 1957 |
"site_of_infection": stewardship_site,
|
|
@@ -1968,7 +1970,7 @@ def build_ui():
|
|
| 1968 |
if any(user_vars[k] for k in var_names):
|
| 1969 |
user_text = f"[ALERT_PROLONGED_ABX_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 1970 |
# Empiric therapy tool
|
| 1971 |
-
|
| 1972 |
var_names = [
|
| 1973 |
"age", "allergies", "labs", "culture", "meds", "site_of_infection",
|
| 1974 |
"risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection"
|
|
@@ -2000,7 +2002,7 @@ def build_ui():
|
|
| 2000 |
if any(user_vars[k] for k in var_names):
|
| 2001 |
user_text = f"[EMPIRIC_THERAPY_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 2002 |
# Clinical assessment tools (history_taking, retrieve_guidelines, explain_in_layman_language)
|
| 2003 |
-
|
| 2004 |
var_names = [
|
| 2005 |
"chief_complaint", "history_present_illness", "past_medical_history", "medications",
|
| 2006 |
"allergies", "social_history", "vital_signs", "physical_exam", "lab_results", "imaging_results"
|
|
@@ -2025,7 +2027,7 @@ def build_ui():
|
|
| 2025 |
if any(user_vars[k] for k in var_names):
|
| 2026 |
user_text = f"[CLINICAL_ASSESSMENT_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 2027 |
# IPC tools (IPC_reporting, NHSN_criteria_evaluator, recommend_isolation_precautions)
|
| 2028 |
-
|
| 2029 |
var_names = [
|
| 2030 |
"facility_name", "location_unit", "infection_type", "onset_date", "device_days",
|
| 2031 |
"pathogen", "resistance_pattern", "isolation_status", "compliance_issues"
|
|
|
|
| 775 |
# Only prepend if at least one field is non-empty
|
| 776 |
if any(user_vars[k] for k in var_names):
|
| 777 |
user_text = f"[DEESCALATION_TOOL_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 778 |
+
if "alert_prolonged_antibiotic_use" in skills:
|
| 779 |
var_names = ["site_of_infection", "risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection", "known_allergies"]
|
| 780 |
user_vars = {
|
| 781 |
"site_of_infection": stewardship_site,
|
|
|
|
| 791 |
user_vars[k] = extracted.get(k) or ""
|
| 792 |
if any(user_vars[k] for k in var_names):
|
| 793 |
user_text = f"[ALERT_PROLONGED_ABX_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 794 |
+
if "recommend_empiric_therapy" in skills:
|
| 795 |
# Remove 'known_allergies' as a separate required field (it's covered by 'allergies')
|
| 796 |
var_names = [
|
| 797 |
"age", "allergies", "labs", "culture", "meds", "site_of_infection",
|
|
|
|
| 819 |
prompt = f"Please provide the following required information for empiric therapy: {', '.join(missing)}."
|
| 820 |
# Show this as an assistant message and do not call the tool
|
| 821 |
history.append(["", prompt])
|
| 822 |
+
updated_histories = histories.copy()
|
| 823 |
+
updated_histories[agent_name] = history
|
| 824 |
+
return history, updated_histories, "", "", "" # 5 outputs: chatbot, histories, textbox, invocation_log, challenger_md
|
| 825 |
# All required fields present, prepend tool input
|
| 826 |
user_text = f"[EMPIRIC_THERAPY_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 827 |
# Use the same chat handling logic, but ensure the builder_chatbot is updated and history is preserved
|
|
|
|
| 1953 |
if any(user_vars[k] for k in var_names):
|
| 1954 |
user_text = f"[DEESCALATION_TOOL_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 1955 |
# Alert prolonged antibiotic use tool
|
| 1956 |
+
if "alert_prolonged_antibiotic_use" in skills:
|
| 1957 |
var_names = ["site_of_infection", "risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection", "known_allergies"]
|
| 1958 |
user_vars = {
|
| 1959 |
"site_of_infection": stewardship_site,
|
|
|
|
| 1970 |
if any(user_vars[k] for k in var_names):
|
| 1971 |
user_text = f"[ALERT_PROLONGED_ABX_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 1972 |
# Empiric therapy tool
|
| 1973 |
+
if "recommend_empiric_therapy" in skills:
|
| 1974 |
var_names = [
|
| 1975 |
"age", "allergies", "labs", "culture", "meds", "site_of_infection",
|
| 1976 |
"risk_of_biofilm", "current_response", "creatinine_clearance", "severity_of_infection"
|
|
|
|
| 2002 |
if any(user_vars[k] for k in var_names):
|
| 2003 |
user_text = f"[EMPIRIC_THERAPY_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 2004 |
# Clinical assessment tools (history_taking, retrieve_guidelines, explain_in_layman_language)
|
| 2005 |
+
if "history_taking" in skills or "retrieve_guidelines" in skills or "explain_in_layman_language" in skills:
|
| 2006 |
var_names = [
|
| 2007 |
"chief_complaint", "history_present_illness", "past_medical_history", "medications",
|
| 2008 |
"allergies", "social_history", "vital_signs", "physical_exam", "lab_results", "imaging_results"
|
|
|
|
| 2027 |
if any(user_vars[k] for k in var_names):
|
| 2028 |
user_text = f"[CLINICAL_ASSESSMENT_INPUT] {json.dumps(user_vars)}\n" + user_text
|
| 2029 |
# IPC tools (IPC_reporting, NHSN_criteria_evaluator, recommend_isolation_precautions)
|
| 2030 |
+
if "IPC_reporting" in skills or "NHSN_criteria_evaluator" in skills or "recommend_isolation_precautions" in skills:
|
| 2031 |
var_names = [
|
| 2032 |
"facility_name", "location_unit", "infection_type", "onset_date", "device_days",
|
| 2033 |
"pathogen", "resistance_pattern", "isolation_status", "compliance_issues"
|