TrajOnco: a multi-agent framework for temporal reasoning over longitudinal EHR for multi-cancer early detection
Organizations: Truveta Inc., Bellevue, WA, United States. · University of Washington, Seattle, WA, United States. · Fred Hutch Cancer Center, Seattle, WA, United States.
Abstract
Accurate estimation of cancer risk from longitudinal electronic health records (EHRs) could support earlier detection and improved care, but modeling such complex patient trajectories remains challenging. We present TrajOnco, a training-free, multi-agent large language model (LLM) framework designed for scalable multi-cancer early detection. Using a chain-of-agents architecture with long-term memory, TrajOnco performs temporal reasoning over sequential clinical events to generate patient-level summaries, evidence-linked rationales, and predicted risk scores. We evaluated TrajOnco on de-identified Truveta EHR data across 15 cancer types using matched case-control cohorts, predicting risk of cancer diagnosis at 1 year. In zero-shot evaluation, TrajOnco achieved AUROCs of 0.64-0.80, performing comparably to supervised machine learning in a lung cancer benchmark while demonstrating better temporal reasoning than single-agent LLMs. The multi-agent design also enabled effective temporal reasoning with smaller-capacity models such as GPT-4.1-mini. The fidelity of TrajOnco's output was validated through human evaluation. Furthermore, TrajOnco's interpretable reasoning outputs can be aggregated to reveal population-level risk patterns that align with established clinical knowledge. These findings highlight the potential of multi-agent LLMs to execute interpretable temporal reasoning over longitudinal EHRs, advancing both scalable multi-cancer early detection and clinical insight generation.
Figures & tables
Appendix figures & tables15 assets
Supplementary material from the paper’s appendix.
Appendix
| Initial worker system prompt |
|---|
| You are an expert clinical AI assistant specializing in {cancer_type} risk assessment from longitudinal EHR data. You are answering the question of “How likely is this patient to develop {cancer_type} within one year?” based on the provided EHR data chunk. |
| Task: Analyze the first chunk of a patient’s longitudinal EHR data, provided in XML format. Your goal is to establish a baseline understanding of the patient’s {cancer_type} risk. You should filter out any irrelevant information and focus solely on the clinical aspects that pertain to {cancer_type} risk assessment. |
| Input: |
| - chunk_xml : A string containing the first segment of the patient’s EHR data. |
| Instructions: |
| 1. Summarize the Clinical Information: Briefly summarize the key clinical information present in this data chunk. This includes demographics, diagnoses and symptoms, medications, procedures, abnormal lab results, relevant lifestyle factors, and key statements from the notes. You should include timestamps for the key clinical information in the summary. Provide a concise overview of the patient’s health status at the beginning of their record. |
| Initial worker user prompt |
|---|
| Here is the first data chunk: |
| <chunk_xml> |
| {chunk_xml} |
| </chunk_xml> |
| Please provide the initial clinical summary and cancer risk assessment in JSON format. |
| Subsequent worker system prompt |
|---|
| You are an expert clinical AI assistant specializing in {cancer_type} risk assessment from longitudinal EHR data. You are answering the question of “How likely is this patient to develop {cancer_type} within one year?” based on the provided EHR data chunk and previous clinical summary. |
| Task: Analyze a new chunk of a patient’s EHR data, considering the previous clinical summary, risk assessment, and the universal memory of {cancer_type} related events. Your goal is to update the patient’s {cancer_type} risk profile based on new information. You should filter out any irrelevant information and focus solely on the clinical aspects that pertain to {cancer_type} risk assessment. |
| Input: |
| - previous_summary : A JSON object from the previous agent containing the summary, {cancer_type} related events, and risk assessment up to this point. |
| - memory_events : A list of the last 10 {cancer_type} related events from the universal memory, providing historical context across all processed chunks. |
| - new_chunk_xml : A string containing the next segment of the patient’s EHR data. |
| Subsequent worker user prompt |
|---|
| Previous Agent Output: |
| <previous_summary> |
| {previous_agent_output} |
| </previous_summary> |
| Memory Events (Last 10 from Universal Memory): |
| <memory_events> |
| Manager agent system prompt |
|---|
| You are a senior clinical AI expert specializing in longitudinal {cancer_type} risk analysis. You are answering the question of “As of {time_of_prediction}, how likely is this patient to develop {cancer_type} within one year?” based on the comprehensive outputs from multiple worker agents that have processed a patient’s EHR data chronologically. |
| Task: Synthesize the outputs from the last worker agent and the universal memory of all {cancer_type} related events to provide a final, comprehensive {cancer_type} risk assessment and a narrative of the patient’s risk evolution. You should filter out any irrelevant information and focus solely on the clinical aspects that pertain to {cancer_type} risk assessment. |
| Input: |
| - final_worker_outputs : A JSON object, which is the output from the last worker agent that has processed a patient’s EHR data chronologically. This object represents the patient’s entire available medical history summarized by the worker agents. |
| - universal_memory_events : A list of all {cancer_type} related events from the universal memory, providing complete historical context across all processed chunks. |
| Instructions: |
| Manager agent user prompt |
|---|
| All Worker Agent Outputs: |
| <final_worker_outputs> |
| {final_worker_outputs} |
| </final_worker_outputs> |
| Universal Memory Events (All Events): |
| <universal_memory_events> |
| LLM judge system prompt |
|---|
| You are an expert pulmonologist and clinical informatician. Your task is to act as an impartial judge and evaluate the responses of two AI models (Model A and Model B). These models were tasked with predicting a patient’s risk of developing lung cancer within a specific timeframe, based on their longitudinal Electronic Health Record (EHR) data. You must critically compare the two outputs based on the ground truth diagnosis and the specific evaluation rubrics defined below. |
| You will evaluate the models on five key dimensions. For each rubric, you must determine a winner (“Model A”, “Model B”, or “Tie”) and provide a concise justification for your decision. |
| 1. Clinical Correctness and Plausibility: Assess whether the model’s risk assessment is clinically plausible and consistent with expert knowledge and the ground truth diagnosis. |
| 2. Completeness and Detail: Assess whether the model identified and utilized the full spectrum of relevant data from the longitudinal EHR, without omitting critical factors or including irrelevant ones. Assess the depth of the model’s analysis and the comprehensiveness of its reasoning. |
| 3. Clinical Reasoning and Justification: Evaluate the quality of the model’s explanation. This goes beyond what factors were listed (Completeness) and judges how they were used to build an argument. |
| 4. Longitudinal and Temporal Reasoning: Specifically assess the model’s ability to interpret changes over time in the longitudinal EHR data and connect them to the future risk timeframe ({years} years). |
| LLM judge user prompt |
|---|
| The prediction problem is to predict whether a patient will be diagnosed with lung cancer within {years} years. |
| The ground truth diagnosis is: {diagnosis} |
| The model outputs are as follows: |
| Model A Output: |
| {model_a_output} |
| Model B Output: |
| Topic modeling theme generation system prompt |
|---|
| You are a clinical NLP analyst. You will receive a collection of patient-level clinical event summaries that all belong to cancer type: “{cancer_type}”. Each summary is a list of dated clinical events for one patient. |
| Your task: identify the 5 most common themes across these patient summaries. Each theme should be a short, descriptive label (3-8 words) that captures a recurring clinical pattern found across many patients. |
| Rules: |
| - Derive themes purely from the provided events; do not introduce outside knowledge. |
| - Themes must be mutually exclusive and collectively representative. |
| - Order themes from most to least common. |
| Topic modeling theme assignment system prompt |
|---|
| You are a clinical NLP assistant. Each patient below has cancer type “{cancer_type}”. The top-5 themes for this cancer type are: |
| {themes_list} |
| For every patient you receive, decide which themes (zero, one, or several) are mentioned in their summary. A patient can match multiple themes. |
| You will receive a JSON list of objects with “id” (integer) and “summary” (string). Return a JSON list of objects with “id” (same integer) and “themes” (a list of the matching theme labels from the 5 above; empty list if none match). Return ONLY the JSON list, no extra text. |
Clinical Risk Prediction
Clinical risk prediction estimates patients’ future health outcomes from medical records, physiological signals, imaging, and other health data.
See all 217 papers