推理成本降78%,API成本降97%,北大系创企开源4B上下文压缩模型

Zhidx (WeChat official account: zhidxcom)
Author | Yang Jingli
Editor | Li Shuiqing

Zhidx reported on November 11 that today, Silicon Heart Technology (aiXcoder), an AI coding startup incubated by the Institute of Software Engineering at Peking University, open-sourcedthe context compression model aiXcompact-4B. The model is designed primarily for long-horizon, complex R&D tasks involving coding agents, has only4B parameters, andsupports private deployment on a single A100 40GB GPU.

When aiXcompact-4B performs context compression, it can structurally process a coding agent’s history:preserving key original information,streamlining tool results such as file reads, code searches, and test runs,removing duplicate or no-longer-relevant intermediate records, andgenerating a structured task summary, thereby reducing the Token overhead caused by repeated inputs in subsequent steps at a lower cost.

According to data published by aiXcoder, after aiXcompact-4B was integrated into OpenCode for context compression testing in the Terminal-Bench benchmark, its overall task completionaccuracy was on par with DeepSeek-V4-Pro. In private deployment scenarios, the per-inference GPU cost for specific tasks was78% lower than that of DeepSeek-V4-Pro.

推理成本降78%,API成本降97%,北大系创企开源4B上下文压缩模型

When using API calls, based on published API pricing estimates, the Token cost of a single aiXcompact-4B context compression request is approximately RMB 0.019. Compared with the reference costs of DeepSeek-V4-Pro, GLM-5.3, and Qwen3.8-Max, this is97.30%, 97.08%, and 97.98% lower, respectively. With per-API-call costs reduced by 97%, aiXcompact-4B offers alightweight and economical option for high-frequency context compression.

推理成本降78%,API成本降97%,北大系创企开源4B上下文压缩模型

After context compression, the historical context that agents need to read repeatedly is reduced accordingly. In target task scenarios, aiXcompact-4B can compress historical context to an average of25.89% of its original length, freeing ample context space for the next agent invocation.

推理成本降78%,API成本降97%,北大系创企开源4B上下文压缩模型

Open-source link:

https://github.com/aixcoder-plugin/aiXcompact-4B

1. Agentic coding tasks consume an average of 4.17 million Tokens, making context compression the key to cost control

As AI programming tools such as Claude Code and Codex are used for increasingly complex R&D tasks, agents must continuously read code, invoke tools, and run tests, causing token costs to rise.

A study based on the OpenHands framework and covering eight frontier models found that, in the SWE-bench Verified experiment, a complete agentic coding task consumed an average of approximately 4.17 million tokens—3,500 times the token consumption of single-turn code reasoning and 1,200 times that of multi-turn code conversations—with input tokens accounting for the vast majority of consumption.

This is closely related to how agents work. For example, when adding user registration functionality to an enterprise’s existing system, an agent must first understand the project structure, locate user management and authentication logic, and then modify files, run tests, and continue adjusting based on errors. Throughout this process, code, search results, and execution logs continually enter the context and become the basis for subsequent work. The same historical information may be fed back repeatedly across multiple rounds of reasoning, and as execution steps increase, the token overhead from repeated inputs continues to accumulate.

Beyond cost, early requirements, critical constraints, and confirmed technical decisions are mixed in with large volumes of intermediate records, which may increase the risk that agents overlook important information or lose debugging clues.

Context compaction has therefore become an important engineering component for controlling agent operating costs and supporting the continued execution of long-running tasks. Its core objective is to retain key information from the continuously growing agent execution trajectory, streamline redundant content, reduce the token cost of repeated inputs, and leave more context space for the current code, the latest feedback, and subsequent decisions.

II. Using a Structured Triage Mechanism to Filter Information and Generate a Summary

In the workflow of a coding agent, the developer first states the requirements, the agent analyzes the problem and invokes tools, and the tools then return file contents or execution results. For agents that need to perform tasks continuously, context compaction must strike a balance between saving tokens and preserving key information: too little compaction cannot effectively reduce context overhead, while excessive compaction may cause critical historical steps to be lost and disrupt the structural relationships between code information and tool calls.

aiXcoder believes that effective compaction must both understand the content of the information and preserve the relationships within the context. aiXcompact-4B uses a structured triage mechanism to generate three types of handling decisions for historical trajectories.

推理成本降78%,API成本降97%,北大系创企开源4B上下文压缩模型

The first category is to preserve critical original information. For information that may influence the direction of subsequent code modifications, such as the developer’s core requirements, critical constraints, and important decisions, aiXcompact-4B preserves the original messages in full, reducing the risk that key qualifiers will be weakened during rewriting.

The second category is to condense tool results. File reads, code searches, and test runs often return large volumes of content, but the next step may require only part of it. aiXcompact-4B retains the tool calls and replaces verbose raw outputs with concise text, reducing input tokens while preserving the clues needed to continue diagnosing problems and modifying code.

The third category is to delete records that have lost their reference value. For repeated content or intermediate outputs that are no longer needed, aiXcompact-4B chooses to delete them and performs corresponding validation actions to check whether the key business information and debugging information within them have been preserved in the task summary.

After information filtering is complete, the model also generates a structured task summary recording the user’s intent, key technical information, errors and their fixes, current work, and outstanding tasks. The final output is a sequence of messages that the agent can use to continue execution while maintaining the pairing between tool calls and their returned results.

In terms of its operating principles, aiXcompact-4B can assess the value of information, distinguishing between information that must not be lost, information that can be condensed, and information that is no longer necessary. It reduces repeated token consumption while preserving the context and structure required for the agent to complete subsequent tasks.

III. Trained on Real R&D Trajectories, the 4B Model’s Context Compaction Evaluation Approaches DeepSeek-V4-Pro

aiXcoder says that the judgment capabilities of aiXcompact-4B come from a training approach that combines distillation from a teacher LLM, LoRA fine-tuning of a 4B student model, and structured compression decisions.

aiXcoder states that all of its training data comes from agent execution trajectories in real R&D scenarios.The team first normalizes the trajectories, filters and screens them, and samples compression trigger points. The teacher model then generates reference compression decisions.

After the reference results undergo sample validation and screening, they are used for targeted training of the student model, enabling it to learn how to process historical context in conjunction with development progress and how to preserve the basis for subsequent work in task summaries.

From a technical division-of-labor perspective, distillation transfers the teacher model’s processing capabilities for this task to a specialized student model, while LoRA fine-tuning adapts the model to compression scenarios. Structured decisions further constrain the model’s output format, allowing it to interface with Agent messaging and execution workflows.

In the context-compression-specific evaluation results published by aiXcoder, aiXcompact-4B achieved a composite rule score of 0.7012, close to DeepSeek-V4-Pro’s 0.7332. Its information-retention rule score was 0.4981, essentially on par with DeepSeek-V4-Pro’s 0.4968. The evaluation also showed that aiXcompact-4B had an average retention rate of 25.89%, higher than DeepSeek-V4-Pro’s 18.46%.

推理成本降78%,API成本降97%,北大系创企开源4B上下文压缩模型

IV. Refining the Division of Labor Between Large and Small Models to Support Enterprise-Grade Private Deployment and Engineering Implementation

As AI gradually penetrates enterprise software development workflows, the requirements for model capabilities across different development stages are beginning to diverge, creating room for a more refined division of labor among models. How to assign different models the tasks best suited to them, while maintaining task completion quality and reducing Token consumption and improving compute utilization efficiency, has become an ongoing challenge for enterprises implementing AI-based development.

To address this, aiXcoder has introduced a “large model + small model” collaboration solution: large models focus on requirement decomposition, complex logical reasoning, and architecture design, while specialized small models handle focused tasks with relatively clear boundaries and high invocation frequency, thereby reducing enterprises’ compute costs.

In addition to aiXcompact-4B, aiXcoder has introduced several models with smaller parameter sizes. In the field of software development, aiXcoder has launched aiXcoder-7B for code generation and completion, aiXapply-4B for code-change applications, and models such as aiXpruner-4B for optimizing Token consumption. In addition, aiXcoder is about to release the aiXdecision model for Agent decision-making stages, focusing on judgment and decision support during agent execution.

Conclusion: Context Compression Models Expand the Boundaries of Complex Agent Tasks

By preserving key original information, streamlining tool-return results, and removing records with no reference value, aiXcompact-4B compresses continuously accumulating historical context and generates structured task summaries, reducing the cost of context compression.

As Agents enter longer chains and more complex development tasks, context management will directly affect Token costs and execution continuity. If context compression models can preserve requirements, decisions, and debugging clues while reducing redundant information, they can help Agents break through the limitations imposed by context overhead and take on tasks in more complex scenarios.

(empty)