Automating Complex Tasks: Planning and Delivery Practices for AI Agents

    Traditional large language model (LLM) applications primarily focus on question-answering. However, complex tasks like generating web pages, creating presentations, or analyzing large spreadsheets require multi-step execution, external data retrieval, and rigorous verification. This article explores how to build reliable task-oriented AI agents by implementing a four-layer architecture: Planning, Execution, Verification, and Delivery. It details best practices for task decomposition, tool design, result validation, and delivering interactive, reusable, and traceable outcomes.

    I. Background: From Q&A to Task Delivery

    Traditional LLM applications primarily focus on question-answering, where a user asks a question and the model generates a text response. When requirements shift to “create an accessible web page,” “organize a presentation,” or “process a massive spreadsheet and provide conclusions,” a single response is no longer sufficient. These tasks require multiple steps, fetching external information, repeated verification, and ultimately producing a ready-to-use file or page. The value of an AI agent lies in transforming the model from a responder to an executor, allowing the system to autonomously plan around the goal, call tools, check results, and deliver outcomes.

    In engineering, a task-oriented agent can be decomposed into four cooperating layers:

    1. Planning Layer: Understands the goal and breaks it down into ordered subtasks.
    2. Execution Layer: Calls tools such as retrieval, content generation, and code execution to complete subtasks.
    3. Verification Layer: Checks whether intermediate and final results meet constraints.
    4. Delivery Layer: Formats results into an interactive, reusable, and traceable form.

    Clear state passing is required between the four layers. The output of the planning layer serves as the input for the execution layer. The products of the execution layer are passed to the verification layer, and if verification fails, it flows back to the execution layer. The following sections expand on this sequence.

    II. Planning Layer: Converting Goals into Trackable Task Lists

    Planning determines the reliability of the agent. If the goal is not decomposed, the execution process becomes directionless trial-and-error, wasting API calls and making it difficult to locate failures.

    In practice, a task list is commonly used to record the plan. Each item contains the following fields:

    • Subtask description: A single sentence explaining what to produce.
    • Dependencies: Which prerequisite task outputs this task depends on.
    • Status: Pending, running, done, or failed.
    • Acceptance criteria: Checkable conditions to determine if the subtask is complete.

    The list not only displays progress but also provides an entry point for user intervention, such as adjusting priorities, deleting unnecessary modules, or adding constraints. Furthermore, the list provides a basis for resuming from breakpoints. If a step fails, you only need to rerun that step and its downstream tasks without starting from scratch.

    Here is a simplified data structure example:

    1. task_plan:
    2. - id: T1
    3. desc: Collect public data in the target domain
    4. depends_on: []
    5. status: done
    6. acceptance: Data sources are traceable, key fields are complete
    7. - id: T2
    8. desc: Clean data and calculate core metrics
    9. depends_on: [T1]
    10. status: running
    11. acceptance: Metric results match manual sample checks
    12. - id: T3
    13. desc: Generate visualization charts
    14. depends_on: [T2]
    15. status: pending
    16. acceptance: Charts include title, axis labels, and data source

    III. Execution Layer: Design Principles for Tool Calling

    The execution layer is responsible for interacting with the external environment. Common tools can be categorized into four types: information retrieval, content generation, code execution, and file operations. The following principles should be followed during design.

    1. Single Responsibility: Each tool should only perform one type of operation with a fixed input/output format. This makes it easier for the model to select the right tool and for the system to audit.
    2. Parameter Validation: Model-generated parameters should be checked for type and range before calling. Invalid parameters should be rejected directly, returning a specific error reason.
    3. Structured Results: Content returned by tools should include the source, timestamp, and status code, allowing downstream steps to determine if the result is usable.
    4. Limited Retries: For network requests that may fail, use a limited number of exponential backoff retries to prevent infinite loops.

    Taking information retrieval as an example, the retrieved results need to retain source links and fetch times. Only when subsequently generated content cites these sources can the system fact-check. For content generation tools, generation parameters and versions should be recorded for reproducibility and replacement.

    Code execution is the highest-risk segment. Generated code should run in an isolated environment, restricting file system access, disabling non-essential network permissions, and setting limits on execution time and memory. The execution results (standard output, error messages, generated files) should be returned together to the planning layer for the next decision. The pseudo-code below is for illustrative purposes only; parameters should be adjusted according to the actual environment:

    1. function run_step(step):
    2. validate_inputs(step.params)
    3. if step.type == "search":
    4. results = search_tool(query=step.params.query, limit=10)
    5. return {status: "ok", sources: results.urls, fetched_at: now()}
    6. if step.type == "codegen_and_run":
    7. code = generate_code(step.spec)
    8. result = sandbox.execute(code, timeout_sec=60, memory_mb=512)
    9. return {status: result.status, stdout: result.stdout,
    10. stderr: result.stderr, artifacts: result.files}
    11. raise UnknownStepType(step.type)

    IV. Verification Layer: Ensuring Results Stand Up to Scrutiny

    The most common failure for an agent is usually not a program crash, but an output that appears complete but is factually incorrect. The task of the verification layer is to shift “looks correct” to “verifiable.” Verification can be divided into three dimensions:

    • Structural Verification: Does the file exist, can the format be parsed correctly, can the page render properly, and are the spreadsheet columns complete?
    • Logical Verification: Do summary values match the details, is the chart data from the same cleaned result, and is the time sequence reasonable?
    • Semantic Verification: Does the content address the original goal, and is there corresponding evidence for key conclusions?

    Code artifacts can be verified through static checks and unit tests. Data artifacts can be sampled and traced back to original records. Document artifacts can be checked to see if cited data points can be found in the sources.

    When verification fails, the system should provide specific failure items. “Missing axis unit on chart 3” is much easier to fix than “Problem with the chart.” A repair limit must be set; if exceeded, the system should request user intervention.

    V. Delivery Layer: Interactive, Reusable Results

    The result the user receives determines the value of all preceding work. Deliverables should meet three requirements:

    1. Interactive: Pages support basic operations, charts support viewing specific values, and documents support modification and export.
    2. Reusable: Key parameters and data sources are stored centrally. When a user modifies an input, the related outputs can be regenerated.
    3. Traceable: Every conclusion can be traced back to its data source and calculation process.

    Upon delivery, a brief note should be attached, listing completed subtasks, incomplete or skipped subtasks, data sources used, and known limitations. Clearly stating limitations helps users determine whether the result is usable.

    VI. Practical Approaches for Three Typical Tasks

    (I)