What is FastContext
FastContext is Microsoft's open-source lightweight code repository exploration model, designed specifically for coding Agents. The model decouples repository browsing from task solving. The main Agent delegates read-only exploration to FastContext via natural language queries. FastContext then calls the Read/Glob/Grep tools in parallel and ultimately uses compact file paths and line number references (<final_answer>) to return focused evidence, freeing the main Agent from accumulating irrelevant code snippets in its context. In SWE-bench multilingual, Pro, and SWE-QA evaluations, the project improves end-to-end success rates by up to 5.5% while reducing the main Agent's Token consumption by up to 60.3%.
Main Features of FastContext
- Delegated Exploration: The main Agent delegates natural language context queries to FastContext and focuses on code editing and testing itself, avoiding exploration process contamination of the main context.
- Read-Only Tool Set: Built in with three language-agnostic tools, Read, Glob, and Grep, it only performs file reading and searching and prohibits any code modification, ensuring repository safety.
- Parallel Tool Calls: It launches multiple independent reads and regular expression searches simultaneously within a single turn, covering complementary hypothesis paths and shortening the number of exploration turns before the first edit.
- Compact Evidence Output: Returns structured
<final_answer>reference blocks, containing only relevant file paths and precise line number ranges, with no redundant exploration trajectories. - Trainable Explorer: Provides dedicated models with 4B–30B parameters, supports supervised fine-tuning (SFT) and task-oriented reinforcement learning (RL), and adapts to repositories of different scales and domains.
Technical Principles of FastContext
- Sub-Agent Delegation Architecture: FastContext adopts a runtime delegation mechanism, completely separating repository exploration from the main Agent's solving trajectory. The main Agent only needs to send natural language queries. FastContext iteratively performs read-only exploration in an independent environment and ultimately returns focused evidence, preventing exploratory reads and searches from occupying the main Agent's context window.
- Three-Tool Parallel Exploration: The sub-Agent exposes only three language-agnostic tools: Read, Glob, and Grep. At each round of decision-making, the model can launch multiple independent tool calls in parallel, simultaneously covering path discovery, symbol search, and content reading, dynamically adjusting the next round's search strategy based on observed results to achieve multi-round evidence collection.
- Compact Reference Output Protocol: When exploration terminates, FastContext outputs structured
<final_answer>blocks, containing only relevant file paths and precise line number ranges, optionally with a brief relevance note. This format allows the main Agent to directly consume focused context without processing lengthy exploration trajectories. - Two-Stage Training Strategy: The exploration model is trained in two stages: supervised fine-tuning (SFT) and reinforcement learning (RL). In the SFT stage, 2,954 examples are constructed from Sonnet 4.6 trajectories, covering three types of behavior: first-round parallel search, multi-round evidence collection, and precise line number referencing. In the RL stage, GRPO is used for optimization to align the model with actual task objectives.
Follow WeChat and reply "Open Source" to join theAI Open Source Project Communication Group
How to Use FastContext
- Environment Preparation: Install Python 3.12+, use
uvto manage dependencies, and runuv tool install .to install the CLI. - Configure Model Endpoint: Set up an OpenAI-compatible chat completion endpoint:
export BASE_URL、export MODEL、export API_KEY。 - Run exploration query: In the target repository root, run
fastcontext --query "定位请求验证逻辑" --max-turns 6to get compact references. - Integrate into the main Agent: Call programmatically via
make_fastcontext_agent(), setcitation=Trueto return only machine-readable reference blocks. - End-to-end evaluation: Copy
.envto configure the main Agent and FastContext credentials, runbench_mini_swe_agent.pyto reproduce SWE-bench results.
FastContext's core advantages
-
Decoupling and cost reduction: Move time-consuming and token-consuming repository browsing out of the main Agent's trajectory, making the main Agent's context cleaner and its reasoning more focused.
-
Efficient small model: After RL training, the 4B parameter model brings a +5.5 point improvement to GPT-5.4 on SWE-bench Pro, with extremely low token overhead.
-
Parallel acceleration: Parallel multiple tools in a single round significantly shortens the number of exploration rounds and reduces the average wait before the first edit.
-
General and pluggable: Served via an OpenAI-compatible API, it can be integrated into any main Agent framework such as Mini-SWE-Agent, Claude Code, Cursor, etc.
-
Open source and reproducible: Fully releases SFT/RL training scripts, evaluation pipeline, and model weights, supporting secondary training by the community.
FastContext's project address
- GitHub repository:https://github.com/microsoft/fastcontext
- HuggingFace model library:https://huggingface.co/collections/microsoft/swe-fastcontext
- arXiv technical paper:https://arxiv.org/pdf/2606.14066
Comparison of FastContext with similar competitors
| Comparison dimension | FastContext | SWE-Pruner |
|---|---|---|
| Core positioning | An independent repository exploration sub-Agent, primarily front-loaded to retrieve focused evidence for the main Agent | A context pruner inside the main Agent, post-processing to compress accumulated redundant content |
| Relationship with the main Agent | External delegation, with the exploration trajectory fully isolated and not polluting the main context | Embedded in the main Agent's reasoning process, performing pruning within the main context |
| Execution timing | First round of parallel search before editing, returning precise references after multiple iterations | After the main Agent has generated a large number of reads, compress the historical context |
| Output form | Structured <final_answer> file-line references, directly consumable |
Pruned context fragments, which still need to be filtered by the main Agent |
| Token saving path | Prevents irrelevant code from entering the main Agent's history, saving up to 60.3% | Reduces the length of context that has already entered the history, with the savings limited by the amount of prior exploration |
| Training method | Dedicated 4B–30B models trained with SFT and task-oriented RL | Based on heuristics or compression strategies, usually reusing the main model |
| Applicable scenarios | First-time localization in large repositories, cross-file dependency queries, low-resource edge deployment | Context load reduction after the main Agent has performed extensive exploration |
FastContext's application scenarios
-
Issue fixing in large codebases: Quickly locate Bug-related files and functions in million-line repositories, reducing manual browsing.
-
Cross-file refactoring assistance: Provide the main Agent with precise line-level citations, supporting cross-module dependency analysis and safe refactoring.
-
Code Review and QA Answers: Answer questions like where a certain feature is implemented, directly providing the location of evidence without needing to read the entire file.
-
Low-Resource Agent Deployment: The 4B explorer can run at the edge or locally, providing low-cost context services for the main Agent.
-
Agent Training Data Generation: Use FastContext's SFT/RL pipeline to train specialized exploration models for specific enterprise codebases.