LLM agents for coding, search, and workplace tasks increasingly rely on long-context capabilities to effectively aggregate and reason over extended interaction histories. Recent work has incorporated agent trajectories into mid-training stage, drawing on their naturally long and interaction-rich structure. Yet how to organize the information within these trajectories into effective mid-training supervision remains underexplored. In this work, we investigate the relationship between long-context and agent atomic capabilities and introduce TrajLong, a novel framework that compiles trajectories into long-context training tasks with dense supervision, targeting three representative atomic capabilities: evidence grounding, cross-evidence aggregation, and temporal state maintenance. We mid-train Qwen3-14B-Base and Qwen3-30B-A3B-Base with data compiled by TrajLong, followed by supervised fine-tuning. Experiments on 6 long-context and 12 agent benchmarks demonstrate broad performance gains, with controlled ablations showing improvements over raw and masked trajectory baselines. Capability-level analyses further reveal task-dependent associations between long-context and agent atomic capabilities. These findings suggest that the shared capability demands of long-context reasoning and agent execution provide a principled basis for designing mid-training data to develop downstream agent capabilities.
Figures & tables
Figure 1: Overview of TrajLong . Left: Full-trajectory and masked mid-training strategies compared with TrajLong compilation. Right: Avg@3 scores of Qwen3-14B variants on seven long-context and agent benchmarks across search, tool-use, and coding tasks.
Figure 2: Correlation between RULER ICL gains and downstream BrowseComp-ZH gains across Qwen3-14B variants mid-trained with different agent trajectories.
Figure 3: The TrajLong data construction pipeline. Search and coding agent trajectories are cleaned and filtered, then compiled into long-context training examples targeting evidence grounding (Retrieval), cross-evidence aggregation (MultidocQA), and temporal state maintenance (State Tracking), providing capability-targeted supervision for long-context agentic mid-training.
Models
LongBench V2
MRCR
GraphWalks
GSM-Inf
CorpusQA
Avg@3
BoN@3
Avg@3
BoN@3
Avg@3
BoN@3
Avg@3
BoN@3
Avg@3
BoN@3
Frontier Models
Gemini-2.5-Flash-Thinking
58.18
67.00
59.45
73.52
41.10
58.41
25.00
42.67
77.41
83.28
QwenLong L1.5-30B-A3B
45.04
54.69
55.12
61.51
39.24
44.16
39.56
64.33
80.14
88.45
GPT-OSS-120B
26.15
38.12
16.66
26.54
30.79
35.48
24.00
42.00
62.31
75.68
Our Models
Table 1: Performance on five long-context benchmarks (Avg@3 and BoN@3). MRCR averages scores equally across 2/4/8-needle settings, and GraphWalks across 0–128K and 128–256K context-length intervals. Subscripts show changes relative to the corresponding Qwen3 model within each group (pp). Bold marks the best score within each group.
Models
Search
Tool Use
Coding
BC
BC-ZH
WideSearch
FSC-V2
SealQA
MCP-Atlas
SkillsBench
WebArena
TB 2.1
NL2Repo
SWE-Verified
SWE-Pro
Frontier Models
Gemini-2.5-Flash-Thinking
12.72
27.89
30.84
34.48
24.02
19.87
7.41
39.43
17.75
12.40
48.60
24.08
QwenLong L1.5-30B-A3B
2.98
11.07
35.27
20.36
16.58
32.73
1.39
27.17
1.87
7.71
31.60
10.94
GPT-OSS-120B
25.62
24.22
36.46
41.09
22.52
39.40
-
31.40
12.36
6.88
53.00
27.13
Our Models
Table 2: Performance on search, tool-use, and coding agent benchmarks (Avg@3). Bold marks the best score within each group. Benchmark details and BoN@3 results are in Appendix B.3 and E.2 .
Mid-training Variant
Long-Context
Agent
Oolong-Synth
GraphWalks
CorpusQA
FSC-V2
SkillsBench
SWE-Verified
SWE-Pro
TrajLong - All
58.50 +0.0
32.30 +0.0
63.83 +0.0
43.53 +0.0
11.11 +0.0
54.40 +0.0
36.43 +0.0
SFT only
53.17 -5.33
24.12 -8.18
55.93 -7.90
35.09 -8.44
6.48 -4.63
42.13 -12.27
24.21 -12.22
Search Trajectories
57.33 -1.17
31.58 -0.72
61.80 -2.03
40.05 -3.48
9.72 -1.39
50.27 -4.13
31.37 -5.06
Code Trajectories
55.33 -3.17
32.77 +0.47
61.80 -2.03
39.49 -4.04
8.80 -2.31
52.40 -2.00
34.38 -2.05
Combined Trajectories
56.67 -1.83
31.38 -0.92
61.80 -2.03
40.87 -2.66
9.26 -1.85
53.60 -0.80
35.93 -0.50
Table 3: Ablation Study (Avg@3) of the mid-training data construction on long-context and agent benchmarks. All variants use the same Qwen3-14B backbone, downstream SFT recipe, and evaluation protocol. The trajectory baselines use raw search trajectories, raw code trajectories, or their combination, with an additional masked variant. All mid-training runs use the same token budget.
Figure 4: ICL score gains over Qwen3-14B-Base on long-context (top) and agent (bottom) tasks during mid-training (pp). Training steps are scaled to 40B tokens per run.
Figure 5: Spearman correlations between long-context and agent ICL gains across five Qwen3-14B variants at final mid-training checkpoints, relative to unmasked Raw Trajectories.
Figure 6: Post-SFT Avg@3 gains of Qwen3-14B variants on long-context and agent benchmarks, relative to unmasked Raw Trajectories under the same SFT recipe. Panels use separate color scales.
Setting
SFT Epoch
Long-Context
Agent
Oolong-Synth
GraphWalks
CorpusQA
BC
NL2Repo
SWE-Pro
None
2
53.17 +0.0
24.12 +0.0
55.93 +0.0
12.53 +0.0
6.23 +0.0
24.21 +0.0
ACC (SFT)
2
56.00 +2.83
30.62 +6.50
57.89 +1.96
10.16 -2.37
7.00 +0.77
27.22 +3.01
TrajLong (SFT)
2
56.83 +3.66
28.04 +3.92
59.27 +3.34
13.56 +1.03
9.40 +3.17
31.11 +6.90
1
55.83 +2.66
31.64 +7.52
64.44 +8.51
11.48 -1.05
14.16 +7.93
34.15 +9.94
2
58.50 +5.33
32.30 +8.18
63.83 +7.90
11.77 -0.76
15.03 +8.80
36.43 +12.22
Table 4: Training-stage and SFT-epoch comparisons on Qwen3-14B (Avg@3). None denotes SFT on the original data only. Subscripts show changes from None (pp); bold marks column maxima.
Appendix figures & tables17 assets
Supplementary material from the paper’s appendix.
Appendix
Criterion
Assessment
Selection principle
Format validity
Rules
∙ Nonempty user request and assistant text or actions. ∙≥5 non-system messages; ≥1 matched tool-call/response pair. ∙ Remove agent-harness boilerplate and tool-output formatting noise.
∙ Reject ≥4 consecutive calls with identical tools and arguments. ∙ Reject error-marked responses exceeding 70% of all tool responses.
LLM
∙ High-value patterns: error recovery and progressive exploration. ∙ Low-value patterns: unproductive loops, dead ends, and irrelevant actions. ∙ Ratios: summed annotated segment lengths / total nodes; reject low-value ratio >50% . ∙ Clarify user instructions and refine tool-response content.
Appendix
Table 5: Trajectory cleaning criteria.
Domain
Records
Tokens (B)
Sampling (%)
Token mix (%)
Nemotron Interactive
278,880
1.220
37.83
40.01
Nemotron Tool Calling
707,052
3.804
36.94
36.86
Nemotron SWE
5,115
0.309
12.47
10.07
UltraChat
207,865
0.247
7.58
8.08
Nemotron Search
5,968
0.152
5.18
4.97
Total
1,204,880
5.732
100.00
100.00
Appendix
Table 8: SFT corpus statistics and mixture proportions.
Benchmark
Task
Description
Format
Length setting
Size
MRCR-ICL
Co-reference resolution
Reproduce an ordinally specified response among repeated requests, with the required prefix.
TC
≤ 256K
1,711
RULER-ICL
RULER-MultiKey
Retrieve the queried key’s value among key–value pairs and distractors.
TC
4K–128K
300
Multivalue
Retrieve all values associated with the queried key.
TC
4K–128K
300
QA1
Answer a SQuAD question using a relevant passage among distractors.
TC
4K–128K
300
QA2
Combine supporting documents to answer a HotpotQA question.
TC
4K–128K
300
CWE
Identify the 10 most frequent words in a long numbered list.
TC
4K–128K
300
Appendix
Table 9: Long ICL benchmark overview. MCQ denotes multiple-choice question answering; TC denotes text completion. Length denotes nominal settings or subset labels, except for BrowseCompLong-ICL, which reports the observed complete-prompt token range; S/M/L denotes short, medium, and long subsets. Size counts evaluated queries, excluding ICL demonstrations. MRCR includes the 2-, 4-, and 8-needle settings. RULER covers six selected subtasks, each evaluated at 4K, 8K, 16K, 32K, 64K, and 128K. BrowseCompLong-ICL uses three randomly selected demonstrations; its complete prompts span approximately 20K–243K tokens in the verified run.
Benchmark
Description
Format
Size
Bug Localization
Locate the faulty line using an issue description and numbered code.
TC
114
Bug Fixing
Select the correct replacement for a specified faulty line.
MCQ
114
Code Summary
Identify the summary that matches a code snippet’s behavior.
MCQ
235
Planning Preference
Choose the next action from the task goal and interaction history.
MCQ
181
Multi-hop Replanning
Select a feasible continuation or task status after tool failure.
MCQ
210
Tool Selection
Match a user request to a tool using candidate descriptions.
Table 12: Downstream SFT configuration. The positional configuration is retained from mid-training, while training sequences are capped at 128K tokens.
Question category
Reasoning requirement
Cross-document or version comparison
Identify shared conclusions, differences, or changes across related documents or versions.
Multi-hop fact composition
Use information from one source to locate and interpret the next source in a chain.
Quantitative reasoning
Combine numerical facts to compute a derived quantity with a meaningful interpretation.
Aggregation
Count, rank, deduplicate, or identify extrema across related records.
Relational reasoning
Connect evidence through calls, data flow, or relationships between definitions and their use.
Conditional reasoning
Infer an outcome under stated conditions or a hypothetical change.
Appendix
Table 13: Question and answer categories used to construct MultidocQA data. Question categories guide the reasoning task, while answer categories specify response requirements. Only compatible combinations are used.
Snapshot subtype
Question target
After edit
Recover the complete file immediately after its K -th successful Edit.
Before edit
Recover the complete file immediately before its K -th successful Edit, incorporating preceding updates.
Final state
Recover the complete file at the end of its reconstructible state history.
Suffix rollback
Recover the file after undoing the last R successful Edits in a consecutive suffix, without crossing a Write or Delete boundary.
Provenance subtype
Question target
Final-state last writer
Identify the Edit or Write that last wrote a target fragment still present in the final state.
Appendix
Table 14: Question subtypes and answer formats used to construct State Tracking data.
Models
Oolong-Synth
Avg@3
BoN@3
Frontier Models
Gemini-2.5-Flash-Thinking
78.17
91.00
QwenLong L1.5-30B-A3B
75.50
89.00
GPT-OSS-120B
68.00
84.50
Our Models
Appendix
Table 15: SFT performance on Oolong-Synth. Subscripts show gains over the corresponding Qwen3 baseline (pp). The best scores for each backbone LLM are bolded .
Models
Search
Tool Use
Coding
BC
BC-ZH
WideSearch
FSC-V2
SealQA
MCP-Atlas
SkillsBench
WebArena
TB 2.1
NL2Repo
SWE-Verified
SWE-Pro
Frontier Models
Gemini-2.5-Flash-Thinking
12.72
43.42
44.09
46.44
38.75
47.47
16.67
51.98
34.83
12.40
48.60
24.08
QwenLong L1.5-30B-A3B
6.48
21.35
45.14
32.51
28.02
62.77
4.17
36.12
4.49
15.09
43.60
19.56
GPT-OSS-120B
37.91
38.41
51.01
55.75
34.23
69.83
-
43.23
22.47
6.88
67.00
40.63
Our Models
Appendix
Table 16: Overall SFT performance (BoN@3, %) across diverse search, tool-use, and coding agentic benchmarks. BC-ZH, FSC-V2, and TB 2.1 denote BrowseComp-ZH, FinSearchComp V2, and Terminal-Bench 2.1, respectively. MCP-Atlas reports unthresholded claim coverage; scoring and three-trial aggregation are defined in Appendices B.3 and C.2 . Empty cells indicate unavailable or invalid evaluation results.
Figure 9: General ICL performance after mid-training on ten evaluations. Outer panels show task scores on individually zoomed axes; the center shows their unweighted mean.
Figure 10: Long-context and Agent ICL accuracy gains over Raw Trajectories (pp). Dashed lines separate the Raw reference row.
Figure 11: Correlations between long-context ICL gains and downstream agent gains after SFT. Each of the five panels contains six matched training variants. Axes show gains over Qwen3-14B-Base and SFT without mid-training, respectively (pp). Dashed lines are descriptive linear fits; ρ denotes Spearman correlation.
Figure 12: Long-to-Agent correlations after SFT (BoN@3) across five Qwen3-14B variants: Retrieval, MultidocQA, State Tracking, All, and Raw Trajectories. Cells show Spearman ρ with average ranks for ties on a shared [−1,1] scale.
TrajLong / Retrieval
User
Run today’s SEO workflow for example-store.example. Review the saved history and strategy, rotate the target markets across India, Sri Lanka, and Nepal, and avoid duplicate publications.
… [1 assistant turn omitted; ≈ 2.9k tokens] …
Assistant
Answer: Today is Monday, so I will check the site’s indexing status and recent articles, then prepare the weekly SEO report.
Result 1: finding your goldmine: the ultimate guide to successful dollar store site selection …
Appendix
Table 17: A TrajLong (Retrieval) example.
TrajLong / MultidocQA
You are given a set of evidence items below, each marked with a unique ID, together with its title and version when available. Read the evidence carefully, identify the items relevant to each question, and answer the question or questions that follow. Evidence IDs are provided to help locate and distinguish evidence items. Use them to keep track of the relevant evidence while solving each question. Follow each question’s own output requirements.
… [103 additional evidence items omitted from this compact display] …
[EVIDENCE id=file-d4ba5ce340e9 | title=AuthRepository.kt | version=1] … class AuthRepository(…) { … private val api: AuthApi by lazy { ApiClient.createApi(AuthApi::class.java) } suspend fun loginWithPassword(…): Result<LoginResponse> = safeCall { val response = api.loginWithPassword(LoginRequest(phone, password)); … } suspend fun loginWithSms(…): Result<LoginResponse> = safeCall { val response = api.loginWithSms(SmsLoginRequest(phone, code)); … } … }
[EVIDENCE id=file-ce5214a29b14 | title=AuthApi.kt | version=1] … interface AuthApi { @POST("/api/v1/auth/tenant/login") suspend fun loginWithPassword(…) … @POST("/api/v1/auth/sms/send") suspend fun sendSmsCode(…) … @POST("/api/v1/auth/sms/login") suspend fun loginWithSms(…) … … }
[EVIDENCE id=file-f879713c7014 | title=AppNavGraph.kt | version=1] … LoginScreen(onLoginSuccess = { val user = authState.user val homeRoute = when { user?.isAdmin() == true -> Screen.AdminHome.route else -> Screen.WorkerHome.route } navController.navigate(homeRoute) { popUpTo(Screen.Login.route) { inclusive = true } } }) …
[EVIDENCE id=file-8c0dc44e8e97 | title=NotificationApi.kt | version=1] … @GET("/api/v1/notifications") suspend fun getNotifications( @Query("page") page: Int = 1, @Query("limit") limit: Int = 20, @Query("is_read") isRead: Boolean? = null): PaginatedResponse<NotificationResponse> …
Appendix
Table 18: A TrajLong (MultidocQA) example.
TrajLong / State Tracking
The following is a historical agent trajectory enclosed between [BEGIN_OF_TRAJECTORY] and [END_OF_TRAJECTORY].
[BEGIN_OF_TRAJECTORY]
System
You are an AI coding assistant.
… [20 assistant turns omitted; ≈ 28.0k tokens] …
User
Can we adjust the font size? It looks a little too small.
Recent development of agents has renewed demand for long-context reasoning capacity of LLMs. However, training LLMs for this capacity requires costly long-document curation or heuristic context synthesis. We observe that agents produce massive trajectories when solving problems, invoking tools and receiving environment observations across many turns. The evidence needed to answer the original question is thus scattered throughout these turns, requiring integration of distant context segments. Nevertheless, standard agent SFT masks tool responses and only trains turn-level tool selection, creating a supervision blind spot where these scattered signals go unused. We propose Agent Context Compilation (ACC), which converts trajectories from search, software engineering, and database querying agents into long-context QA pairs that combine the original question with tool responses and environment observations gathered across multiple turns, training the model to answer directly without tool use. This makes the dependencies between the question and the evidence explicit, enabling direct supervision of long-context reasoning over distant segments without additional annotation. ACC is a simple but effective approach that can be combined with any existing long-context extension or training method, providing scalable supervised fine-tuning data. We validate ACC on long-range dependency modeling tasks through MRCR and GraphWalks, challenging benchmarks requiring cross-turn coreference resolution and graph traversal over extended contexts. Training Qwen3-30B-A3B with ACC achieves 68.3 on MRCR (+18.1) and 77.5 on GraphWalks (+7.6), results comparable to Qwen3-235B-A22B, while preserving general capabilities on GPQA, MMLU-Pro, AIME, and IFEval. Further mechanism analysis reveals that the ACC-trained model exhibits task-adaptive attention restructuring and expert specialization.
Qisheng Su, Zhen Fang, Shiting Huang +8
MoE Key Lab of BIPC, University of Science and Technology of China · Shanghai Innovation Institute · Shanghai AI Laboratory
This paper introduces KLong, an open-source LLM agent trained to solve extremely long-horizon tasks. The principle is to first cold-start the model via trajectory-splitting SFT, then scale it via progressive RL training. Specifically, we first activate basic agentic abilities of a base model with a comprehensive SFT recipe. Then, we introduce Research-Factory, an automated pipeline that generates high-quality training data by collecting research papers and constructing evaluation rubrics. Using this pipeline, we build thousands of long-horizon trajectories distilled from Claude 4.5 Sonnet (Thinking). To train with these extremely long trajectories, we propose a new trajectory-splitting SFT, which preserves early context, progressively truncates later context, and maintains overlap between sub-trajectories. In addition, to further improve long-horizon task-solving capability, we propose a novel progressive RL, which schedules training into multiple stages with progressively extended timeouts. Experiments demonstrate the superiority and generalization of KLong, as shown in Figure 1. Notably, our proposed KLong (106B) surpasses Kimi K2 Thinking (1T) by 11.28% on PaperBench, and the performance improvement generalizes to other coding benchmarks like SWE-bench Verified and MLE-bench.
Mid-training is increasingly recognized as a critical stage for shaping the capabilities of large language models. Recent work has shown that targeted mid-training can strengthen reasoning-intensive abilities such as math and science, and can also improve agentic capabilities in software-engineering settings. In this work, we study the parallel but less explored agentic capability: general tool use. We present MidTool, an open corpus construction pipeline for agentic tool-use mid-training that combines large-scale web, PDF, and code data with synthesized supervision from real-world tool APIs, MCP skills, and document-grounded workflows. MidTool is designed to teach models how to recognize tool affordances, ground arguments from context, compose tool call workflow, and recover from incomplete information. We mid-train Qwen3-4B-Base and Qwen3-8B-Base on MidTool-Mix, and then apply follow-up post-training with both supervised fine-tuning and reinforcement learning. Compared with baselines, MidTool-Mix consistently improves downstream performance under both SFT and RL on BFCL, tau2-Bench, and MCP Universe. These results suggest that general tool use, like other important LLM capabilities, benefits from dedicated mid-training rather than being left entirely to post-training.
Fengqing Jiang, Yite Wang, Boyi Liu +5
University of Washington · Snowflake · University of North Carolina at Chapel Hill