Evaluating LLMs for Long-Horizon Tasks: A Practical Guide to Model Selection
This guide provides a practical framework for evaluating large language models (LLMs) for long-horizon tasks such as code generation and AI agent execution. It covers setting fixed evaluation conditions, defining pass criteria for code iteration and agent loops, comparing models on a per-successful-task cost basis, and checking infrastructure requirements. This is tailored for developers and architects moving from simple Q&A to complex, multi-step automation with LLMs.
As large language models shift from basic question answering to use cases like code generation and autonomous agent execution, model selection criteria must evolve accordingly. Evaluating output quality is no longer sufficient; you must also assess whether a model can maintain code integrity over multi-turn tasks, understand a local codebase, self-correct based on test failures, and do so at a manageable cost. This guide provides actionable evaluation methods for developers and architects involved in model selection. For clarity, an “agent” in this context refers to an LLM application that can use tools (e.g., file read/write, command execution) and iteratively act on the results.
1. Establish Fixed Evaluation Conditions
A model’s performance can vary significantly with its version, the prompt used, and the scale of the project. To ensure a fair comparison, you must document the following for each test run:
| Item | Example | Description |
|---|---|---|
| Model Name & Version | specific version string | Avoid vague references like “latest.” |
| Task Description | version of a product-plan doc | Use the exact same instruction set for all models. |
| Sample Data | anonymized business data | Ensure the test is reproducible. |
| Frontend Framework & Version | React 18 | Code structure varies greatly with framework. |
| Runtime Environment | container image, dependency versions | This determines the reproducibility of the result. |
| Pass Criteria | see Section 5 | Define criteria before testing, not after. |
2. Code Generation & Long-Task Iteration
For evaluation, select a medium-complexity application—for instance, an earnings-season monitoring page with a data list, filters, charts, and a backend API. Test these checkpoints:
- File Completeness: Check if the entry point, routes, components, styles, and API calls are fully generated, rather than just provided as code fragments.
- Interaction Completeness: Verify user interactions like filtering, sorting, and empty-data states. Use a fixed set of scripted operations to test these one by one.
- Iteration Stability: In subsequent rounds, use natural language to request added features (e.g., new backend logic). Observe whether the model breaks existing functionality.
- Truncation & Omission: Track and calculate the proportion of outputs that end prematurely or contain phrases like “this part is omitted.”
This method converts a subjective impression of “skimping on work” into a quantifiable metric.
3. Agent Execution Loops: Execute, Feedback, Correct
An agent’s ability to run tests, parse error logs, modify code, and re-run is a key source of efficiency, but it also introduces risk. Ensure the following prerequisites are in place before deployment:
- Sandbox Environment: The agent must be restricted to the test project directory, with no access to other host files or production databases.
- Least Privilege: Grant only the minimum necessary command and directory access. Actions like file deletion, code pushing, and service deployment should require human confirmation.
- Iteration Limit: Set a hard cap for correction loops (e.g., 5 rounds). The agent should stop and escalate to a human if it exceeds this limit to prevent runaway costs.
- Log Sanitization: Filter any keys, tokens, or user data before writing runtime logs.
- Traceability: Save code diffs, test results, and model outputs from every iteration to facilitate post-mortem analysis.
4. Cost & Quota: Compare Using Cost per Successful Task
A model with a higher benchmark score may consume significantly more tokens to finish the same task, leading to higher overall costs. Use the following metric to compare your shortlist:
Cost per Successful Task = Total Expenditure ÷ Number of Tasks Passing Acceptance
Total expenditure includes input and output tokens, cache costs (if applicable), and the cost of failed tasks from all attempts. It’s crucial to agree on the billing model beforehand:
| Item | Question to Confirm |
|---|---|
| Billing Units | How are inputs, outputs, and cache usage priced? |
| Quota Reset Cycle | Is the quota reset daily, weekly, or monthly? |
| Rate Limits | What are the maximum requests-per-minute and concurrent request counts? |
| Overload Handling | What happens when the quota is exceeded—degradation, queuing, or rejection? |
| Measurement | Calculate based on a full cycle of tasks, not a single trial run. |
The sufficiency of the quota depends on your team’s actual workload. Run the same set of tasks against each competitive model, record the weekly usage as a percentage of the quota, and include these figures in the final selection report.
5. Execution Checklist for Four Evaluation Dimensions
| Dimension | Test Methodology | Acceptance Criteria (Team-Defined) | Data to Record |
|---|---|---|---|
| Stability | Add requirements incrementally within a single, long conversation across 10 rounds for a fixed project. | The pass rate of key functionality tests in each round. | Pass rate, the specific round where quality drops. |
| Instruction Following | Issue complex, nested instructions with conditional branches. | The model does not modify code outside the indicated scope, and all key constraints are satisfied. | Number of out-of-scope code changes. |
| Environment Awareness | Provide a project with multiple layers of directories, dependency conflicts, and multiple config files. | The model correctly identifies entry points, dependency relationships, and effective configuration files. | List of files/items the model misidentified. |
| Error Handling | Artificially induce exceptions and observe the resolution process. | Each exception type has a defined, expected handling action. | The action taken, and whether it escalated to a human. |
Examples of expected handling actions for exceptions:
- Network Errors: The agent should automatically retry with a backoff interval and a maximum retry count. After exceeding the limit, it should save progress and report to the user.
- Missing Dependencies: The agent should first read lock or config files, then suggest an install command for user confirmation, rather than arbitrarily changing dependency versions.
- Test Framework Errors: The agent should distinguish between code errors and environment errors. For environment issues, it should not modify the business code.
- Degradation Strategy: If a specific test repeatedly fails, the agent should revert to the last known working version and flag the task for manual review.
6. Infrastructure Requirements to Verify
Agent workloads (concurrent requests, runtime, log volume) are significantly higher than those for standard Q&A. Verify these points with your service provider or internal operations team:
- Isolation: Is the runtime environment isolated? Can containers or VMs be quickly rebuilt per project?
- Scalability: Can concurrent requests and auto-scaling meet peak demands? How long does a scale-up take?
- Observability: Do logs, monitoring, and alerts cover model call latency, error rates, and costs?
- SLA: Are the service level agreements, usage restrictions, and billing rules clearly documented, specifically concerning concurrency limits and timeout policies?
Vendor claims of “high cost-performance” should not be taken at face value. Base decisions on your team’s independently measured cost per successful task.
7. Applicable and Non-Applicable Scenarios
Ideal for:
- Iterative development of small-to-medium projects with a comprehensive automated test suite, where success or failure is determined automatically.
- Feature development with clear, well-defined requirements that can be broken down into specific acceptance checkpoints.
- Teams that already have established code review and version rollback processes.
Not suitable for:
- Projects without test cases, making it impossible to automatically judge the output.
- Environments involving production data, keys, or payment operations that cannot be secured with isolated permissions.
- Exploratory work with ambiguous requirements that requires frequent, high-level human judgement.
Conclusion
During model selection, focus on three key metrics: cost per successful task, pass rates across different test dimensions, and the frequency of manual intervention during edge-case testing. It is critical to evaluate code generation capability and agent execution performance separately—a model might excel at generating initial code but repeatedly break existing features during multi-turn amendments. Finally, because model versions are updated frequently, re-run the same task suite with the new version to ensure your selection conclusions remain valid for your team.
