Agent Development in Practice: Building Agents for Complex Coding and Long-Horizon Tasks

    This article explores the engineering shift required to build AI agents that can deliver end-to-end tasks rather than just generate code. It presents a three-layer architecture for complex coding scenarios (semantic, execution, and validation layers), principles for defensive cybersecurity use cases, context governance strategies for long-horizon tasks, a three-tier evaluation framework, and a phased adoption roadmap. Readers will learn how runtime design, verification loops, and clear security boundaries determine delivery quality.

    1. From “Writing Code” to “Delivering Tasks”: A Shift in Focus

    Over the past two years, developers’ core expectations for code models centered on completion speed and syntactic accuracy. Once models began entering real development workflows, the evaluation criteria quickly shifted to “whether the model can independently complete an end-to-end task.” This transition has three direct consequences: coarser task granularity, longer execution chains, and higher failure costs. A seemingly simple request like “fix this bug” actually involves five stages: localization, reproduction, hypothesis, verification, and regression. Missing context at any stage leads the model to produce a plausible-looking but non-functional solution.

    Therefore, the engineering focus must shift from “prompt tuning” to “task runtime design.” The runtime refers to the scheduling layer outside the model: it decomposes goals, maintains state, constrains tool permissions, records intermediate artifacts, and decides whether to retry or roll back on failure. The stronger the model, the greater the leverage of runtime design; conversely, even the most capable model can only produce one-off code snippets when called without state management.

    2. A Three-Layer Architecture for Complex Coding Scenarios

    1. Semantic Layer: Turning Requirements into Verifiable Constraints

    The prerequisite for high-quality delivery is converting vague requirements into machine-checkable acceptance criteria. The recommended approach is to have the model first output an “acceptance checklist” rather than code, for example: which input boundaries a new API must cover, how error codes map, and what the upper limit on performance metrics is. After human confirmation of the checklist, implementation begins, significantly reducing rework.

    1. # Example: constrain first, implement second
    2. spec = {
    3. "goal": "Add an idempotent creation API to the order module",
    4. "acceptance": [
    5. "Repeated requests with the same idempotency key return the same order ID",
    6. "No duplicate database writes under 20-way concurrent load testing",
    7. "Unified error codes for exception paths, logs include trace_id"
    8. ],
    9. "forbidden": ["modify database table structure", "introduce new runtime dependencies"]
    10. }

    2. Execution Layer: Small Commits and Rollback Capability

    Long-chain tasks fear “one-shot large patches” the most. A more robust engineering strategy is to limit the scope of each change, making every step compilable, testable, and rollback-able. When verification fails, the runtime preserves the last passing state to prevent error accumulation. At the same time, the model should be provided with the minimal necessary repository view, such as relevant files, interface definitions, and failing tests, rather than the entire codebase. This controls costs and reduces interference from irrelevant context.

    3. Validation Layer: Let Tests Be the Sole Judge

    Model self-assessment is unreliable; automated verification is reliable. It is recommended to chain static checks, unit tests, type checks, and dependency compliance scans into a pipeline where any failure triggers a rejection. For parts that are difficult to judge automatically (such as interaction experience), retain manual spot-check nodes and accumulate spot-check conclusions as new test cases, forming reusable assets.

    3. Defensive Cybersecurity: The Stronger the Capability, the Clearer the Boundary

    The high-value use of models in security is on the defensive side: code auditing, dependency vulnerability assessment, log anomaly attribution, and hardening recommendation generation. To keep such applications controllable, three principles must be upheld.

    First, least privilege. Analysis tasks are granted read-only access only; any write operations and external network egress are prohibited. Second, data masking. Before samples enter analysis, automatic identification and replacement of keys, tokens, and personal information is completed. Third, traceable conclusions. Every risk conclusion must include evidence location and reasoning basis for security personnel to review, rather than being accepted at face value.

    1. Analysis request -> Masking -> Read-only sandbox -> Evidence extraction -> Conclusion + location -> Human review -> Rule base accumulation

    It should be emphasized that such capabilities must be strictly limited to authorized self-owned assets; any cross-boundary probing does not fall within the scope of engineering practice. Compliance is not an add-on but a prerequisite for whether a solution can go live.

    4. Context Governance for Long-Horizon Tasks

    The failure of long-horizon tasks is usually not a reasoning error but “memory pollution”: hypotheses that were overturned early on remain in context, continuously misleading subsequent decisions. Governance measures include three types.

    First, layered memory. Divide context into a stable layer (requirements and constraints), a rolling layer (recent steps), and an archive layer (summaries of historical artifacts), injected on demand. Second, externalized state. Write intermediate results to external storage; the model holds only indexes and summaries, avoiding unlimited context expansion. Third, explicit eviction. Mark rejected solutions and remove them from active context, retaining only the rejection reason.

    When deployed in the cloud, these capabilities can be mapped to combinations of general-purpose components: object storage carries large artifacts, message queues drive asynchronous task flow, container platforms provide isolated execution environments, and logging services with monitoring and alerting handle full-chain tracing and anomaly notification. Through unified observability, teams can pinpoint “at which step the task started to go off track.”

    5. Evaluation Loop: No Measurement, No Improvement

    It is recommended to establish a three-tier evaluation system: unit-level (single-function correctness), task-level (end-to-end pass rate and average steps), and regression-level (whether historical defects recur). Each tier retains a fixed sample set and automated scoring scripts; the same set of problems is run before and after version iterations to avoid subjective judgments like “it feels stronger.” In addition to pass rate, metrics should also focus on average time consumption, number of tool calls, and human intervention rate; these three directly determine real costs.

    6. Adoption Roadmap Recommendations

    Phase one is shadow running: the model provides solutions but does not directly modify code; engineers adopt them, used to calibrate prompts and constraints. Phase two is constrained automation: open small commits and automated verification in low-risk modules. Phase three is scaling: integrate unified evaluation and canary releases, gradually expanding permissions by business domain.

    Baidu AI Cloud typically serves as the infrastructure and engineering foundation in such solutions, providing general-purpose capabilities such as computing, storage, containers, and observability, helping teams focus on task orchestration and evaluation systems themselves. Overall, improving model capability is only the starting point; what truly determines delivery quality is the three engineering foundations: runtime design, verification loops, and security boundaries.