LLM Selection and Implementation Practices for Programming and Automation

    This article explores practical strategies for selecting and implementing Large Language Models (LLMs) in programming and automation tasks. It shifts the focus from merely comparing model versions to evaluating task delivery capabilities within budget and security constraints. The article covers establishing engineering evaluation dimensions, configuring security boundaries, and demonstrates through two practical scenarios—equipment inspection and a full-stack guessing game—how to build robust, reproducible, and secure automated development workflows.

    1. Shifting from Model Selection to Task Delivery

    Model updates are frequent, and developers can easily fall into a trap: constantly chasing newer versions without establishing a stable evaluation standard. For actual engineering work, what truly matters is not how well a model performs in a single response, but whether it can consistently complete valuable tasks within budget and safety constraints.

    This is especially true for local automation and full-stack development. The former requires handling device connections, permissions, exceptions, and scheduled execution, while the latter involves requirement understanding, API design, state management, testing, and deployment. Missing any link can lead to a situation where “code is generated, but the system is unusable.”

    Therefore, when selecting a primary model, the question should be rephrased as:

    Given the development environment, task type, and cost constraints, which model configuration can consistently deliver accepted results with less manual intervention?

    Building a process around this question provides more long-term value than simply comparing model names.

    2. Establishing Evaluation Dimensions for Engineering Tasks

    1. Requirement Understanding and Constraint Maintenance

    The model must accurately understand requirements and continuously adhere to constraints across multiple revisions. For example, if frontend-backend separation is required, it should not deliver a static page demo; if a device inspection is required to be read-only, it must not modify device configurations to retrieve information.

    Requirements can be organized into three checklists:

    • Functional requirements: What business actions the system must perform.
    • Non-functional requirements: Limitations in security, maintainability, response time, and operating environment.
    • Acceptance criteria: What evidence proves the task is complete.

    Evaluation should not only check if the model “mentions” these requirements but also verify if it implements them in code, tests, and documentation.

    2. Tool Calling and Failure Recovery

    The intelligent programming process typically involves reading files, modifying code, executing tests, and analyzing logs. How well the model uses these capabilities directly impacts task delivery efficiency.

    Key details to observe include: whether it checks the environment before executing commands; whether it can locate the cause after a modification failure; whether it fixes the root cause when a test fails rather than deleting the test; and whether it clearly explains blocking points when encountering network or permission issues.

    A single failure is not terrible. What needs to be guarded against is repeatedly executing invalid operations, continuously expanding the scope of modifications, and claiming task completion without verification.

    3. Cost Per Successful Task

    The unit call price does not fully reflect the total cost. A cheaper model may consume more context, tool calls, and manual time if it frequently requires rework.

    A more practical accounting method is:

    Total Cost = Model API Fees + Tool and Execution Resource Fees + Manual Review and Rework Cost.

    Cost Per Successful Task = Total Cost / Number of Accepted Tasks.

    This metric should be calculated based on actual workloads. Short script generation, cross-file refactoring, and complex troubleshooting have different demands on the model, and a single task should not represent all capabilities.

    3. Establishing Configuration and Security Boundaries Before Model Integration

    1. Separating Model Configuration from Business Code

    When integrating intelligent programming tools, you typically need to configure access credentials, service endpoints, and model identifiers. The exact fields depend on the official documentation of the tools and services used; do not assume complete compatibility between different services.

    It is recommended to place this information in controlled configurations and follow these principles:

    • Access credentials should not be written into source code or committed to version control.
    • Configure development, test, and production environments separately.
    • Set least-privilege permissions for credentials and rotate them periodically.
    • Logs should only record necessary call metadata and not output full credentials.
    • Set timeouts, concurrency limits, and cost alerts for requests.

    Even if a service provides a compatible interface, you still need to verify message formats, streaming output, tool calling, error structures, and context limits. A successful connection only indicates basic communication is available; it does not mean complex development tasks can be executed stably.

    2. Setting Permission Levels for Automated Execution

    Tool operations can be divided into three levels:

    • Low risk: Reading project files, running static checks, generating content in a temporary directory.
    • Medium risk: Installing dependencies, modifying multiple files, accessing external networks.
    • High risk: Deleting data, changing system configurations, operating production resources.

    High-risk operations should require manual confirmation and provide previews, backups, and rollback options whenever possible. For terminal commands, do not just evaluate the command name; also check parameters, working directory, and the potential data scope affected.

    3. Verifying Data Flow

    “Running programming tools locally” does not mean “all data stays local.” If model inference is done via a remote service, the input code, logs, and configuration snippets may leave your machine.

    Therefore, confirm the allowed data transmission scope in advance. Device passwords, access tokens, sensitive business fields, and internal network information should be isolated, desensitized, or prohibited from being sent out. Text from logs, pages, and device return values should also be treated as untrusted data and should not be automatically executed just because it contains operation instructions.

    4. Practice 1: Building a Sustainable Equipment Inspection System

    Equipment inspection is suitable for testing a model’s automation development capability because it requires not only generating scripts but also handling uncertainties in real-world environments.

    1. Designing from a Data Contract

    Different devices may return fields and status expressions that vary greatly. If raw results are directly concatenated onto a page, adding new device types later will cause the collection and display logic to become tightly coupled.

    A more robust approach is to define a unified data structure, for example:

    1. Device ID
    2. Device Type
    3. Collection Time
    4. Collection Status
    5. Standardized Metric Set
    6. Error Category
    7. Raw Evidence Reference

    “Collection Status” and “Device Health Status” must be distinguished. A connection timeout means the device’s condition cannot be confirmed this time and should not be directly equated to a device failure; missing fields should not default to indicating normal metrics.

    2. Splitting the Processing Pipeline by Responsibility

    The following structure is recommended:

    1. Device List
    2. ↓
    3. Collection Adapter Layer
    4. ↓
    5. Field Standardization
    6. ↓
    7. Rule Judgment
    8. ↓
    9. Result Storage
    10. ↓
    11. Reporting and Alerting

    The collection adapter layer is responsible for shielding differences in connection methods. When a stable, supported interface exists, it should be prioritized. If data can only be obtained through pages or interactive logins, additional handling for session expiration, page changes, and authentication requirements is needed; existing security controls should not be bypassed.

    The rule judgment layer handles deterministic logic, such as threshold comparisons, field integrity checks, and certificate validity calculations. LLMs can assist in explaining anomalies and compiling reports, but they should not replace the deterministic calculations of critical rules.

    3. Handling Timeouts, Retries, and Partial Failures

    A single slow device response should not block the entire inspection task. The collection process should have independent timeouts and concurrency limits to avoid sending too many requests to devices in a short period.

    Retries need to be categorized:

    • Temporary network anomalies can have limited retries.
    • Authentication failures should stop repeated attempts and trigger an alert.
    • Data format changes should retain necessary evidence and wait for adapter fixes.
    • Explicitly unsupported operations should not be executed repeatedly.

    Read-only collection is usually safer for retries, but write operations must consider idempotency to avoid side effects from repeated execution.

    4. Enabling Historical Data for Analysis

    Spreadsheets are suitable as a user-facing export format but should not be the sole data source. A more reasonable approach is to retain structured records first and generate reports on demand.

    Each inspection should record at least the task ID, scheduled time, actual collection time, device ID, rule version, and execution result. This helps determine whether an anomaly is appearing for the first time, persists, or is caused by a rule adjustment.

    To prevent scheduled task overlaps, task locks or deduplication mechanisms should be designed. Even if the same task is triggered repeatedly, it should be able to identify and control duplicate writes.

    5. Practice 2: Verifying Full-Stack Delivery with a Guessing Game

    A guessing game is moderately scaled but covers data modeling, API design, frontend interaction, testing, and security boundaries, making it an excellent engineering verification task.

    1. Defining Acceptable Rules First

    The basic version can be defined as:

    • At least twenty built-in puzzles.
    • Each puzzle contains a theme, a standard answer, and three hints from hard to easy.
    • Only the first hint is returned at the start.
    • Users can submit answers or progressively unlock subsequent hints.
    • The system records the number of guesses, hint usage, and current game status.
    • The game ends when answered correctly, abandoned, or the attempt limit is reached.

    Among these, attempt limits, scoring rules, and answer tolerance ranges are project design decisions that should be clarified before development. The model should not adopt different rules in different files on its own.

    2. Separating Frontend Display and Backend State

    The frontend is responsible for displaying puzzles, submitting input, and reflecting status; the backend is responsible for selecting puzzles, judging answers, and maintaining the game session.

    For convenience, do not send the complete puzzle bank and answers directly to the browser and rely on UI to hide them. This only hides the display and does not protect the data.

    Backend responses should follow the principle of least exposure: ongoing games should only return unlocked hints, not standard answers, future hints, or internal fields that could deduce the answer.

    3. Defining LLM Involvement

    Not all games with “intelligent” experiences need to call a model for every operation. The basic version can use a fixed puzzle bank and deterministic judging, making the system easier to test and reducing cost and latency.

    If LLMs are introduced, they can assist in generating candidate puzzles, explaining answers, or providing more natural hints, but content moderation and quality checks must be added. Generated puzzles may have multiple solutions, leak answers via hints, or contain factual errors, and should not enter the official puzzle bank unverified.

    For judging, it is suitable to first use whitespace processing, punctuation normalization, and explicit alias tables. Whether synonymous expressions are accepted should be decided by business rules. When model assistance is needed for judgment, a clear fallback strategy should be retained to avoid the same answer being judged differently repeatedly.

    4. Designing Consistent Game States

    The game can be abstracted into states like “in progress,” “won,” “abandoned,” and “ended,” with clear operations allowed for each state.

    For example, an ended game should not continue to increment guess counts; repeatedly clicking the hint button should not deduct points multiple times; after refreshing the page, the user should be able to resume progress based on a valid session.

    These state constraints should be guaranteed by the backend, not just by disabling frontend buttons. Network retries, concurrent requests, and direct API calls can all bypass UI restrictions.

    6. Organizing Fair and Reproducible Comparative Evaluations

    1. Fixing Task Inputs and Running Conditions

    Different models should use the same initial project, requirement descriptions, tool permissions, time budget, and acceptance tests. Each round of experiments should start from a clean environment to avoid inheriting code and cached results from the previous round.

    If evaluating the model itself, fix the programming tools and their configurations as much as possible. If evaluating a complete development solution, different configurations can be allowed, but the differences must be recorded. Otherwise, the impact of the toolchain might be mistaken for differences in model capability.

    2. Recording More Than the Final UI

    It is recommended to record the following metrics:

    • Functional acceptance pass rate.
    • Automated test results.
    • Number and reasons for manual interventions.
    • Total time to complete the task.
    • API and execution resource costs.
    • Whether high-risk operations were introduced.
    • Whether the documentation is sufficient for independent startup and maintenance.

    Test cases should cover both normal and exception flows. For example, the guessing game should test repeated requests, invalid game IDs, and answer leakage; the inspection task should test device timeouts, missing fields, and partial device unavailability.

    3. Using Multi-Round Results Instead of Single Impressions

    The generation process is subject to fluctuations. A single success does not prove stability, and a single failure does not represent overall capability.

    You can repeat the same type of task and simultaneously observe median performance and failure cases. The cause of failure is particularly important: is it a missing requirement, a tool usage error, an environmental limitation, or the model’s inability to perform critical reasoning? Only by distinguishing the causes can you know whether to change the model, optimize the prompt, or fix the engineering environment.

    Without real test data, you should not draw definitive conclusions like “efficiency increased by X%” or “cost reduced by Y%.”

    7. Forming a Reusable Intelligent Development Workflow

    It is recommended to converge daily practices into the following closed loop:

    1. Define the task: Write down the goals, constraints, inputs, outputs, and acceptance methods.
    2. Require a proposal: Review the architecture, risks, and implementation steps before allowing code modifications.
    3. Implement in phases: Complete the minimum viable loop first, then gradually add exception handling and auxiliary functions.
    4. Continuously verify: Run tests at each stage and check actual changes.
    5. Human review: Focus on reviewing permissions, credentials, data deletion, and external communications.
    6. Accumulate assets: Retain requirement templates, test sets, failure records, and operational instructions.
    7. Periodic re-evaluation: Re-evaluate when task structures, model versions, or billing methods change.

    Ultimately, the model should be viewed as a replaceable component in the engineering system, not the sole source of overall system reliability.

    For programming and automation tasks, the worthwhile long-term investment is not a single generation result, but clear requirements, explicit permission boundaries, reproducible tests, and a traceable delivery process. Once these foundations are established, model selection shifts from a subjective experience to an explainable and verifiable engineering decision.