Open-Source LLM Selection Guide for Coding and Agent Tasks
A practical framework for choosing open-source models for coding and AI Agent workflows: break down your tasks first, evaluate dense versus MoE parameter structures and VRAM requirements, decide whether multimodal input is worth the cost, replace public leaderboards with task-specific scorecards, verify effective long-context usage with needle-in-a-haystack tests, and run generated code safely in sandboxes.
1. Break Down Tasks Before Comparing Models
The first step in model selection is dividing your team’s work into distinct task categories: function completion and unit test generation, repository-level refactoring, cross-file Agent planning, and frontend debugging based on screenshots or design mockups. Different tasks place very different demands on a model. Using a single model for everything usually means overspending on some tasks while underperforming on others.
2. Parameter Architecture: Separate Total Parameters from Active Parameters
Current open-source models fall into two main architectural categories. Dense models use all of their parameters in every inference pass. Mixture-of-Experts (MoE) models activate only a subset of experts per pass. Several mainstream open-source models adopt MoE architectures, but dense models remain widely used, and both deserve a place in your evaluation.
Take DeepSeek-V3 as an example: it has roughly 671B total parameters, with about 37B activated per token. This tells you two things. First, the compute cost of a single inference is mainly determined by active parameters. Second, VRAM requirements must be estimated based on total parameters, because all expert weights need to be loaded into memory.
VRAM usage can be estimated with a rough formula: weight memory ≈ parameter count × bytes per parameter. FP16 uses 2 bytes per parameter; INT4 quantization uses about 0.5 bytes. For 671B parameters, FP16 weights require roughly 1,342 GB of VRAM, and about 335 GB after INT4 quantization. This figure covers weights only — it excludes the KV cache and runtime overhead, so real deployments need additional headroom.
Always confirm a model’s exact parameter count, active parameters, and memory requirements against the official documentation for that specific version. Differences between versions in the same family can be substantial.
3. Modality: Pay Only for Capabilities You Actually Use
Multimodal models that accept image or video input are well suited to frontend debugging, where you need to inspect screenshots, design files, or screen recordings to locate problems. If your workflow involves only code and text, a text-only model is usually cheaper and performs comparably on coding benchmarks.
A practical suggestion: measure what share of your tasks over the past month actually required multimodal input. If that share is very low, the premium for multimodal capability may not be worth paying.
4. Coding and Agent Capabilities: Use Scorecards Instead of Leaderboards
Public leaderboards indicate a model’s general level, but they cannot replace testing on your own codebase. Build a scorecard for each task category. Here is an example:
| Task Type | Candidate Model Traits | Evaluation Metrics | Pass Threshold (Example) |
|---|---|---|---|
| Function completion, unit test generation | Coding-optimized, fast responses | Share of generated code that passes tests | Pass rate ≥ 85% |
| Repository-level refactoring | Strong long-context understanding | Compilation pass rate, regression test failures | Compilation ≥ 95%, zero regression failures |
| Cross-file Agent tasks | Strong general reasoning and planning | Task completion rate, tool-call success rate, average steps | Completion ≥ 70%, tool-call success ≥ 95% |
| Frontend UI debugging | Image input support | Issue localization accuracy | Accuracy ≥ 80% |
The thresholds above are examples only. Each team should adjust them based on its quality requirements and tolerance for trial and error.
Agent task evaluation should be broken down further. Record separately whether the plan is sound, whether each tool call’s parameters are correct, and whether the model can recover after a failure. Looking only at the final result makes it hard to tell where things went wrong.
Below is a sample evaluation call. In practice, replace the endpoint and test cases with your own.
import osimport requests# Sample code: assumes an OpenAI Chat Completions-compatible endpoint;# check your provider's documentation for the actual URL and model nameAPI_URL = os.environ["LLM_API_URL"]API_KEY = os.environ["LLM_API_KEY"] # Read the key from an environment variable, never hardcode itdef evaluate_model_capability(model_name, prompt, context_code, timeout=60):headers = {"Authorization": f"Bearer {API_KEY}","Content-Type": "application/json",}payload = {"model": model_name,"messages": [{"role": "system", "content": "You are a rigorous coding assistant. Output only runnable code."},{"role": "user", "content": f"{prompt}\n\nRelevant code:\n{context_code}"},],"max_tokens": 1024,"temperature": 0.2, # Coding tasks typically use a low temperature}try:resp = requests.post(API_URL, json=payload, headers=headers, timeout=timeout)resp.raise_for_status()return resp.json()["choices"][0]["message"]["content"]except requests.RequestException as e:raise RuntimeError(f"Model service request failed: {e}") from eexcept (KeyError, IndexError, ValueError) as e:raise RuntimeError(f"Unexpected response format: {e}") from edef run_case(model_name, case):"""After generation, run the unit tests in an isolated environmentand use the test results to determine pass/fail."""generated = evaluate_model_capability(model_name, case["prompt"], case["context"])# Write `generated` into a sandbox, run case["tests"], then return the resultsreturn {"model": model_name, "case_id": case["id"], "output": generated}
Generated code should never run directly on a development machine. Execute it in a container or sandbox, and use unit test results as the pass/fail criterion.
5. Long Context: Window Size Does Not Equal Effective Utilization
Some open-source models already support million-token contexts, such as the Qwen2.5-1M series. Most mainstream open-source models, however, commonly offer context windows of 128K to 256K. Refer to official announcements for exact window sizes, and validate real-world performance through your own testing.
As windows grow larger, the challenge shifts to how effectively the context is used. Irrelevant content interferes with reasoning. The well-known “lost in the middle” phenomenon refers to models recalling information from the middle of a long context less reliably than content at the beginning or end. Dumping an entire codebase into the context at once is therefore both expensive and potentially harmful to output quality.
In practice, the following approaches help:
- Semantic chunking: Use retrieval-augmented generation (RAG) to split code by semantic units such as functions, classes, or modules, rather than cutting at fixed character counts.
- Rerank after retrieval: Rerank retrieved results and keep only the top-scoring chunks.
- Set a context budget: Define the share of each section in advance. For example, about 5% for system instructions, 10% for the task description, 60% for code snippets, and the remainder for outputs and tool results. These ratios are only a reference — adjust them per task.
- Run needle-in-a-haystack tests: Embed a fact in the middle of a long text, then query the model and plot recall as a function of text length. The point where the curve drops sharply is the model’s practical effective context limit for that task.
Multimodal models are more convenient when handling mixed inputs of code, design images, and requirement documents. Text-only models concentrate their compute when analyzing long code repositories, typically responding faster with lower token consumption.
