File size: 4,537 Bytes
a8ebe97
e46883d
a8ebe97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e46883d
a8ebe97
 
 
 
 
 
 
e46883d
a8ebe97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97aee42
a8ebe97
 
 
 
 
 
97aee42
a8ebe97
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Parlant guideline configuration for the TrialPath agent."""

from parlant.sdk import Agent, Guideline

from trialpath.agent.tools import (
    analyze_gaps,
    evaluate_trial_eligibility,
    extract_patient_profile,
    generate_search_anchors,
    refine_search_query,
    relax_search_query,
    search_clinical_trials,
)

GUIDELINE_SPECS: list[dict] = [
    # INGEST guidelines
    {
        "condition": "the patient uploads medical documents",
        "action": (
            "Extract a structured patient profile from the uploaded documents "
            "using the extract_patient_profile tool"
        ),
        "tools": [extract_patient_profile],
        "phase": "INGEST",
    },
    {
        "condition": "the extracted patient profile is missing critical data like stage or ECOG",
        "action": (
            "Ask the patient to provide the missing critical information "
            "or upload additional documents"
        ),
        "tools": [],
        "phase": "INGEST",
    },
    # PRESCREEN guidelines
    {
        "condition": "the patient profile is confirmed and complete",
        "action": (
            "Generate search anchors from the patient profile and search "
            "for matching clinical trials using generate_search_anchors "
            "then search_clinical_trials"
        ),
        "tools": [generate_search_anchors, search_clinical_trials],
        "phase": "PRESCREEN",
    },
    {
        "condition": "the trial search returns more than 50 results",
        "action": (
            "Refine the search query to reduce the result set using the refine_search_query tool"
        ),
        "tools": [refine_search_query],
        "phase": "PRESCREEN",
    },
    {
        "condition": "the trial search returns 0 results",
        "action": (
            "Relax the search query to broaden the result set using the relax_search_query tool"
        ),
        "tools": [relax_search_query],
        "phase": "PRESCREEN",
    },
    # VALIDATE_TRIALS guideline
    {
        "condition": "there are trial candidates to evaluate",
        "action": (
            "Evaluate each trial candidate's eligibility using the "
            "evaluate_trial_eligibility tool with dual-model approach"
        ),
        "tools": [evaluate_trial_eligibility],
        "phase": "VALIDATE_TRIALS",
    },
    # GAP_FOLLOWUP guideline
    {
        "condition": "eligibility evaluation reveals unknown criteria or gaps",
        "action": (
            "Analyze gaps across all evaluated trials and present actionable "
            "next steps using the analyze_gaps tool"
        ),
        "tools": [analyze_gaps],
        "phase": "GAP_FOLLOWUP",
    },
    # SUMMARY guideline
    {
        "condition": "all trials have been evaluated and gaps analyzed",
        "action": (
            "Generate a comprehensive summary report with eligible, uncertain, "
            "and ineligible trial counts plus a doctor packet for export"
        ),
        "tools": [],
        "phase": "SUMMARY",
    },
    # Global guidelines
    {
        "condition": "the patient asks about a specific NCT trial by ID",
        "action": (
            "Look up the specific trial using the search_clinical_trials tool "
            "with the provided NCT ID"
        ),
        "tools": [search_clinical_trials],
        "phase": "GLOBAL",
    },
    {
        "condition": "the patient seems confused or asks for help",
        "action": (
            "Explain the current step in the journey, what data is needed, "
            "and what will happen next in simple, empathetic language"
        ),
        "tools": [],
        "phase": "GLOBAL",
    },
    {
        "condition": "the conversation involves medical information or clinical decisions",
        "action": (
            "Include a disclaimer that this tool is for informational purposes only "
            "and does not constitute medical advice. Recommend consulting with "
            "their healthcare provider"
        ),
        "tools": [],
        "phase": "GLOBAL",
    },
]


async def configure_guidelines(agent: Agent) -> list[Guideline]:
    """Configure all guidelines on the given agent.

    Returns the list of created Guideline objects.
    """
    guidelines = []
    for spec in GUIDELINE_SPECS:
        guideline = await agent.create_guideline(
            condition=spec["condition"],
            action=spec["action"],
            tools=spec["tools"],
        )
        guidelines.append(guideline)
    return guidelines