MidTool: Mid-Training Corpus for Language Models
- MidTool is an open corpus-construction and mid-training pipeline specially designed to imbue language models with general tool-use capabilities, combining filtered web, PDF, and code data with real-world API. API, where the models undergo mid-training before supervised fine-tuning (SFT) and reinforcement learning (RL).
- The MidTool-Mix corpus, comprising 20.3 billion tokens and 11.22 million samples, serves as both a corpus for mid-training and a dataset that teaches effective tool use through comprehensive agentic trajectories and contextual grounding.
- MidTool improves tool-use competence during mid-training, boosting metrics in multi-turn, long-context, and multi-tool scenarios. It also performs exploratory visual tool use, resilience, where outlines of potentialBeginning outcomes.
MidTool is an open corpus-construction and mid-training pipeline for developing general agentic tool-use capabilities in LLMs. It combines filtered web, PDF, and code data with supervision synthesized from real-world APIs, Model Context Protocol (MCP) skills, document-grounded workflows, executable tool interactions, and failure-recovery trajectories. The resulting MidTool-Mix corpus contains 20.3 billion tokens and 11.22 million samples, and is used to mid-train Qwen3-4B-Base and Qwen3-8B-Base before supervised fine-tuning (SFT) and reinforcement learning (RL). Its central thesis is that tool use should be established as a broad capability during mid-training rather than learned almost entirely from narrow post-training traces (Jiang et al., 20 Aug 2026).
1. Concept and motivation
MidTool addresses general tool use as a compound capability rather than as isolated function calling. An agent must recognize tool affordances, identify tool boundaries, select among competing tools, ground arguments in schemas and context, extract parameters from long or noisy sources, compose calls into ordered workflows, request missing information, interpret tool responses, and recover from invalid or incomplete interactions.
The pipeline distinguishes two related deficiencies:
- Grounding deficiency: the model lacks sufficient knowledge of tool purposes, argument requirements, output formats, API relationships, and workflow structure because these are distributed across documentation, manuals, source code, SDKs, REST specifications, and MCP skills.
- Execution deficiency: the model may understand a schema yet fail to preserve turn order, use tool outputs, ask clarification questions, switch tools, or recover from failures.
MidTool therefore treats tool-use competence as a policy over conversational and execution states. The next assistant action may be a natural-language response, a tool selection, schema-valid argument construction, a clarification question, a sequence of calls, or a recovery action. In informal terms, the desired behavior is:
The corpus is intended to provide a broad prior over these behaviors before post-training. Its central data formulation is:
MidTool does not introduce a separate tool-use loss, affordance-classification objective, argument-verification objective, or trajectory-level auxiliary loss. Mid-training uses standard language-model training over a mixed plain-chat corpus. Subsequent SFT and RL are used to optimize downstream tool-use behavior.
The paper’s motivation is consistent with findings from earlier multi-tool systems. MultiTool-CoT showed that GPT-3 could interleave language reasoning with calculator, chemical-reaction, and molar-mass tools, but tool selection and argument construction remained dependent on few-shot demonstrations and free-form generated triggers (Inaba et al., 2023). MidTool instead attempts to shape the underlying model representation before post-training through large-scale exposure to tool-centered knowledge and trajectories.
2. Corpus architecture and source collection
MidTool-Mix is constructed from three principal data sources: technical web pages, PDF documents, and source code. These are supplemented by structured tool artifacts and synthesized agentic trajectories.
Web data
The primary web source is processed Common Crawl data from FineWeb. Multiple dumps from 2020–2025 are sampled to capture current technical material, including API references, SDK documentation, developer guides, troubleshooting pages, CLI instructions, configuration instructions, code-centered discussions, and workflow descriptions.
Web data contributes breadth, terminology, and contextual descriptions of tools. High-recall prescreening uses software-development vocabulary, documentation-oriented URL patterns, and code-like structure. A fastText classifier is trained from LLM-labeled seed data comprising 1 million web documents and 3 million PDF documents. Qwen2.5-7B-Instruct supplies the seed annotations.
PDF data
FinePDFs supplies English-language manuals, product handbooks, platform documentation, and long-form procedural material that may not be represented cleanly in HTML. Because PDF extraction is noisier, PDF data receives stricter filtering and an additional OCR-quality check.
Code data
The code collection contains two GitHub slices. The first targets agent- and MCP-oriented repositories discovered through GH Archive events and filtered by recency, activity, licensing, and agent-related content. The second targets active, high-quality technical repositories in Python, Java, JavaScript, TypeScript, Go, Rust, C/C++, C#, SQL, Shell, and Dockerfile.
The pipeline retains repositories likely to contain libraries, SDKs, frameworks, examples, tutorials, and educational material. It removes personal projects, forks, benchmark repositories, and dataset repositories. A maintained blacklist excludes repositories associated with BFCL, -Bench and -Bench, MCP-Universe, and other tool-use evaluations.
Code preprocessing includes binary and low-value-file exclusion, line-length and line-count heuristics, alphabetic-character-ratio filtering, notebook-to-Python conversion, SHA-256 exact deduplication, and MinHash locality-sensitive hashing for near-duplicate removal. Documentation-like directories such as docs, examples, tutorials, guides, samples, and cookbook receive particular attention.
Structured tool artifacts
Structured tool data consists of REST APIs, API groups, MCP skills, executable tool definitions, schemas, and parameter structures. These artifacts provide explicit tool boundaries and argument specifications and therefore serve as the principal substrate for native schema-grounded trajectory generation.
Quality control
Web and PDF documents undergo language-confidence, length, word-count, symbol-density, estimated-code-ratio, and OCR-quality filtering. MinHash LSH is applied across documents and shards. Code is filtered and deduplicated separately.
The corpus construction also applies contamination controls. Known benchmark repositories are excluded before crawling, and a post-hoc DeCon scan examines web, PDF, teacher-synthesized data, BFCLv3, -Bench, and MCP-Universe overlap. Fewer than 20 candidates are flagged, all from the web slice; manual inspection classifies them as false positives consisting of generic API or function-calling language rather than benchmark examples or reference answers. The paper notes that surface -gram checks cannot rule out semantic or schema-level overlap.
3. Synthesis branches and supervision formats
MidTool uses two complementary synthesis branches: context-grounded trajectory augmentation and native agentic trajectory synthesis.
Context-grounded trajectory augmentation
This branch transforms unstructured or semi-structured web, PDF, and code documents into tool-use supervision while retaining the source context.
Qwen3-235B-A22B-Instruct-2507 assigns documents a quality score and an affordance profile indicating whether they support inference of:
- tool responses;
- API or schema structure;
- code or CLI usage;
- workflow structure;
- tool topology;
- domain terminology.
Higher-quality documents are sent to a rule-based planner that ties augmentation volume to document quality, uses bounded generation budgets, encourages diverse question-answer types, and allows at most one multi-turn chain per document. Generated categories include tool selection, schema-grounded parameter extraction, format-constrained calls, workflow recognition, and multiple or parallel tool use. Trajectory categories include sequential execution, parameter clarification, tool switching, long-context reasoning, and recovery from incomplete information.
The branch teaches mappings of the form:
For example, a technical manual can yield a question about a configuration parameter, an answer containing the required value, and a multi-turn trajectory involving package installation, certificate generation, file writing, and command execution.
Native agentic trajectory synthesis
The native branch starts from executable APIs and MCP skills. Related endpoints or skills are grouped, definitions are parsed, low-signal sources are removed, developer documentation is recovered, tools are normalized into canonical executable schemas, and underspecified argument descriptions are refined.
GPT-5 assigns each source a quality score and a feasibility profile for simple calls, multiple-tool or parallel use, and information-missing situations. A deterministic budget controller allocates trajectory generation according to source quality, tool count, argument structure, feasibility, and desired complexity.
Category-specific generators use GPT-5, GPT-5.1, and GPT-5.2. Generated trajectories are validated for turn ordering, schema grounding, required arguments, and tool-response consistency. Invalid examples are retried with quality-control feedback and discarded if they remain invalid. The branch also incorporates rollout trajectories from Agent World Model synthetic environments and filtered traces from the Nemotron Agentic dataset.
Native trajectories expose multi-turn planning, tool switching, clarification, response-conditioned actions, incomplete information, output interpretation, execution failure, recovery, and long workflows involving real tool interfaces. They are normalized into flattened chat-style sequences containing user messages, assistant actions, tool calls, and tool responses.
Supervision formats
MidTool uses three broad supervision formats:
- Raw source examples: technical web, PDF, and code content that provides knowledge about APIs, commands, configuration, interfaces, and workflows.
- Context-plus-QA examples: a document paired with a question and answer targeting tool selection, argument extraction, format recognition, configuration retrieval, or workflow relations.
- Context-plus-trajectory examples: a document or tool environment paired with a multi-turn trajectory containing planning, calls, responses, clarification, switching, execution, and recovery.
This combination distinguishes MidTool from datasets consisting only of clean, manually authored tool-call demonstrations. The contextual branch teaches grounding from heterogeneous technical sources, while the native branch teaches interaction behavior against executable interfaces.
4. MidTool-Mix composition and training
The final MidTool-Mix corpus contains 20.3 billion tokens, 11.22 million samples, and 2.60 million unique tool names across tool calls.
| Component | Main contribution | Reported share |
|---|---|---|
| Web | Technical sources and QA augmentation | 42% |
| Manuals and full trajectory augmentation | 23% | |
| Code | Raw technical content and code-grounded examples | 26% |
| Native trajectories | Executable API and MCP interactions | 9% |
Slash-separated token values in the corpus accounting denote source tokens and context-grounded augmentation tokens. Web data is dominated by QA augmentation, PDF data contributes the largest fraction of full trajectories, and code remains mostly raw because much of its tool-use signal is already encoded in source files.
Trajectory-containing samples have different profiles by source. Context-grounded web, PDF, and code trajectories tend to contain more assistant steps and tool calls per user turn, whereas native trajectories contain more user turns and can reach 69 turns. Maximum tool-call counts reach 72 for web, 78 for PDF, 103 for code, and 66 for native trajectories.
The tool inventory has a substantial long tail. Keyword-based categories include code execution, shell, and DevOps; list and get operations; filesystem operations; modification; creation; search and lookup; AI, NLP, and machine learning; web and HTTP APIs; databases and SQL; hardware and sensors; and domain-specific tools.
Mid-training
The principal models are Qwen3-4B-Base and Qwen3-8B-Base. Mid-training uses ArcticTraining on 32 H200 GPUs for one epoch with an 8,192-token maximum sequence length, AdamW, learning rate , betas , weight decay 0.01, a WSD learning-rate schedule, 50 warmup steps, and a global packed token batch of 4 million tokens.
The paper does not specify a tool-specific mid-training objective. MidTool-Mix is trained as a mixed plain-chat corpus using standard language-model training.
Follow-up SFT
SFT uses a sampled 100,000-example tool-use subset from TOUCAN. The maximum sequence length is 32,768 tokens, with AdamW, learning rate , betas 0, weight decay 0.01, cosine scheduling, warmup ratio 0.001, and training batch size 128.
Follow-up RL
RL uses 526 synthetic tool-use environments from Agent World Model and a VeRL-style GRPO implementation. Training uses eight B200 GPUs, 64 training steps, learning rates of 1 for the 4B model and 2 for the 8B model, data and PPO minibatches of 32, 16 rollouts per prompt, KL coefficient 0.001, entropy coefficient 0, high clip ratio 0.28, history limit 3, and a maximum of 20 agent turns.
Four principal recipes are compared at each model size:
- Base model plus SFT.
- Base model plus SFT and RL.
- Base model plus MidTool-Mix and SFT.
- Base model plus MidTool-Mix, SFT, and RL.
5. Evaluation and empirical results
MidTool is evaluated on BFCLv3, verified 3-Bench, and MCP-Universe. These benchmarks span function calling, multi-turn interaction, missing functions and parameters, long-context behavior, hallucination, airline, retail, telecom, browser automation, finance, location, multi-server tasks, and web search.
BFCLv3
MidTool-Mix yields its strongest and most consistent gains on multi-turn, missing-parameter, and long-context settings.
| Model configuration | BFCL overall |
|---|---|
| Qwen3-4B + SFT | 39.73% |
| Qwen3-4B + SFT + RL | 39.51% |
| Qwen3-4B + MidTool + SFT | 50.25% |
| Qwen3-4B + MidTool + SFT + RL | 54.18% |
| Qwen3-8B + SFT | 47.62% |
| Qwen3-8B + SFT + RL | 45.79% |
| Qwen3-8B + MidTool + SFT | 51.12% |
| Qwen3-8B + MidTool + SFT + RL | 55.12% |
For the 4B model, MidTool plus SFT improves BFCL overall from 39.73% to 50.25%, a 10.52-point gain. MidTool plus SFT and RL reaches 54.18%, compared with 39.51% for the corresponding non-mid-trained RL model. For the 8B model, the corresponding gains are 3.50 and 9.33 points.
The 4B MidTool model with SFT and RL increases multi-turn-base performance to 34.50%, missing-function performance to 24.50%, missing-parameter performance to 20.50%, and long-context performance to 31.00%. The 8B model with MidTool, SFT, and RL reaches 50.50% on multi-turn base, 33.50% on missing functions, 25.00% on missing parameters, and 41.50% on long context.
4-Bench
MidTool improves interactive completion, particularly in retail and at Pass@4.
| Model configuration | Overall Pass@1 | Overall Pass@4 |
|---|---|---|
| Qwen3-4B + SFT | 8.54% | 20.50% |
| Qwen3-4B + MidTool + SFT | 12.23% | 28.06% |
| Qwen3-4B + MidTool + SFT + RL | 19.96% | 38.49% |
| Qwen3-8B + SFT | 10.43% | 28.06% |
| Qwen3-8B + MidTool + SFT | 14.75% | 34.89% |
| Qwen3-8B + MidTool + SFT + RL | 21.31% | 39.57% |
The 4B model’s overall Pass@1 rises from 8.54% with SFT alone to 12.23% with MidTool and SFT and to 19.96% with subsequent RL. The 8B model follows the same pattern, reaching 21.31% after MidTool, SFT, and RL. Telecom remains difficult and unstable, indicating that general tool-use priors do not solve every domain-specific interactive behavior.
MCP-Universe
MidTool improves MCP interaction, particularly financial and location tasks, but does not solve multi-server or web-search tasks.
| Model configuration | Overall MCP score | Overall pass rate |
|---|---|---|
| Qwen3-4B + SFT | 13.20 | 1.68% |
| Qwen3-4B + MidTool + SFT | 18.66 | 5.03% |
| Qwen3-4B + MidTool + SFT + RL | 23.80 | 10.06% |
| Qwen3-8B + SFT | 15.18 | 3.35% |
| Qwen3-8B + MidTool + SFT | 17.82 | 3.91% |
| Qwen3-8B + MidTool + SFT + RL | 25.16 | 9.50% |
For the 4B model, MidTool plus SFT increases the overall MCP score from 13.20 to 18.66 and the pass rate from 1.68% to 5.03%. Adding RL reaches 23.80 and 10.06%, compared with 14.50 and 2.23% for the corresponding non-mid-trained RL model. For the 8B model, MidTool plus SFT plus RL reaches 25.16 and 9.50%, compared with 15.67 and 5.03% for the non-mid-trained RL model.
The MCP-Universe web-search subset remains at score 0.00 and pass rate 0.00% for all reported systems. The paper interprets this as a capability boundary: schema grounding, argument construction, and basic workflow composition do not automatically produce deep-search behavior requiring iterative query refinement, hypothesis maintenance, source reconciliation, evidence sufficiency judgments, and grounded synthesis.
Exploratory visual-tool transfer
A pilot evaluates transfer from text-only tool-use mid-training to visual tool use using Gemma-3-4B-PT, 37.5K FineVision samples, and a reconstructed VisualToolBench harness. No visual tool-use data is included during mid-training or SFT.
| Model configuration | Tool success | Overall ARS |
|---|---|---|
| Gemma3-4B-PT + SFT | 0.5863 | 0.0567 |
| Gemma3-4B-PT + MidTool + SFT | 0.7231 | 0.0661 |
The result is explicitly exploratory. It suggests transfer beyond text-only APIs, while also showing that successful invocation does not guarantee that returned visual evidence is incorporated into the final answer.
6. Ablations, interpretation, and limitations
Ablation findings
Ablations separate raw processed data, native trajectories, context-grounded trajectories, and generic mid-training.
| Mid-training corpus | BFCL overall | 5 Pass@1 | MCP score | MCP pass |
|---|---|---|---|---|
| No mid-training | 39.73 | 8.54% | 13.20 | 1.68% |
| Dolmino-20BT | 43.10 | 7.37% | 5.41 | 0.00% |
| Processed data without trajectories | 42.30 | 7.30% | 12.20 | 3.03% |
| Native trajectories only | 47.59 | 4.23% | 6.80 | 1.12% |
| Context-grounded trajectories only | 44.66 | 8.99% | 8.46 | 1.12% |
| Complete MidTool-Mix | 50.25 | 12.23% | 18.66 | 5.03% |
Native trajectories provide a larger BFCL gain than context-grounded trajectories alone, indicating their value for precise function calling. Context-grounded trajectories perform better on 6-Bench and provide stronger transfer to MCP settings. The complete mixture is the only configuration that improves all eight reported metrics over no mid-training.
Dolmino-20BT improves BFCL but transfers poorly to MCP-Universe, suggesting that generic reasoning or instruction-style mid-training does not supply the same tool-specific prior. The ablation therefore supports a complementary role for raw technical data, contextual supervision, and executable trajectories.
Optimization and generalization
MidTool-initialized models begin downstream SFT with the lowest loss, descend fastest early in training, and maintain the best loss for nearly the entire run. During AWM RL, they begin with higher reward and improve faster in early training. Non-mid-trained models partially catch up in the same environment, but the benchmark gap remains, which the paper interprets as evidence for stronger out-of-environment generalization.
The 8B model is generally stronger than the 4B model after complete training on difficult multi-turn BFCL categories and several MCP categories. However, scale alone does not explain the results: MidTool-trained 4B models outperform larger or officially post-trained references in some settings, indicating that data composition and inductive bias are significant factors.
Capability boundaries
MidTool improves tool recognition, schema grounding, argument construction, clarification, multi-turn execution, and recovery-related behavior. It does not substantially solve deep-search-style agency, and its coverage remains limited for highly specialized vertical workflows, software engineering agents, complex visual interaction, and safety-sensitive actions.
The corpus contains executable commands, filesystem operations, browser interactions, finance-like tools, and mutating actions. Incorrectly learned behavior could produce destructive commands, invalid configurations, unintended state changes, unsafe API calls, privacy failures, or security failures. The paper evaluates capability rather than providing a comprehensive safety framework.
Limitations
Several limitations constrain interpretation:
- Teacher dependence: contextual synthesis relies on Qwen3-235B-A22B-Instruct-2507, while native trajectory generation uses GPT-5-family models. Their errors and biases may propagate into the corpus.
- Incomplete mixture controls: the study does not exhaustively compare equal-compute alternatives, QA without source context, native trajectories scaled to the full token budget, or matched-budget branches.
- Benchmark leakage risk: blacklist and DeCon checks reduce obvious contamination but cannot exclude all semantic or schema-level overlap.
- Limited domain coverage: general tool-use gains do not establish performance on deep research, safety-sensitive actions, software engineering, or complex visual interaction.
- Evaluation scale: MCP-Universe scores and pass rates are low for some categories, and the paper does not report confidence intervals.
- Unresolved co-design: the experiments hold SFT and RL recipes mostly fixed and do not fully study interactions between MidTool-Mix, larger SFT datasets, RL environments, and reward design.
- Tool-use safety: the pipeline contains executable and mutating operations but does not present a complete mechanism for permission control, sandboxing, risk-sensitive planning, or safe abstention.
MidTool’s principal contribution is therefore data-centric. It treats general tool use as a broad competence involving technical knowledge, affordance recognition, schema grounding, workflow planning, execution, clarification, and recovery. Its empirical results indicate that dedicated mid-training can make later SFT and RL more effective, especially for multi-turn, missing-parameter, long-context, and unfamiliar-tool settings. At the same time, the persistent failure of web search and other exploratory tasks shows that general tool-use priors do not by themselves yield deep agency. Further progress requires specialized data and objectives for evidence gathering, long-horizon planning, tool-output grounding, safety, and adaptive execution.