Building a Complete AI Agent: Planning, Confirmation, and Execution Loops

    This article explains why tool-calling alone does not make a complete AI agent and how to design one around four closed loops: planning, confirmation, execution, and governance. It covers a five-layer architecture, the three-stage Agent Core design, a human-in-the-loop confirmation protocol, tool contracts with permission boundaries, externalized state for cross-turn consistency, observability and evaluation, common pitfalls, and a staged adoption path.

    1. Where the Problem Starts: Why “Able to Plan” Is Not a Complete Agent

    Many developers hit the same wall when building agents: the model can break a user request into steps and call a few tools, yet the whole chain never gets past “works in a demo.” In real business scenarios the gaps surface immediately: plans are invisible, execution is uncontrollable, failures cannot be traced back, and permissions cannot be enforced. What users see is a black box running on its own, with no way to intervene or to tell whether it is on the right path.

    So the test for whether an agent is “complete” should not be whether it can call tools, but whether it closes four loops:

    • Planning loop: turn a vague request into a structured, verifiable sequence of steps.
    • Confirmation loop: expose the plan to the user before execution, and support edits, rejection, and added constraints.
    • Execution loop: dispatch tools step by step, and handle timeouts, retries, rollbacks, and partial failures.
    • Governance loop: provide logging, tracing, evaluation, and permission boundaries so the system can ship and be operated.

    The original requirement to “show the execution plan, wait for user confirmation, then execute” is essentially a demand to make the confirmation loop a first-class citizen in the design rather than a patch added afterward. That decision drives the architecture.

    2. Layered Architecture: Split the Agent into Five Replaceable Layers

    A production agent should not be a single monolithic prompt. It should be layered and decoupled so each part can evolve and be tested independently.

    1. Interaction layer: session management, multi-turn context, plan rendering, and confirmation controls.
    2. Orchestration layer: where the Agent Core lives; handles intent recognition, plan generation, and state machine progression.
    3. Capability layer: the registry for tools and knowledge retrieval, with unified interface contracts, parameter schemas, and permission tags.
    4. Model layer: a unified gateway to large models of different parameter sizes and reasoning types, with routing and fallback support.
    5. Foundation layer: shared cloud capabilities such as logging, monitoring and alerting, object storage, message queues, and container platforms.

    The payoff is direct: swapping a model does not touch the tools, and changing a tool does not touch the interaction layer. Confirmation nodes can be tested in isolation, and permission policy is enforced in the capability layer instead of being scattered across prompts.

    3. Agent Core Design: Think It Through Before Acting

    The Agent Core is the brain of the system. Use three-stage progression rather than generating every action in one shot.

    Stage 1: Intent clarification. When user input is insufficient, the core should ask questions instead of guessing. The decision can be based on slot completeness, for example whether all required fields in a tool’s parameter schema are present.

    Stage 2: Plan generation. Output a structured plan, not a natural-language paragraph. An example structure:

    1. {
    2. "plan_id": "p-20260801-001",
    3. "goal": "Summarize last quarter's contract risks and produce a brief",
    4. "steps": [
    5. {"id": 1, "tool": "doc_parse", "args": {"path": "contracts/q3"}, "risk": "low"},
    6. {"id": 2, "tool": "vector_search", "args": {"query": "breach clauses"}, "risk": "low"},
    7. {"id": 3, "tool": "report_render", "args": {"template": "risk_brief"}, "risk": "medium"}
    8. ],
    9. "requires_confirmation": true
    10. }

    A structured plan buys three things: it can be schema-validated, it can be rendered as a checklist in the frontend, and it can go through a static risk review before execution.

    Stage 3: Execute after confirmation. The state machine moves from PLANNED to RUNNING only after an explicit user confirmation event arrives.

    1. class PlanState:
    2. PLANNED = "planned"
    3. CONFIRMED = "confirmed"
    4. RUNNING = "running"
    5. PARTIAL = "partial_failed"
    6. DONE = "done"
    7. def on_user_confirm(plan_id, approved, edits=None):
    8. plan = store.get(plan_id)
    9. if not approved:
    10. return store.mark(plan_id, "rejected")
    11. if edits:
    12. plan = validator.apply(plan, edits) # Re-run schema validation
    13. return store.mark(plan_id, PlanState.CONFIRMED)

    4. Confirmation Mechanism: Make Human-in-the-Loop a First-Class Citizen

    Human confirmation is not a simple yes/no dialog. It is an interaction protocol that has to be designed.

    • Plan visibility: show the goal, the steps, the tools involved, and the expected scope of impact, rather than a one-line summary.
    • Editability: let users delete a step, reorder steps, or add parameter constraints; re-validate after any edit.
    • Risk grading: mark steps that write data, send data externally, or touch sensitive data as higher risk and force a second confirmation.
    • Timeout policy: define default behavior for plans left unconfirmed. The usual choice is “expire and void” rather than “approve by default,” to avoid accidental execution.
    • Reversibility: running steps should support cancellation, and completed write operations need compensating actions.

    One detail that is often missed: the confirmation token should be bound to the plan_id and a hash of the plan content, so a plan cannot be swapped before execution while the confirmation stays valid.

    5. Tool Orchestration: Give the Capability Layer Contracts and Boundaries

    The more tools you have, the larger the failure surface. Define a uniform contract for each tool:

    1. TOOL_SPEC = {
    2. "name": "doc_parse",
    3. "input_schema": {"path": "string", "max_pages": "integer"},
    4. "timeout_ms": 8000,
    5. "retry": {"max": 2, "backoff": "exponential"},
    6. "permission": ["storage:read"],
    7. "side_effect": False,
    8. "compensate": None
    9. }

    Key engineering points: idempotency keys, so repeated calls produce no duplicate side effects; failure classification, separating retryable errors from semantic errors; partial failure handling, letting the flow report completed and unfinished parts to the user while in the PARTIAL state; and least privilege, so each tool only receives the data scope it needs.

    6. Context and State: The Source of Cross-Turn Consistency

    Across multiple turns, agents tend to “forget what they promised.” The fix is to externalize state: persist session context, the plan object, and the execution trace separately. The model handles reasoning and is not responsible for memory. Context compression can use a “summary plus key entity table” approach, keeping the goal, constraints, completed steps, and pending items while dropping redundant dialogue text.

    7. Observability and Evaluation: From Demo to Production

    Before shipping, you need at least three observability capabilities: tracing, which records the input, output, and latency of each step; metrics monitoring, focused on plan confirmation rate, step success rate, and average confirmation time; and a regression evaluation set that turns historical real questions into test cases and runs on every prompt or model-routing change. Without an evaluation set, iteration quality depends entirely on subjective impressions.

    8. Common Pitfalls and How to Avoid Them

    • Letting the model execute directly without producing a plan: smooth in the short term, uncontrollable over time, with no interception point for risky steps.
    • Putting permissions in prompts: prompts can be bypassed; enforce permissions in the capability layer.
    • Confirmation that is only formal: plans that are too vague leave users unable to judge, which amounts to no confirmation at all.
    • Ignoring compensation design: only the success path is considered, so a failed write leaves data inconsistent.
    • Generating one long plan at a time: the more steps, the harder the validation. Prefer segmented planning with confirmation per segment.

    9. A Practical Adoption Path

    A four-step progression works well: start with a minimal loop of one tool plus a confirmation node to validate the interaction protocol; expand to multi-tool plan orchestration and fill in validation and risk grading; then add persistence and observability to reach an operable form; finally build the evaluation set and a canary mechanism, gradually opening up the degree of automation. If you rely on general-purpose cloud capabilities, logging, monitoring, storage, and queues can be delegated to the corresponding service categories, leaving your effort on orchestration and evaluation, the two areas that actually determine outcomes.

    In the end, whether you can build a complete agent has little to do with the number of tools. It depends on making the planning, confirmation, execution, and governance loops real. Treating the confirmation node as an architectural constraint rather than an add-on feature is what makes an agent ready for real business.