Improving Terminal Task Performance with a 27B Model: A Practical Guide
This article explains how to improve a 27B model's performance on terminal and software engineering tasks without rebuilding the base model. It covers why long-horizon dependencies and asymmetric action costs make these tasks difficult, and how combining asynchronous reinforcement learning with LoRA-based parameter-efficient fine-tuning reshapes tool-use behavior. You will find details on reward design, environment setup, data mixing, evaluation practices, and deployment of the resulting adapter, along with observed gains in accuracy, tool-call efficiency, and token cost.
1. Why Terminal Tasks Are Hard for LLMs
Terminal and software engineering tasks demand something fundamentally different from ordinary question answering. The model must repeat an observe-decide-act-observe loop across a long chain: read directory structures, search for keywords, locate the target function, modify code, run tests, and keep fixing based on errors. Two characteristics stand out.
First, long-range dependency. The information that actually determines success often appears in test output dozens of steps later. The model must keep early observations within its effective attention span; otherwise it “forgets what it already searched” and repeats the same lookups.
Second, asymmetric action cost. A wrong search or a pointless re-run costs far more than a wrong piece of text generation, because it consumes environment interaction turns and execution time. Without an explicit efficiency constraint, the model tends to fall back on the most naive but wasteful strategy: exhaustive searching and repeated re-runs until it hits the step limit and fails.
A typical case from the original practice illustrates the point. The base model searched repeatedly and re-ran code on the same problem, exhausting a budget of one hundred steps without converging. The adapted version went straight to the target function, modified the implementation, ran the tests, and fixed the last failing case within a single-digit number of tool calls. The gap does not come mainly from “more knowledge” but from a better behavioral strategy.
2. Core Idea: Reshape Tool Use, Not the Model
The conventional approach is continued pre-training or full-parameter fine-tuning to “pour” domain knowledge into the model. In terminal scenarios this is not cost-effective: domain knowledge changes fast and has a long tail, while full-parameter training is expensive and can degrade general capabilities.
A more pragmatic route keeps the base model unchanged and trains only a low-rank adapter, using reinforcement learning to optimize the model’s interaction policy across three objectives:
- Correctness: whether the task is actually solved (tests pass, state reaches the expected condition);
- Efficiency: whether the same result is achieved with fewer tool turns and shorter output;
- Stability: whether multi-step reasoning stays coherent when explicit thinking mode is off.
The third point matters most. A long chain of thought can raise accuracy, but it brings heavy token generation and latency costs, which is not worthwhile in terminal settings that interact frequently with a real environment. The ideal state is to internalize “what needs to be thought through” as a policy habit rather than externalizing it as verbose reasoning text every time.
3. Training Method: Combining Asynchronous RL with Parameter-Efficient Fine-Tuning
3.1 Algorithm Choice
The practice uses asynchronous reinforcement learning (in the spirit of AsyncGRPO) together with low-rank adaptation (LoRA). Asynchrony addresses the sampling bottleneck of terminal tasks: every sample requires a real execution environment to return results, and latency varies widely, so synchronous waiting leaves compute idle. Asynchronous sampling decouples generation from execution feedback and substantially improves training throughput.
A simplified training loop follows (structure only, not a specific API):
# Pseudocode: async sampling + reward computation + adapter updatefor step in range(max_steps):batch = [env.reset(task) for task in sample_tasks(n=32)]async def rollout(env):traj = []for t in range(max_tool_steps):action = policy.generate(env.observation, thinking=False)if action.is_finish:breakobs, done, info = await env.step(action) # real execution, variable latencytraj.append((action, obs))return score(traj, info)trajectories = await gather(*[rollout(e) for e in batch]) # no waiting for the slowest; compute as results arriveloss = grpo_loss(trajectories)adapter.update(loss) # update low-rank parameters only
3.2 Environment and Task Hosting
Training needs an environment layer that is executable, rollback-capable, and able to run tasks concurrently in batches: each task is wrapped as an isolated sandbox, and a unified execution interface provides file read/write, command execution, and test feedback. In engineering practice this is usually built with containerized sandboxes plus a task orchestration service, where environment state can be snapshotted and reset to avoid cross-task contamination.
3.3 Data Mix
The data combines two task types: harder software engineering repair tasks (on the order of 750) and terminal command and state operation tasks (on the order of 300). The rationale is that software engineering tasks apply long-chain reasoning pressure while terminal tasks build a feel for high-frequency short interactions. The two complement each other and prevent overfitting to a single distribution.
3.4 Reward Design
The reward is a weighted sum of two terms:
- Task correctness reward: the main term, given by test pass status or state validation, a sparse signal close to 0/1;
- Tool efficiency reward: an auxiliary term with a small weight (such as 0.1), penalizing redundant turns and overly long output.
The weight should not be too large, or the model will skip necessary verification steps to “save turns,” producing false positives that look complete but do not pass. Techniques for converging under sparse rewards include ordering tasks from easy to hard, keeping multiple trajectories per task for within-group relative comparison, and truncating overly long trajectories with a negative reward.
4. Results: A Change in Behavior, Not Just Scores
By public evaluation measures, adaptation delivered two kinds of gains.
Accuracy: on the hard software engineering subset, pass rate rose from roughly 40% to roughly 65%; on the terminal task benchmark it improved by about 16 percentage points; on held-out tasks not used for checkpoint selection it also improved by about 16 percentage points, indicating the gains are not memorization of the training set but show some generalization.
Behavior: on tasks both versions completed, the adapted version needed less than half the tool turns of the base model. Compared with the base model running at the maximum thinking budget, the adapted version reached a similar accuracy with thinking off, while generating about one quarter of the tokens.
Together these numbers are the most valuable conclusion: capability gains can come from doing things more skillfully rather than saying more. For production systems this means lower inference cost, shorter task duration, and more controllable context growth.
5. Evaluation and Acceptance: Avoiding Self-Congratulatory Optimization
To make this kind of optimization solid, evaluation design is more easily overlooked than the training algorithm. At least four points are recommended:
- Held-out isolation: tasks used for checkpoint selection must be separate from tasks used in the final report, otherwise the improvement may be selection bias;
- Dual metrics in parallel: report success rate and average tool turns together to prevent trading accuracy for steps;
- Thinking budget comparison: set three baselines (thinking off / medium budget / maximum budget) to verify whether policy internalization actually happened;
- Unified cost accounting: convert generated tokens, environment execution time, and failed retries into one table for easy cross-comparison.
6. Deployment: The Adapter Is Not a Standalone Model
It is important to stress that this artifact is low-rank adapter weights loaded on top of a base model and cannot run on its own. Common deployment patterns include:
- Mounting the adapter in the inference framework, loading and unloading it dynamically per request so multiple tasks share the same base weights;
- Loading it in a standard deep learning inference stack, suitable for offline batch processing and further training;
- Exporting it after quantization aggregation into a general quantized format for local inference runtimes, making deployment easier in resource-constrained environments.
Engineering also requires supporting pieces: a sandbox resource pool with concurrency limits, timeout and idempotency design for tool calls, retention and replay of failed trajectory logs, and instrumentation in monitoring and alerting to track average turns, success rate, and timeout rate. If cloud capabilities are used, container platforms can host sandboxes, object storage can hold trajectories and checkpoints, and logging and monitoring services can track quality metrics.
7. A Reusable Checklist
- Quantify “wasted steps” before optimizing, using the turn distribution to locate redundant stages;
- Make the reward primarily correctness with efficiency as secondary, starting from a small weight and tuning from there;
- Use asynchronous sampling to handle long-tail latency in environment execution;
- Keep the data mixed between long chains and short interactions to avoid a single distribution;
- Report held-out results and cost metrics together;
- Make clear that the adapter depends on the base model, and plan version binding and rollback in advance.
In summary, the key to improving terminal and software engineering tasks is not simply scaling the model or extending the chain of thought, but using parameter-efficient fine-tuning and reinforcement learning to turn “take fewer detours and verify properly” into the model’s default behavior. This path has controllable cost and measurable gains, offering direct reference value for teams that want to lower the barrier to agent deployment.
