LLM Agent Programming: A Practical Guide to Loose Constraints and Strict Goals

    Many LLM agent failures come not from insufficient model capability but from constraints placed in the wrong part of the task. This article presents a practical programming model: fix the endpoint and open the path. It covers three scenarios—self-verifying SVG generation, one-shot generation of a runnable application, and UI-operating computer-use agents—and explains prompt design, security controls, evaluation, observability, and cost governance for moving agents into production. Readers will learn how to define hard goals, avoid conflicting process instructions, design acceptance checklists, and use testing and observability to prove quality rather than relying on intuition.

    1. The Real Problem: Constraints in the Wrong Place

    Many failures in practice do not stem from insufficient model capability. They come from constraints applied in the wrong place. A typical anti-pattern is specifying in the prompt what to do first, what to do next, which function to use, and how many steps to take. This treats the model as an interpreter that only executes a fixed workflow. The core strength of newer models is long-horizon autonomous planning: they can decompose tasks, choose implementation paths, and self-correct after errors. When you hard-code the path as well, you voluntarily give up that strength and introduce many conflicting instructions.

    The right split is: fix the endpoint; open the path.

    • Endpoint (hard constraints): verifiable inputs and outputs, boundary conditions, performance and safety baselines, and dependency and runtime environment limits.
    • Path (soft constraints): implementation steps, internal data structures, code organization, and debugging order—all left to the model.

    In one sentence: fewer rules can produce better performance—but “fewer” means less control over the process, not lower standards.

    2. Scenario 1: Structured Graphical Code Generation

    A simple prompt—“Generate high-quality SVG code that draws a pelican riding a bicycle”—can produce results far beyond expectations. There are three reasons:

    1. The task is self-verifying. Vector graphics can be rendered instantly, and correctness is visually obvious. During long reasoning, the model can form internal consistency checks.
    2. The constraints are aesthetic rather than procedural. The prompt describes only the target object and state; it does not specify how many paths to use or how to layer them.
    3. The output is plain text with zero dependencies. No environment setup is required, and the cost of failure is very low, so the model can be allowed to refine itself over multiple rounds.

    A reusable prompt skeleton:

    1. Goal: Output a single-file SVG that renders directly in the browser. The subject is <object>; the state is <action>.
    2. Acceptance:
    3. - No external dependencies and no bitmap references;
    4. - No deformation at both 320px and 1920px widths;
    5. - Key structures are identifiable (subject, support points, motion trend).
    6. The implementation approach is up to you.

    Engineering points: Use “renders successfully” as the minimum bar, and “no deformation at multiple sizes” and “identifiable structure” as regression items. These tasks are well suited to a small evaluation set. After every model or prompt change, rerun the set in batch and manually spot-check rendered screenshots. This avoids judging whether the model “got stronger” by feel.

    3. Scenario 2: One-Shot Generation of a Complete Runnable Application

    One developer obtained a structurally complete 3D interactive application in a single run in just over forty minutes, with visuals closely matching the concept art. This was not accidental; three conditions were met at the same time:

    • Standardized scaffolding. Directory structures, build scripts, and dependency lists follow common industry patterns, so the model does not need to guess.
    • Programmatically obtainable resources. Geometry, materials, lighting, and textures can be generated with code or common assets, without relying on manual art resources.
    • A short feedback loop. Local hot reload compresses the write–run–view cycle to seconds, allowing the model to keep correcting within the same session.

    A practical recommendation is to put the acceptance checklist in the prompt upfront rather than relying on rework afterward:

    1. Deliverable: A project directory that can be started directly.
    2. Must satisfy:
    3. 1) Installation and startup complete with one command, with no interactive prompts;
    4. 2) The first screen is interactive within 3 seconds;
    5. 3) Scene elements match the reference description: list the five required elements;
    6. 4) No console errors; low-end devices can fall back to lower rendering quality.

    It is important to frame one-shot generation correctly: it is a “high-quality first draft,” not a “test-free delivery.” The real time savings come from a sensible structure, consistent naming, and clear boundaries in the draft, which greatly reduce the cost of subsequent human review and incremental changes.

    4. Scenario 3: Agents with UI Operation Capabilities

    Having a model draw directly in a design platform depends on computer-use capabilities: understanding the interface from screenshots, planning clicks and input, observing results, and correcting them. These capabilities open up many long-tail tasks that previously had no API, but they raise the risk level by an order of magnitude and require corresponding governance:

    • Least privilege: Use a separate low-privilege account and a dedicated session; do not log in to primary accounts or production systems.
    • Sandbox isolation: Run in disposable containers or virtual desktops that are destroyed when the task ends; return files through general mechanisms such as object storage.
    • End-to-end auditing: Retain operation logs, screenshots, and records of key actions; connect them to logging services and monitoring alerts so anomalous behavior can be traced.
    • Human approval gates: Require human confirmation for irreversible actions such as payments, deletions, and external sending.
    • Timeouts and rollback: Set limits on steps and duration, and restore the initial snapshot on failure.

    5. Why “Fewer Rules” Works Mechanically

    From a context engineering perspective, long and conflicting instructions create three problems: attention is diluted and key constraints are buried in noise; when instructions conflict, model behavior becomes unpredictable; and rules consume the context budget, leaving less room for code and reasoning.

    A three-layer prompting method is therefore recommended:

    1. Goal layer: One sentence explaining what is needed and why.
    2. Acceptance layer: A determinable checklist, quantified where possible.
    3. Boundary layer: Only the non-negotiable red lines (safety, compliance, dependencies, environment).

    Delete anything outside these three layers where possible. At the same time, keep a small number of constraints that must be hardened, such as structured output formats, prohibitions on sending data externally, and mandatory existing API contracts. These are non-negotiable items, and they do not contradict the principle of not managing the process.

    6. Moving to Production: Evaluation, Observability, and Cost

    To replicate the benefits of individual experimentation across a team, three pieces of infrastructure are needed:

    • Evaluation set: Codify representative tasks as repeatable test cases, and record pass rate, rework rounds, and lines of manual modification.
    • Observability: End-to-end logs and metric monitoring that separate model latency, tool-call latency, and the distribution of failure causes.
    • Cost governance: Choose models and context lengths by task tier; place large objects in object storage, use message queues to smooth peak load, and use container platforms for sandbox execution, avoiding uncontrolled growth of long sessions.

    On cloud platforms such as Baidu AI Cloud, these capabilities are typically provided by general product categories such as object storage, container platforms, logging services, monitoring and alerting, and message queues. They can be combined directly into an agent runtime foundation without building it in-house.

    7. Checklist

    • Does the prompt specify implementation steps that the model should decide?
    • Are acceptance criteria verifiable, quantifiable, and automatically rerunnable?
    • Are there conflicting instructions?
    • Are irreversible actions protected by human confirmation and privilege isolation?
    • Are there evaluation sets and logs that prove the system “got better” rather than merely creating that impression?

    Conclusion

    The biggest change brought by the new generation of models is the shift from executing instructions to owning the goal. The user’s role shifts accordingly from process writer to standard setter and result acceptor. Define the goal clearly, open the path completely, and use evaluation and observability to guarantee quality. This is the full engineering meaning of being strict about the endpoint and loose about the route.