TrajLong: Co-Designing Agentic and Long-Context Supervision for Mid-Training
Organizations: The Hong Kong University of Science and Technology (Guangzhou) · Hunyuan Team, Tencent · Peking University
Abstract
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
| 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 | ||||||||||
| 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 | ||||||||||||
| 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 |
| 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 | |
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. non-system messages; matched tool-call/response pair. Remove agent-harness boilerplate and tool-output formatting noise. |
| Task completeness | Rules + LLM | Remove dangling terminal calls; reject LLM-labeled incomplete workflows. Allow completed attempts with explicit external constraints. |
| Quality | Rules | Reject 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 . Clarify user instructions and refine tool-response content. |
| 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 |
| 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 |
| 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. | MCQ | 103 |
| Parameter | Configuration |
|---|---|
| Maximum sequence length | 262,144 tokens |
| RoPE base | 16,000,000 (no additional scaling) |
| Optimizer | AdamW |
| Adam , ; | ; |
| Peak / minimum learning rate | / |
| Learning-rate schedule / warmup | Cosine / 10% |
| Parameter | Configuration |
|---|---|
| Maximum sequence length | 131,072 tokens |
| RoPE base | 16,000,000 (no additional scaling) |
| Optimizer | AdamW |
| Adam , ; | ; |
| Peak / minimum learning rate | / |
| Learning-rate schedule / warmup | Cosine / 3% |
| 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. |
| Snapshot subtype | Question target |
|---|---|
| After edit | Recover the complete file immediately after its -th successful Edit. |
| Before edit | Recover the complete file immediately before its -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 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. |
| 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 | ||
| 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 | ||||||||||||
| 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. |
| Tool Call: web_search({ "query": "site:example-store.example", "max_results": 10 }) | |
| Observation | [example-store.example (search results)] |
| Result 1: finding your goldmine: the ultimate guide to successful dollar store site selection … | |
| 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> … |
| 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. |
| Assistant | Tool Call: Read({"file_path": "…/src/renderer/index.css"}) |
LLM Agent Training
Large language model agent training teaches models to plan, use tools, and learn from multi-step interaction with environments.
See all 588 papers