Rethink context engineering using an attention-based architecture
摘要
Accurate prediction of user actions is essential for optimizing digital platform workflows, enabling proactive recommendations, resource prefetching, and intelligent user assistance. Traditional Markov chain-based methods, though widely used for modeling sequential behavior, are fundamentally limited in capturing the complexity, long-range dependencies, and multi-objective nature of real-world user interactions. This paper introduces a multi-task attention-based transformer architecture for sequential API recommendation that addresses these gaps in robustness and generalizability. The core insight is that user behavior on enterprise platforms is driven by latent intent: users with different goals—such as executing a machine learning pipeline, conducting data analysis, managing user accounts, or generating quick visualizations—exhibit systematically different sequential patterns across functional API categories. Our framework exploits this structure through a shared transformer encoder backbone that produces a unified representation of the user’s action history, which is then decoded by three task-specific prediction heads operating simultaneously. The primary head predicts the next API action from a probability distribution over all available endpoints; an auxiliary goal classification head infers the user’s underlying session objective from the observed action sequence alone; and a session boundary detection head estimates the probability that the user is about to conclude their session. During inference, only the sequence of prior API calls is required as input—the model jointly infers what the user will do next, what they are trying to accomplish, and whether they are about to leave, all from the observed behavioral trace. Leveraging a large-scale simulated behavioral dataset encompassing 2, 000 user sessions and 20, 000 API calls across 100 APIs organized into 10 functional categories, with 4 distinct session goal types governing workflow-specific transition patterns, our model demonstrates strong performance across all tasks. The primary API prediction task achieves