FastContext - Microsoft's open-source lightweight code repository exploration model
FastContext is a lightweight code repository exploration model open-sourced by Microsoft, designed specifically for programming agents. The model decouples repository browsing from task solving; the main agent delegates tasks to FastContext via natural language queries...
What is FastContext?
FastContext is a lightweight code repository exploration model open-sourced by Microsoft, designed specifically for programming agents. The model decouples repository browsing from task solving. The main agent delegates read-only exploration to FastContext via natural language queries, which in turn calls Read/Glob/Grep tools in parallel, ultimately using compact file paths and line number references (…).<final_answer>This returns focused evidence, preventing the main agent from accumulating irrelevant code snippets in the context. In SWE-bench multi-language, Pro, and SWE-QA benchmarks, the project improved end-to-end success rate by up to 5.5%, while reducing main agent token consumption by up to 60.3%.
The main functions of FastContext
- Commissioned explorationThe main agent delegates natural language context queries to FastContext, focusing on code editing and testing to avoid polluting the main context during the exploration process.
- Read-only toolsetIt includes three language-independent tools: Read, Glob, and Grep. These tools only perform file reading and searching, prohibiting any code modification and ensuring repository security.
- Parallel tool callsMultiple independent reads and regular expression searches can be initiated simultaneously within a single round, covering complementary hypothesis paths and shortening the number of exploration rounds before the first edit.
- Compact Evidence OutputReturn structured
<final_answer>The reference block contains only the relevant file path and precise line number range, with no redundant exploration path. - Trainable explorerProvides dedicated models with 4B–30B parameters, supports supervised fine-tuning (SFT) and task-oriented reinforcement learning (RL), and adapts to repositories of different sizes and domains.
The technical principles of FastContext
- Sub-Agent Delegation ArchitectureFastContext employs a runtime delegation mechanism to completely separate repository exploration from the main Agent's solution path. The main Agent only needs to send natural language queries, while FastContext iteratively executes read-only exploration in an independent environment, ultimately returning focused evidence, thus avoiding exploratory reads and searches occupying the main Agent's context window.
- Parallel exploration using three toolsThe sub-agent exposes only three language-independent tools: Read, Glob, and Grep. During each round of decision-making, the model can initiate multiple independent tool calls in parallel, simultaneously covering path discovery, symbol search, and content reading. Based on the observation results, the model dynamically adjusts the search strategy for the next round, achieving multi-round evidence collection.
- Compact Reference Output ProtocolWhen the exploration terminates, FastContext outputs a structured message.
<final_answer>A block contains only the relevant file path and precise line number range, optionally with a brief description of its relevance. This format allows the main agent to directly consume the focus context without having to process lengthy exploration paths. - Two-stage training strategyThe model was trained in two phases: supervised fine-tuning (SFT) and reinforcement learning (RL). The SFT phase constructed 2,954 examples from Sonnet 4.6 trajectories, covering three types of behaviors: first-round parallel search, multiple rounds of evidence collection, and precise line number citation. The RL phase optimized the model using GRPO to align it with the actual task objective.
Follow us on WeChat and reply with "open source",join inAI open source project discussion group
How to use FastContext
- Environmental preparationInstall Python 3.12 or later, and use...
uvManage dependencies, executeuv tool install .Install the CLI. - Configure model endpointsConfigure an OpenAI-compatible chat completion interface:
export BASE_URL,export MODEL,export API_KEY. - Perform exploratory queryRun in the root directory of the target repository
fastcontext --query "定位请求验证逻辑" --max-turns 6Get compact references. - Integrate into the main agent:pass
make_fastcontext_agent()Call programmatically, setcitation=TrueOnly machine-readable reference blocks are returned. - End-to-end evaluation:copy
.envConfigure the main Agent and FastContext credentials, and run...bench_mini_swe_agent.pyReproduce the SWE-bench results.
FastContext's core advantages
-
Decoupling and cost reductionRemove time-consuming and token-intensive repository browsing from the main agent's path, resulting in a cleaner main agent context and more focused inference.
-
Small model, high efficiencyThe 4B parameter model, after being trained with RL, delivers a +5.5 score improvement to GPT-5.4 on SWE-bench Pro, with extremely low token overhead.
-
Parallel accelerationThe single-round multi-tool parallelism significantly shortens the number of exploration rounds and reduces the average waiting time before the first edit.
-
Universal pluggableIt uses OpenAI-compatible API services and can be integrated with any main agent framework such as Mini-SWE-Agent, Claude Code, and Cursor.
-
Open source and reproducibleFully release SFT/RL training scripts, evaluation processes, and model weights, supporting secondary training by the community.
FastContext project address
- GitHub repositoryhttps://github.com/microsoft/fastcontext
- HuggingFace model libraryhttps://huggingface.co/collections/microsoft/swe-fastcontext
- arXiv technical paper: https://arxiv.org/pdf/2606.14066
Comparison of FastContext with similar products
| Comparison Dimensions | FastContext | SWE-Pruner |
|---|---|---|
| Core positioning | Independent repository exploration sub-agents, primarily front-end agents, focus on evidence retrieval. | The main agent's internal context pruner performs post-processing compression of accumulated redundant content. |
| Relationship with the main agent | External delegation ensures complete isolation of the exploration trajectory, without contaminating the main context. | Embedded into the main agent inference process, pruning is performed within the main context. |
| Timing of Execution | The first round of parallel search before editing, followed by multiple iterations, returns an exact reference. | After the main agent has generated a large number of reads, the historical context is compressed. |
| Output format | Structured <final_answer> File-line quotations can be consumed directly. |
The pruned context fragments still need to be filtered by the main agent. |
| Token saving path | Prevent irrelevant code from entering the main agent history, saving up to 60.3%. | Reducing the length of contexts that have already been incorporated into history, the savings are limited by the amount of exploration done in the early stages. |
| Training methods | 4B–30B dedicated models, trained using SFT and task-oriented RL. | Based on heuristic or compression strategies, the main model is typically reused. |
| Applicable Scenarios | Initial location of large repositories, cross-file dependency queries, and low-resource edge deployment. | The main agent has performed extensive context reduction after exploration. |
Application scenarios of FastContext
-
Large codebase issue fixesQuickly locate bug-related files and functions in a repository with millions of lines of code, reducing manual browsing.
-
Cross-file reconstruction assistantProvides precise line-level references to the main Agent, supporting cross-module dependency analysis and security refactoring.
-
Code review and QA responseWhen answering questions about where a certain function is implemented, simply provide the location of the evidence; there's no need to read the entire file.
-
Low-resource agent deploymentThe 4B explorer can run at the edge or locally, providing low-cost context services to the main agent.
-
Agent training data generation: Leverage FastContext's SFT/RL pipeline to train dedicated exploratory models for specific enterprise codebases.