{"content_id":"oswgmcvvui","slug":"loop-engineering-concept-components","locale":"en","schema_type":"TechArticle","category":"ai_data","category_name":"AI Data","title":"The Concept and Essential Components of Loop Engineering","summary":"Loop Engineering is a design approach in which humans define goals and constraints, and AI agents iterate through the process of planning, execution, testing, and refinement to improve results. Its core components can be categorized as automation, worktrees, skills, plugins and connectors, subagents, and memory.","author":{"name":"Injoys Editorial Team","url":"https://injoys.com/ko/about"},"key_points":["Loop engineering is an approach that involves designing a task system that allows AI to repeatedly execute tasks until it achieves its goal, rather than simply writing prompts.","While Harness Engineering establishes a safe working environment and rules, Loop Engineering operates the iterative execution engine within that environment.","A safe loop requires an isolated workspace, clear instructions, tool connections, defined roles, state preservation, and termination conditions.","In AI development automation, a loop combines code writing, test execution, error analysis, retries, and review requests into a single closed-loop feedback cycle.","While loop engineering can increase productivity, it can become risky without mechanisms for access control, cost management, quality verification, and prevention of infinite loops."],"content_markdown":"## Overview\n\nLoop engineering is a method for designing an **iterative structure** in which an AI agent **plans, executes, evaluates results, reflects on the causes of failure, and tries again** to achieve a single goal. It is becoming particularly important in tasks where results can be verified, such as software development, data processing, document generation, and test automation.\n\nThis term is not yet established as a fixed academic term in all standard documents. However, in practice, it can be described as the next step beyond prompt engineering, context engineering, and harness engineering. The key is not “giving the AI good instructions once,” but “creating a system where the AI can iterate within a safe environment until it achieves its goal.”\n\n## The Evolution of AI Engineering: From Prompts to Loops\n\n| Stage | Key Questions | Human Role | AI Role | Representative Outputs |\n|---|---|---|---|---|\n| Prompt Engineering | How should I ask the question? | Writing instructions and verifying results | Generating a single response | Answers, drafts, code snippets |\n| Context Engineering | What background information should I provide? | Providing documents, examples, policies, and data | Reasoning within the given context | More consistent answers, tailored results |\n| Harness Engineering | In what environment and under what rules should it operate? | Designing permissions, tools, procedures, and safety rules | Using tools within a defined environment | Controlled agent workflow |\n| Loop Engineering | How to have the agent iterate until the goal is achieved | Setting goals, constraints, evaluation criteria, and termination conditions | Repeating execution, verification, modification, and retries | Self-improving task loops |\n\n### Prompt Engineering\n\nPrompt engineering is the process of carefully crafting questions, commands, examples, and output formats to elicit the desired results from AI. It is the most basic form of interaction and closely resembles a structure where a human changes instructions and verifies results each time.\n\n### Context Engineering\n\nContext engineering is a method of providing the model with documents, policies, codebase information, user preferences, output styles, and past conversations to achieve more accurate results. Long context windows, search-augmented generation, file attachments, and codebase indexing are all related to this stage.\n\n### Harness Engineering\n\nHarness engineering designs **the procedures and constraints within which the AI must operate** when using tools and performing multiple steps. For example, rules such as “Read the relevant files before modifying the code,” “Do not merge if tests fail,” and “Do not open files containing sensitive information” are embedded within the environment.\n\n### Loop Engineering\n\nLoop engineering involves overlaying a **iterative execution engine** on top of the controlled working environment created by harness. The AI agent independently selects its next action toward a goal, uses tools, evaluates results, and—if it fails—adjusts its strategy and executes again.\n\n## Core Definition of Loop Engineering\n\nLoop engineering can be defined as the design of an AI task system that satisfies the following conditions:\n\n- Humans define the ultimate goal, acceptable limits, evaluation criteria, and termination conditions.\n- The AI agent devises a task plan to achieve the goal.\n- The agent uses necessary tools, such as executing code, running tests, performing searches, modifying files, and making API calls.\n- If the execution results in failure or are insufficient, the agent analyzes the cause of failure and generates the next attempt.\n- The loop stops when termination conditions are met, such as goal achievement, budget overrun, exceeding the number of iterations, the occurrence of a risk signal, or the need for human approval.\n\nIn other words, the essence of loop engineering is an **automated feedback cycle**.\n\n## Why Is Loop Engineering Necessary?\n\nIn traditional AI workflows, humans often become the bottleneck. This is because humans must write prompts, review results, request revisions, run tests, and copy and paste error messages.\n\nLoop engineering systematizes this iterative process. For example, in development tasks, AI can automatically repeat the following workflow:\n\n1. Read the requirements and create a work plan.\n2. Modify the code in a separate workspace.\n3. Run tests and linters.\n4. Analyze error logs.\n5. Generate a revised prompt or determine the next action on its own.\n6. Modify the code again.\n7. If the pass criteria are met, summarize the results and request a review.\n\nIn this structure, humans do not need to directly instruct every intermediate step. Instead, humans focus on setting goals, providing approval, handling exceptions, and making final quality judgments.\n\n## The 6 Essential Components of Loop Engineering\n\n### 1. Automation: The Engine That Actually Runs the Loop\n\nAutomation is the foundation that enables the loop to run without manual human input. This includes task queues, schedulers, CI/CD pipelines, agent runtimes, event triggers, and retry policies.\n\nAutomation handles the following functions:\n\n- Detecting task start conditions\n- Running agents\n- Invoking tools and collecting results\n- Executing test or validation steps\n- Retrying in case of failure\n- Storing logs\n- Transitioning to human approval steps\n- Limiting costs, time, and number of iterations\n\nAutomation is not merely “automatic execution”; it is a control mechanism that manages the loop’s lifecycle.\n\n### 2. Worktree: A Secure Workspace\n\nA worktree is an isolated workspace designed to prevent AI from directly corrupting the main code or actual production data. A typical approach, similar to Git’s `worktree` feature, involves creating a separate working directory within the same repository to allow for independent modification and testing.\n\nWorktrees are important for the following reasons:\n\n- They protect the main branch or production environment.\n- Multiple agents can perform different tasks in parallel.\n- Failed attempts can be easily discarded.\n- Changes can be reviewed via diffs.\n- Only changes that pass testing can be merged.\n\nIn loop engineering, a worktree serves as the AI’s experimental space. To ensure the entire system remains secure even when agents make bold modifications, workspace isolation is essential.\n\n### 3. Skills: Guidelines for Performing Tasks\n\nSkills are a collection of guidelines, procedures, checklists, coding rules, design principles, and examples that AI must follow when performing specific tasks. Just as humans provide onboarding documents to new team members, agents also need standards for performing their work.\n\nSkill documentation may include the following information:\n\n- Description of the project structure and core modules\n- Code style and naming conventions\n- Test writing guidelines\n- API design principles\n- Security prohibitions\n- Pre-deployment checklist\n- Locations of logs to check in case of failure\n- Report format\n\nWithout skills, agents must rely on general reasoning every time. Conversely, well-written skills convey the organization’s way of working to the AI in a reusable format.\n\n### 4. Plugins and Connectors: Access to Necessary Tools\n\nPlugins and connectors allow the AI to access the tools and systems it needs while working. For example, code repositories, issue trackers, search systems, databases, document repositories, test runners, browsers, deployment tools, and notification systems can all be connected.\n\nThe reason for connecting these tools is clear. If an agent determines that it “needs to run a test” but lacks the permission to do so, the loop will stall. If it determines that it “needs to check relevant documentation” but has no way to access the documents, it is more likely to provide an answer based on guesswork.\n\nGood connector design requires the following principles:\n\n- Apply the principle of least privilege.\n- Separate read and write permissions.\n- Include an approval step for risky operations.\n- Log all tool calls.\n- Restrict access to sensitive information through a separate policy.\n- Log failed tool calls in the loop status as well.\n\n### 5. Sub-Agents: AI Workers with Divided Roles\n\nA sub-agent structure ensures that a single main agent does not handle all tasks, but rather that agents with distinct roles collaborate. Similar to a human development team, roles such as design, backend, frontend, QA, security review, and documentation can be separated.\n\n| Role | Key Responsibilities | Example Output |\n|---|---|---|\n| Planner Agent | Requirements analysis, task decomposition, priority setting | Implementation plan, task list |\n| Backend Agent | API, data model, and server logic implementation | Code changes, testing |\n| Front-End Agent | UI, state management, accessibility improvements | Component modifications, screen tests |\n| QA Agent | Test execution, bug reproduction, regression verification | Failure logs, reproduction steps |\n| Review Agent | Code quality, security, and style checks | Review comments, risk list |\n| Documentation Agent | Describing changes, writing usage guides | Release notes, user guides |\n\nThe advantage of a sub-agent structure is that it allows for the division of expertise. However, since conflicts between agents, duplicate work, and unclear responsibilities can arise, a coordinator role and clear work agreements are necessary.\n\n### 6. Memory: State Preservation That Enables Pausing and Resuming\n\nMemory is the functionality that stores the current state of the loop, past attempts, causes of failure, reasons for decisions, file changes, test results, and the next action plan. The longer the loop, the more essential memory becomes.\n\nMemory can be broadly divided into two types.\n\n- Short-term memory: Plans for the current work session, logs, results of tool calls, and error messages\n- Long-term memory: Project rules, past solutions, recurring bug patterns, user preferences, and team standards\n\nWithout memory, an agent may repeat the same mistakes or have to restart a task from the beginning if it was interrupted. Conversely, well-designed memory ensures the loop continues reliably and reduces costs.\n\n## Basic Architecture of Loop Engineering\n\nA loop engineering system typically has the following structure:\n\n1. Goal Input: A human provides the problem to be solved and the criteria for completion.\n2. Context Collection: Reads code, documentation, issues, logs, and policies.\n3. Planning: The agent breaks the task down into small steps.\n4. Execution: Modifies code, generates files, processes data, and invokes tools.\n5. Verification: Runs tests, lint checks, type checks, policy checks, and reviews.\n6. Evaluation: Determines whether the target criteria have been met.\n7. Iteration: If the task fails, analyzes the cause and returns to planning a new strategy.\n8. Termination: The process stops upon one of the following: success, exceeding limits, detecting risks, or requiring human approval.\n9. Reporting: Summarize changes, verification results, remaining risks, and recommended next steps.\n\nThis workflow is based on the premise of an “AI that acts in real-world environments and verifies results,” rather than an “AI that merely thinks in a loop.”\n\n## The Difference Between Harness Engineering and Loop Engineering\n\n| Category | Harness Engineering | Loop Engineering |\n|---|---|---|\n| Purpose | Creates an environment where AI can work safely | Enables AI to iterate until it achieves its goal |\n| Key Elements | Rules, permissions, tools, procedures, constraints | Iterative execution, feedback, retries, state saving |\n| Failure Response | Prevent dangerous actions or request approval | Generate the next attempt based on the cause of failure |\n| Human Intervention | Focus on policy and environment design | Focus on goal setting, exception handling, and final approval |\n| Analogy | Workplace and safety equipment | A production line that keeps the workplace running |\n\nIf you create a loop without a harness, the agent may engage in dangerous behavior due to excessive permissions. If you create only a harness without a loop, you have a safe environment but limited productivity. In practice, both approaches are necessary.\n\n## Application Example: Loops in AI Coding Agents\n\nIn software development, loop engineering is relatively easy to understand. For example, suppose we are given the goal: “Fix the login error.”\n\n### Input\n\n- Goal: Fix a bug causing login failures under specific conditions\n- Completion Criteria: Pass relevant tests, no regression in existing login functionality, submit a change summary\n- Constraints: Do not change the authentication token storage method; do not directly modify the user database\n\n### Loop Execution\n\n1. The agent reads the issue description and related files.\n2. Creates a separate branch or working directory in the work tree.\n3. Reproduces the failing test.\n4. Analyzes the error logs and relevant code.\n5. Applies the fix.\n6. Runs the tests.\n7. If it fails, summarize the cause and try another fix.\n8. If it succeeds, compile the diff, test results, and risk factors.\n9. Request merge approval from a human reviewer.\n\nIn this example, humans do not copy the error log and write a new prompt every time. Instead, the loop performs repetitive tasks, and the human intervenes at stages requiring final judgment and responsibility.\n\n## Control Variables That Must Be Defined During Design\n\nAlthough loop engineering is sometimes described as involving infinite repetition, “infinite” is dangerous in real systems. A safe loop requires clear limits.\n\n| Control Variable | Description | Example |\n|---|---|---|\n| Maximum Number of Iterations | Limits the number of times the same task can be retried | Maximum of 5 retries |\n| Time Budget | Limits the loop execution time | Stop if it exceeds 30 minutes |\n| Cost Budget | Limits costs for model calls, tool usage, and infrastructure | $10 or less per task |\n| Permission Scope | Separates read, write, execute, and deployment permissions | No write access to production DB |\n| Approval Points | Defines moments requiring human review | Approval required before deployment, deletion, payment, or external data transfer |\n| Success Criteria | Objective conditions for determining completion | Passing tests, meeting accuracy thresholds |\n| Failure Criteria | Red flags requiring termination | Three consecutive instances of the same error, security alerts triggered |\n\nA good loop is not one that runs endlessly, but **one that knows when to stop at the right moment**.\n\n## Quality Evaluation Criteria\n\nWhen evaluating a loop engineering system, you should look at the following metrics in addition to simply asking, “Did the AI provide an answer?”\n\n- Goal Achievement Rate: The percentage of tasks successfully completed\n- Number of Iterations to First Success: Whether there were unnecessary retries\n- Test pass rate: Whether automated verification criteria were met\n- Regression rate: The percentage of existing features that were broken\n- Number of human interventions: Whether automation actually reduced bottlenecks\n- Cost-effectiveness: Performance relative to model call costs and infrastructure costs\n- Auditability: Whether it is possible to track which tools were called and why\n- Security violation rate: Whether prohibited files, APIs, or data were accessed\n- Reproducibility: Whether similar results are obtained under the same conditions\n\nIn software development, in particular, simply passing tests may not be sufficient. Security, performance, maintainability, and user experience must also be evaluated.\n\n## Common Failure Patterns\n\n### 1. Ambiguous Success Criteria\n\nIf completion criteria are unclear—such as “Make it good”—it is difficult to find a basis for stopping the loop. Verifiable criteria are needed, such as “Add three unit tests, pass all existing tests, and maintain a response time of 200 ms or less.”\n\n### 2. When Tools Have Excessive Privileges\n\nGranting agents unlimited privileges—such as writing to production databases, performing deployments, or sending external emails—can cause a minor judgment error to lead to a major incident. High-risk tools must be isolated and operated on an approval-based basis.\n\n### 3. When Memory Is Missing or Corrupted\n\nWithout state persistence, the same failures will recur. Conversely, if incorrect data accumulates in memory, incorrect assumptions may be continuously reused. It is best to store verified facts, estimates, and failure logs separately in memory.\n\n### 4. When Responsibilities Overlap Among Sub-Agents\n\nIf multiple agents modify the same file simultaneously, conflicts may occur. Scope of work, file ownership, review order, and merge rules must be defined.\n\n### 5. When There Are No Cost Limits\n\nSince loops are iterative structures, the costs of model calls and tool executions can increase rapidly. You must limit the number of iterations, token usage, the number of external API calls, and execution time.\n\n## Implementation Checklist\n\nWhen applying loop engineering to a real project, it is recommended to check the following in this order.\n\n### Goals and Evaluation Criteria\n\n- Have you defined the problem to be solved in a single sentence?\n- Are the completion criteria automatically verifiable?\n- Have you identified criteria that require human approval?\n- Are there termination conditions in case of failure?\n\n### Work Environment\n\n- Is there a separate work tree from the main code?\n- Is the test execution environment reproducible?\n- Have you restricted access to secret keys and sensitive information?\n- Can changes be tracked via diff?\n\n### Guidelines and Context\n\n- Is there a description of the project structure?\n- Are coding and testing rules documented?\n- Are prohibited actions and security rules clearly defined?\n- Is the documentation referenced by the agent up to date?\n\n### Tools and Permissions\n\n- Are the necessary tools pre-configured?\n- Are tool-specific permissions minimized?\n- Is there an approval step for high-risk tool invocations?\n- Are logs kept for all tool invocations?\n\n### Loop Control\n\n- Are there maximum iteration counts and time limits?\n- Are there cost limits?\n- Does the system detect repeated errors?\n- Can intermediate states be saved and resumed?\n\n## Tasks Suitable and Unsuitable for Loop Engineering\n\n| Task Type | Suitability | Reason |\n|---|---:|---|\n| Code modification with tests | High | Success can be easily determined by execution results |\n| Linting, formatting, migration | High | Repetitive and has clear verification criteria |\n| Draft document creation and review | Medium | Can be automated but requires fact-checking |\n| Data cleansing | Medium to high | Effective when rules and sample validation are in place |\n| Security patches | Medium | Can be automated but requires expert review |\n| Legal judgments, medical diagnoses, investment advice | Low | High liability, expertise, and regulatory risks |\n| Direct Changes to Operating Systems | Low | Unauthorized automated loops pose a high risk of incidents |\n\nLoop engineering is most effective for “verifiable tasks.” Decisions where verification criteria are unclear or where liability is high require control by human experts.\n\n## Roadmap for Practical Application\n\n### Step 1: Create a Single-Task Loop\n\nStart by focusing on a single, small task. Narrow the scope to something like a loop that fixes test failures, corrects broken document links, or resolves typos.\n\n### Step 2: Secure the Harness\n\nDocument pre-task checks, editable files, executable commands, prohibited actions, and approval conditions. If this step is weak, the risk increases as the loop expands.\n\n### Step 3: Create a Work Tree and Logging System\n\nPerform all changes in an isolated environment, and log tool calls and test results. Even failed attempts are valuable data.\n\n### Step 4: Document Skills\n\nTurn knowledge required repeatedly into documented skills. Documents such as “How to Add Tests in This Project,” “Checklist for API Changes,” and “Front-End Accessibility Standards” are useful.\n\n### Step 5: Separating Sub-Agents\n\nAs tasks become more complex, separate roles such as planner, implementer, QA, and reviewer. Rather than creating too many agents from the start, it’s better to begin by dividing roles where bottlenecks have been identified.\n\n### Step 6: Improving Memory Usage and Evaluation Metrics\n\nRecord the causes of repeated failures, patterns of success, costs, and the frequency of human intervention. Use this data to improve the loop’s efficiency and safety.\n\n## Conclusion\n\nLoop engineering is a design approach that transforms AI agents from simple response generators into **goal-oriented task-execution systems**. The key is not to grant the AI blind autonomy, but to create a controlled environment through harness engineering and, within that environment, combine automation, work trees, skills, plugins and connectors, sub-agents, and memory to build a safe iterative structure.\n\nA well-designed Loop reduces the burden of repetitive human instructions and increases work speed. However, a Loop without safety measures can lead to increased costs, reduced quality, abuse of authority, and infinite loop problems. Therefore, the core principle of Loop Engineering is “automate, but make it verifiable, and ensure it stops when necessary.”","content_html":"\u003ch2\u003e\n\u003ca href=\"#overview\" class=\"anchor\" id=\"overview\"\u003e\u003c/a\u003eOverview\u003c/h2\u003e\n\u003cp\u003eLoop engineering is a method for designing an \u003cstrong\u003eiterative structure\u003c/strong\u003e in which an AI agent \u003cstrong\u003eplans, executes, evaluates results, reflects on the causes of failure, and tries again\u003c/strong\u003e to achieve a single goal. It is becoming particularly important in tasks where results can be verified, such as software development, data processing, document generation, and test automation.\u003c/p\u003e\n\u003cp\u003eThis term is not yet established as a fixed academic term in all standard documents. However, in practice, it can be described as the next step beyond prompt engineering, context engineering, and harness engineering. The key is not “giving the AI good instructions once,” but “creating a system where the AI can iterate within a safe environment until it achieves its goal.”\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#the-evolution-of-ai-engineering-from-prompts-to-loops\" class=\"anchor\" id=\"the-evolution-of-ai-engineering-from-prompts-to-loops\"\u003e\u003c/a\u003eThe Evolution of AI Engineering: From Prompts to Loops\u003c/h2\u003e\n\u003cdiv class=\"overflow-x-auto\"\u003e\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eStage\u003c/th\u003e\n\u003cth\u003eKey Questions\u003c/th\u003e\n\u003cth\u003eHuman Role\u003c/th\u003e\n\u003cth\u003eAI Role\u003c/th\u003e\n\u003cth\u003eRepresentative Outputs\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Stage\"\u003ePrompt Engineering\u003c/td\u003e\n\u003ctd data-label=\"Key Questions\"\u003eHow should I ask the question?\u003c/td\u003e\n\u003ctd data-label=\"Human Role\"\u003eWriting instructions and verifying results\u003c/td\u003e\n\u003ctd data-label=\"AI Role\"\u003eGenerating a single response\u003c/td\u003e\n\u003ctd data-label=\"Representative Outputs\"\u003eAnswers, drafts, code snippets\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Stage\"\u003eContext Engineering\u003c/td\u003e\n\u003ctd data-label=\"Key Questions\"\u003eWhat background information should I provide?\u003c/td\u003e\n\u003ctd data-label=\"Human Role\"\u003eProviding documents, examples, policies, and data\u003c/td\u003e\n\u003ctd data-label=\"AI Role\"\u003eReasoning within the given context\u003c/td\u003e\n\u003ctd data-label=\"Representative Outputs\"\u003eMore consistent answers, tailored results\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Stage\"\u003eHarness Engineering\u003c/td\u003e\n\u003ctd data-label=\"Key Questions\"\u003eIn what environment and under what rules should it operate?\u003c/td\u003e\n\u003ctd data-label=\"Human Role\"\u003eDesigning permissions, tools, procedures, and safety rules\u003c/td\u003e\n\u003ctd data-label=\"AI Role\"\u003eUsing tools within a defined environment\u003c/td\u003e\n\u003ctd data-label=\"Representative Outputs\"\u003eControlled agent workflow\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Stage\"\u003eLoop Engineering\u003c/td\u003e\n\u003ctd data-label=\"Key Questions\"\u003eHow to have the agent iterate until the goal is achieved\u003c/td\u003e\n\u003ctd data-label=\"Human Role\"\u003eSetting goals, constraints, evaluation criteria, and termination conditions\u003c/td\u003e\n\u003ctd data-label=\"AI Role\"\u003eRepeating execution, verification, modification, and retries\u003c/td\u003e\n\u003ctd data-label=\"Representative Outputs\"\u003eSelf-improving task loops\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\u003c/div\u003e\n\u003ch3\u003e\n\u003ca href=\"#prompt-engineering\" class=\"anchor\" id=\"prompt-engineering\"\u003e\u003c/a\u003ePrompt Engineering\u003c/h3\u003e\n\u003cp\u003ePrompt engineering is the process of carefully crafting questions, commands, examples, and output formats to elicit the desired results from AI. It is the most basic form of interaction and closely resembles a structure where a human changes instructions and verifies results each time.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#context-engineering\" class=\"anchor\" id=\"context-engineering\"\u003e\u003c/a\u003eContext Engineering\u003c/h3\u003e\n\u003cp\u003eContext engineering is a method of providing the model with documents, policies, codebase information, user preferences, output styles, and past conversations to achieve more accurate results. Long context windows, search-augmented generation, file attachments, and codebase indexing are all related to this stage.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#harness-engineering\" class=\"anchor\" id=\"harness-engineering\"\u003e\u003c/a\u003eHarness Engineering\u003c/h3\u003e\n\u003cp\u003eHarness engineering designs \u003cstrong\u003ethe procedures and constraints within which the AI must operate\u003c/strong\u003e when using tools and performing multiple steps. For example, rules such as “Read the relevant files before modifying the code,” “Do not merge if tests fail,” and “Do not open files containing sensitive information” are embedded within the environment.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#loop-engineering\" class=\"anchor\" id=\"loop-engineering\"\u003e\u003c/a\u003eLoop Engineering\u003c/h3\u003e\n\u003cp\u003eLoop engineering involves overlaying a \u003cstrong\u003eiterative execution engine\u003c/strong\u003e on top of the controlled working environment created by harness. The AI agent independently selects its next action toward a goal, uses tools, evaluates results, and—if it fails—adjusts its strategy and executes again.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#core-definition-of-loop-engineering\" class=\"anchor\" id=\"core-definition-of-loop-engineering\"\u003e\u003c/a\u003eCore Definition of Loop Engineering\u003c/h2\u003e\n\u003cp\u003eLoop engineering can be defined as the design of an AI task system that satisfies the following conditions:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eHumans define the ultimate goal, acceptable limits, evaluation criteria, and termination conditions.\u003c/li\u003e\n\u003cli\u003eThe AI agent devises a task plan to achieve the goal.\u003c/li\u003e\n\u003cli\u003eThe agent uses necessary tools, such as executing code, running tests, performing searches, modifying files, and making API calls.\u003c/li\u003e\n\u003cli\u003eIf the execution results in failure or are insufficient, the agent analyzes the cause of failure and generates the next attempt.\u003c/li\u003e\n\u003cli\u003eThe loop stops when termination conditions are met, such as goal achievement, budget overrun, exceeding the number of iterations, the occurrence of a risk signal, or the need for human approval.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn other words, the essence of loop engineering is an \u003cstrong\u003eautomated feedback cycle\u003c/strong\u003e.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#why-is-loop-engineering-necessary\" class=\"anchor\" id=\"why-is-loop-engineering-necessary\"\u003e\u003c/a\u003eWhy Is Loop Engineering Necessary?\u003c/h2\u003e\n\u003cp\u003eIn traditional AI workflows, humans often become the bottleneck. This is because humans must write prompts, review results, request revisions, run tests, and copy and paste error messages.\u003c/p\u003e\n\u003cp\u003eLoop engineering systematizes this iterative process. For example, in development tasks, AI can automatically repeat the following workflow:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eRead the requirements and create a work plan.\u003c/li\u003e\n\u003cli\u003eModify the code in a separate workspace.\u003c/li\u003e\n\u003cli\u003eRun tests and linters.\u003c/li\u003e\n\u003cli\u003eAnalyze error logs.\u003c/li\u003e\n\u003cli\u003eGenerate a revised prompt or determine the next action on its own.\u003c/li\u003e\n\u003cli\u003eModify the code again.\u003c/li\u003e\n\u003cli\u003eIf the pass criteria are met, summarize the results and request a review.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eIn this structure, humans do not need to directly instruct every intermediate step. Instead, humans focus on setting goals, providing approval, handling exceptions, and making final quality judgments.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#the-6-essential-components-of-loop-engineering\" class=\"anchor\" id=\"the-6-essential-components-of-loop-engineering\"\u003e\u003c/a\u003eThe 6 Essential Components of Loop Engineering\u003c/h2\u003e\n\u003ch3\u003e\n\u003ca href=\"#1-automation-the-engine-that-actually-runs-the-loop\" class=\"anchor\" id=\"1-automation-the-engine-that-actually-runs-the-loop\"\u003e\u003c/a\u003e1. Automation: The Engine That Actually Runs the Loop\u003c/h3\u003e\n\u003cp\u003eAutomation is the foundation that enables the loop to run without manual human input. This includes task queues, schedulers, CI/CD pipelines, agent runtimes, event triggers, and retry policies.\u003c/p\u003e\n\u003cp\u003eAutomation handles the following functions:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eDetecting task start conditions\u003c/li\u003e\n\u003cli\u003eRunning agents\u003c/li\u003e\n\u003cli\u003eInvoking tools and collecting results\u003c/li\u003e\n\u003cli\u003eExecuting test or validation steps\u003c/li\u003e\n\u003cli\u003eRetrying in case of failure\u003c/li\u003e\n\u003cli\u003eStoring logs\u003c/li\u003e\n\u003cli\u003eTransitioning to human approval steps\u003c/li\u003e\n\u003cli\u003eLimiting costs, time, and number of iterations\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eAutomation is not merely “automatic execution”; it is a control mechanism that manages the loop’s lifecycle.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#2-worktree-a-secure-workspace\" class=\"anchor\" id=\"2-worktree-a-secure-workspace\"\u003e\u003c/a\u003e2. Worktree: A Secure Workspace\u003c/h3\u003e\n\u003cp\u003eA worktree is an isolated workspace designed to prevent AI from directly corrupting the main code or actual production data. A typical approach, similar to Git’s \u003ccode\u003eworktree\u003c/code\u003e feature, involves creating a separate working directory within the same repository to allow for independent modification and testing.\u003c/p\u003e\n\u003cp\u003eWorktrees are important for the following reasons:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eThey protect the main branch or production environment.\u003c/li\u003e\n\u003cli\u003eMultiple agents can perform different tasks in parallel.\u003c/li\u003e\n\u003cli\u003eFailed attempts can be easily discarded.\u003c/li\u003e\n\u003cli\u003eChanges can be reviewed via diffs.\u003c/li\u003e\n\u003cli\u003eOnly changes that pass testing can be merged.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn loop engineering, a worktree serves as the AI’s experimental space. To ensure the entire system remains secure even when agents make bold modifications, workspace isolation is essential.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#3-skills-guidelines-for-performing-tasks\" class=\"anchor\" id=\"3-skills-guidelines-for-performing-tasks\"\u003e\u003c/a\u003e3. Skills: Guidelines for Performing Tasks\u003c/h3\u003e\n\u003cp\u003eSkills are a collection of guidelines, procedures, checklists, coding rules, design principles, and examples that AI must follow when performing specific tasks. Just as humans provide onboarding documents to new team members, agents also need standards for performing their work.\u003c/p\u003e\n\u003cp\u003eSkill documentation may include the following information:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eDescription of the project structure and core modules\u003c/li\u003e\n\u003cli\u003eCode style and naming conventions\u003c/li\u003e\n\u003cli\u003eTest writing guidelines\u003c/li\u003e\n\u003cli\u003eAPI design principles\u003c/li\u003e\n\u003cli\u003eSecurity prohibitions\u003c/li\u003e\n\u003cli\u003ePre-deployment checklist\u003c/li\u003e\n\u003cli\u003eLocations of logs to check in case of failure\u003c/li\u003e\n\u003cli\u003eReport format\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eWithout skills, agents must rely on general reasoning every time. Conversely, well-written skills convey the organization’s way of working to the AI in a reusable format.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#4-plugins-and-connectors-access-to-necessary-tools\" class=\"anchor\" id=\"4-plugins-and-connectors-access-to-necessary-tools\"\u003e\u003c/a\u003e4. Plugins and Connectors: Access to Necessary Tools\u003c/h3\u003e\n\u003cp\u003ePlugins and connectors allow the AI to access the tools and systems it needs while working. For example, code repositories, issue trackers, search systems, databases, document repositories, test runners, browsers, deployment tools, and notification systems can all be connected.\u003c/p\u003e\n\u003cp\u003eThe reason for connecting these tools is clear. If an agent determines that it “needs to run a test” but lacks the permission to do so, the loop will stall. If it determines that it “needs to check relevant documentation” but has no way to access the documents, it is more likely to provide an answer based on guesswork.\u003c/p\u003e\n\u003cp\u003eGood connector design requires the following principles:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eApply the principle of least privilege.\u003c/li\u003e\n\u003cli\u003eSeparate read and write permissions.\u003c/li\u003e\n\u003cli\u003eInclude an approval step for risky operations.\u003c/li\u003e\n\u003cli\u003eLog all tool calls.\u003c/li\u003e\n\u003cli\u003eRestrict access to sensitive information through a separate policy.\u003c/li\u003e\n\u003cli\u003eLog failed tool calls in the loop status as well.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003e\n\u003ca href=\"#5-sub-agents-ai-workers-with-divided-roles\" class=\"anchor\" id=\"5-sub-agents-ai-workers-with-divided-roles\"\u003e\u003c/a\u003e5. Sub-Agents: AI Workers with Divided Roles\u003c/h3\u003e\n\u003cp\u003eA sub-agent structure ensures that a single main agent does not handle all tasks, but rather that agents with distinct roles collaborate. Similar to a human development team, roles such as design, backend, frontend, QA, security review, and documentation can be separated.\u003c/p\u003e\n\u003cdiv class=\"overflow-x-auto\"\u003e\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eRole\u003c/th\u003e\n\u003cth\u003eKey Responsibilities\u003c/th\u003e\n\u003cth\u003eExample Output\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Role\"\u003ePlanner Agent\u003c/td\u003e\n\u003ctd data-label=\"Key Responsibilities\"\u003eRequirements analysis, task decomposition, priority setting\u003c/td\u003e\n\u003ctd data-label=\"Example Output\"\u003eImplementation plan, task list\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Role\"\u003eBackend Agent\u003c/td\u003e\n\u003ctd data-label=\"Key Responsibilities\"\u003eAPI, data model, and server logic implementation\u003c/td\u003e\n\u003ctd data-label=\"Example Output\"\u003eCode changes, testing\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Role\"\u003eFront-End Agent\u003c/td\u003e\n\u003ctd data-label=\"Key Responsibilities\"\u003eUI, state management, accessibility improvements\u003c/td\u003e\n\u003ctd data-label=\"Example Output\"\u003eComponent modifications, screen tests\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Role\"\u003eQA Agent\u003c/td\u003e\n\u003ctd data-label=\"Key Responsibilities\"\u003eTest execution, bug reproduction, regression verification\u003c/td\u003e\n\u003ctd data-label=\"Example Output\"\u003eFailure logs, reproduction steps\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Role\"\u003eReview Agent\u003c/td\u003e\n\u003ctd data-label=\"Key Responsibilities\"\u003eCode quality, security, and style checks\u003c/td\u003e\n\u003ctd data-label=\"Example Output\"\u003eReview comments, risk list\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Role\"\u003eDocumentation Agent\u003c/td\u003e\n\u003ctd data-label=\"Key Responsibilities\"\u003eDescribing changes, writing usage guides\u003c/td\u003e\n\u003ctd data-label=\"Example Output\"\u003eRelease notes, user guides\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\u003c/div\u003e\n\u003cp\u003eThe advantage of a sub-agent structure is that it allows for the division of expertise. However, since conflicts between agents, duplicate work, and unclear responsibilities can arise, a coordinator role and clear work agreements are necessary.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#6-memory-state-preservation-that-enables-pausing-and-resuming\" class=\"anchor\" id=\"6-memory-state-preservation-that-enables-pausing-and-resuming\"\u003e\u003c/a\u003e6. Memory: State Preservation That Enables Pausing and Resuming\u003c/h3\u003e\n\u003cp\u003eMemory is the functionality that stores the current state of the loop, past attempts, causes of failure, reasons for decisions, file changes, test results, and the next action plan. The longer the loop, the more essential memory becomes.\u003c/p\u003e\n\u003cp\u003eMemory can be broadly divided into two types.\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eShort-term memory: Plans for the current work session, logs, results of tool calls, and error messages\u003c/li\u003e\n\u003cli\u003eLong-term memory: Project rules, past solutions, recurring bug patterns, user preferences, and team standards\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eWithout memory, an agent may repeat the same mistakes or have to restart a task from the beginning if it was interrupted. Conversely, well-designed memory ensures the loop continues reliably and reduces costs.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#basic-architecture-of-loop-engineering\" class=\"anchor\" id=\"basic-architecture-of-loop-engineering\"\u003e\u003c/a\u003eBasic Architecture of Loop Engineering\u003c/h2\u003e\n\u003cp\u003eA loop engineering system typically has the following structure:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eGoal Input: A human provides the problem to be solved and the criteria for completion.\u003c/li\u003e\n\u003cli\u003eContext Collection: Reads code, documentation, issues, logs, and policies.\u003c/li\u003e\n\u003cli\u003ePlanning: The agent breaks the task down into small steps.\u003c/li\u003e\n\u003cli\u003eExecution: Modifies code, generates files, processes data, and invokes tools.\u003c/li\u003e\n\u003cli\u003eVerification: Runs tests, lint checks, type checks, policy checks, and reviews.\u003c/li\u003e\n\u003cli\u003eEvaluation: Determines whether the target criteria have been met.\u003c/li\u003e\n\u003cli\u003eIteration: If the task fails, analyzes the cause and returns to planning a new strategy.\u003c/li\u003e\n\u003cli\u003eTermination: The process stops upon one of the following: success, exceeding limits, detecting risks, or requiring human approval.\u003c/li\u003e\n\u003cli\u003eReporting: Summarize changes, verification results, remaining risks, and recommended next steps.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eThis workflow is based on the premise of an “AI that acts in real-world environments and verifies results,” rather than an “AI that merely thinks in a loop.”\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#the-difference-between-harness-engineering-and-loop-engineering\" class=\"anchor\" id=\"the-difference-between-harness-engineering-and-loop-engineering\"\u003e\u003c/a\u003eThe Difference Between Harness Engineering and Loop Engineering\u003c/h2\u003e\n\u003cdiv class=\"overflow-x-auto\"\u003e\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eCategory\u003c/th\u003e\n\u003cth\u003eHarness Engineering\u003c/th\u003e\n\u003cth\u003eLoop Engineering\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Category\"\u003ePurpose\u003c/td\u003e\n\u003ctd data-label=\"Harness Engineering\"\u003eCreates an environment where AI can work safely\u003c/td\u003e\n\u003ctd data-label=\"Loop Engineering\"\u003eEnables AI to iterate until it achieves its goal\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Category\"\u003eKey Elements\u003c/td\u003e\n\u003ctd data-label=\"Harness Engineering\"\u003eRules, permissions, tools, procedures, constraints\u003c/td\u003e\n\u003ctd data-label=\"Loop Engineering\"\u003eIterative execution, feedback, retries, state saving\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Category\"\u003eFailure Response\u003c/td\u003e\n\u003ctd data-label=\"Harness Engineering\"\u003ePrevent dangerous actions or request approval\u003c/td\u003e\n\u003ctd data-label=\"Loop Engineering\"\u003eGenerate the next attempt based on the cause of failure\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Category\"\u003eHuman Intervention\u003c/td\u003e\n\u003ctd data-label=\"Harness Engineering\"\u003eFocus on policy and environment design\u003c/td\u003e\n\u003ctd data-label=\"Loop Engineering\"\u003eFocus on goal setting, exception handling, and final approval\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Category\"\u003eAnalogy\u003c/td\u003e\n\u003ctd data-label=\"Harness Engineering\"\u003eWorkplace and safety equipment\u003c/td\u003e\n\u003ctd data-label=\"Loop Engineering\"\u003eA production line that keeps the workplace running\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\u003c/div\u003e\n\u003cp\u003eIf you create a loop without a harness, the agent may engage in dangerous behavior due to excessive permissions. If you create only a harness without a loop, you have a safe environment but limited productivity. In practice, both approaches are necessary.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#application-example-loops-in-ai-coding-agents\" class=\"anchor\" id=\"application-example-loops-in-ai-coding-agents\"\u003e\u003c/a\u003eApplication Example: Loops in AI Coding Agents\u003c/h2\u003e\n\u003cp\u003eIn software development, loop engineering is relatively easy to understand. For example, suppose we are given the goal: “Fix the login error.”\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#input\" class=\"anchor\" id=\"input\"\u003e\u003c/a\u003eInput\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eGoal: Fix a bug causing login failures under specific conditions\u003c/li\u003e\n\u003cli\u003eCompletion Criteria: Pass relevant tests, no regression in existing login functionality, submit a change summary\u003c/li\u003e\n\u003cli\u003eConstraints: Do not change the authentication token storage method; do not directly modify the user database\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003e\n\u003ca href=\"#loop-execution\" class=\"anchor\" id=\"loop-execution\"\u003e\u003c/a\u003eLoop Execution\u003c/h3\u003e\n\u003col\u003e\n\u003cli\u003eThe agent reads the issue description and related files.\u003c/li\u003e\n\u003cli\u003eCreates a separate branch or working directory in the work tree.\u003c/li\u003e\n\u003cli\u003eReproduces the failing test.\u003c/li\u003e\n\u003cli\u003eAnalyzes the error logs and relevant code.\u003c/li\u003e\n\u003cli\u003eApplies the fix.\u003c/li\u003e\n\u003cli\u003eRuns the tests.\u003c/li\u003e\n\u003cli\u003eIf it fails, summarize the cause and try another fix.\u003c/li\u003e\n\u003cli\u003eIf it succeeds, compile the diff, test results, and risk factors.\u003c/li\u003e\n\u003cli\u003eRequest merge approval from a human reviewer.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eIn this example, humans do not copy the error log and write a new prompt every time. Instead, the loop performs repetitive tasks, and the human intervenes at stages requiring final judgment and responsibility.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#control-variables-that-must-be-defined-during-design\" class=\"anchor\" id=\"control-variables-that-must-be-defined-during-design\"\u003e\u003c/a\u003eControl Variables That Must Be Defined During Design\u003c/h2\u003e\n\u003cp\u003eAlthough loop engineering is sometimes described as involving infinite repetition, “infinite” is dangerous in real systems. A safe loop requires clear limits.\u003c/p\u003e\n\u003cdiv class=\"overflow-x-auto\"\u003e\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eControl Variable\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003eMaximum Number of Iterations\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eLimits the number of times the same task can be retried\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003eMaximum of 5 retries\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003eTime Budget\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eLimits the loop execution time\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003eStop if it exceeds 30 minutes\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003eCost Budget\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eLimits costs for model calls, tool usage, and infrastructure\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003e$10 or less per task\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003ePermission Scope\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eSeparates read, write, execute, and deployment permissions\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003eNo write access to production DB\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003eApproval Points\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eDefines moments requiring human review\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003eApproval required before deployment, deletion, payment, or external data transfer\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003eSuccess Criteria\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eObjective conditions for determining completion\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003ePassing tests, meeting accuracy thresholds\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Control Variable\"\u003eFailure Criteria\u003c/td\u003e\n\u003ctd data-label=\"Description\"\u003eRed flags requiring termination\u003c/td\u003e\n\u003ctd data-label=\"Example\"\u003eThree consecutive instances of the same error, security alerts triggered\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\u003c/div\u003e\n\u003cp\u003eA good loop is not one that runs endlessly, but \u003cstrong\u003eone that knows when to stop at the right moment\u003c/strong\u003e.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#quality-evaluation-criteria\" class=\"anchor\" id=\"quality-evaluation-criteria\"\u003e\u003c/a\u003eQuality Evaluation Criteria\u003c/h2\u003e\n\u003cp\u003eWhen evaluating a loop engineering system, you should look at the following metrics in addition to simply asking, “Did the AI provide an answer?”\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eGoal Achievement Rate: The percentage of tasks successfully completed\u003c/li\u003e\n\u003cli\u003eNumber of Iterations to First Success: Whether there were unnecessary retries\u003c/li\u003e\n\u003cli\u003eTest pass rate: Whether automated verification criteria were met\u003c/li\u003e\n\u003cli\u003eRegression rate: The percentage of existing features that were broken\u003c/li\u003e\n\u003cli\u003eNumber of human interventions: Whether automation actually reduced bottlenecks\u003c/li\u003e\n\u003cli\u003eCost-effectiveness: Performance relative to model call costs and infrastructure costs\u003c/li\u003e\n\u003cli\u003eAuditability: Whether it is possible to track which tools were called and why\u003c/li\u003e\n\u003cli\u003eSecurity violation rate: Whether prohibited files, APIs, or data were accessed\u003c/li\u003e\n\u003cli\u003eReproducibility: Whether similar results are obtained under the same conditions\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn software development, in particular, simply passing tests may not be sufficient. Security, performance, maintainability, and user experience must also be evaluated.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#common-failure-patterns\" class=\"anchor\" id=\"common-failure-patterns\"\u003e\u003c/a\u003eCommon Failure Patterns\u003c/h2\u003e\n\u003ch3\u003e\n\u003ca href=\"#1-ambiguous-success-criteria\" class=\"anchor\" id=\"1-ambiguous-success-criteria\"\u003e\u003c/a\u003e1. Ambiguous Success Criteria\u003c/h3\u003e\n\u003cp\u003eIf completion criteria are unclear—such as “Make it good”—it is difficult to find a basis for stopping the loop. Verifiable criteria are needed, such as “Add three unit tests, pass all existing tests, and maintain a response time of 200 ms or less.”\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#2-when-tools-have-excessive-privileges\" class=\"anchor\" id=\"2-when-tools-have-excessive-privileges\"\u003e\u003c/a\u003e2. When Tools Have Excessive Privileges\u003c/h3\u003e\n\u003cp\u003eGranting agents unlimited privileges—such as writing to production databases, performing deployments, or sending external emails—can cause a minor judgment error to lead to a major incident. High-risk tools must be isolated and operated on an approval-based basis.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#3-when-memory-is-missing-or-corrupted\" class=\"anchor\" id=\"3-when-memory-is-missing-or-corrupted\"\u003e\u003c/a\u003e3. When Memory Is Missing or Corrupted\u003c/h3\u003e\n\u003cp\u003eWithout state persistence, the same failures will recur. Conversely, if incorrect data accumulates in memory, incorrect assumptions may be continuously reused. It is best to store verified facts, estimates, and failure logs separately in memory.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#4-when-responsibilities-overlap-among-sub-agents\" class=\"anchor\" id=\"4-when-responsibilities-overlap-among-sub-agents\"\u003e\u003c/a\u003e4. When Responsibilities Overlap Among Sub-Agents\u003c/h3\u003e\n\u003cp\u003eIf multiple agents modify the same file simultaneously, conflicts may occur. Scope of work, file ownership, review order, and merge rules must be defined.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#5-when-there-are-no-cost-limits\" class=\"anchor\" id=\"5-when-there-are-no-cost-limits\"\u003e\u003c/a\u003e5. When There Are No Cost Limits\u003c/h3\u003e\n\u003cp\u003eSince loops are iterative structures, the costs of model calls and tool executions can increase rapidly. You must limit the number of iterations, token usage, the number of external API calls, and execution time.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#implementation-checklist\" class=\"anchor\" id=\"implementation-checklist\"\u003e\u003c/a\u003eImplementation Checklist\u003c/h2\u003e\n\u003cp\u003eWhen applying loop engineering to a real project, it is recommended to check the following in this order.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#goals-and-evaluation-criteria\" class=\"anchor\" id=\"goals-and-evaluation-criteria\"\u003e\u003c/a\u003eGoals and Evaluation Criteria\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eHave you defined the problem to be solved in a single sentence?\u003c/li\u003e\n\u003cli\u003eAre the completion criteria automatically verifiable?\u003c/li\u003e\n\u003cli\u003eHave you identified criteria that require human approval?\u003c/li\u003e\n\u003cli\u003eAre there termination conditions in case of failure?\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003e\n\u003ca href=\"#work-environment\" class=\"anchor\" id=\"work-environment\"\u003e\u003c/a\u003eWork Environment\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eIs there a separate work tree from the main code?\u003c/li\u003e\n\u003cli\u003eIs the test execution environment reproducible?\u003c/li\u003e\n\u003cli\u003eHave you restricted access to secret keys and sensitive information?\u003c/li\u003e\n\u003cli\u003eCan changes be tracked via diff?\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003e\n\u003ca href=\"#guidelines-and-context\" class=\"anchor\" id=\"guidelines-and-context\"\u003e\u003c/a\u003eGuidelines and Context\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eIs there a description of the project structure?\u003c/li\u003e\n\u003cli\u003eAre coding and testing rules documented?\u003c/li\u003e\n\u003cli\u003eAre prohibited actions and security rules clearly defined?\u003c/li\u003e\n\u003cli\u003eIs the documentation referenced by the agent up to date?\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003e\n\u003ca href=\"#tools-and-permissions\" class=\"anchor\" id=\"tools-and-permissions\"\u003e\u003c/a\u003eTools and Permissions\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eAre the necessary tools pre-configured?\u003c/li\u003e\n\u003cli\u003eAre tool-specific permissions minimized?\u003c/li\u003e\n\u003cli\u003eIs there an approval step for high-risk tool invocations?\u003c/li\u003e\n\u003cli\u003eAre logs kept for all tool invocations?\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003e\n\u003ca href=\"#loop-control\" class=\"anchor\" id=\"loop-control\"\u003e\u003c/a\u003eLoop Control\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eAre there maximum iteration counts and time limits?\u003c/li\u003e\n\u003cli\u003eAre there cost limits?\u003c/li\u003e\n\u003cli\u003eDoes the system detect repeated errors?\u003c/li\u003e\n\u003cli\u003eCan intermediate states be saved and resumed?\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2\u003e\n\u003ca href=\"#tasks-suitable-and-unsuitable-for-loop-engineering\" class=\"anchor\" id=\"tasks-suitable-and-unsuitable-for-loop-engineering\"\u003e\u003c/a\u003eTasks Suitable and Unsuitable for Loop Engineering\u003c/h2\u003e\n\u003cdiv class=\"overflow-x-auto\"\u003e\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eTask Type\u003c/th\u003e\n\u003cth\u003eSuitability\u003c/th\u003e\n\u003cth\u003eReason\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eCode modification with tests\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eHigh\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eSuccess can be easily determined by execution results\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eLinting, formatting, migration\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eHigh\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eRepetitive and has clear verification criteria\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eDraft document creation and review\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eMedium\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eCan be automated but requires fact-checking\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eData cleansing\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eMedium to high\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eEffective when rules and sample validation are in place\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eSecurity patches\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eMedium\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eCan be automated but requires expert review\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eLegal judgments, medical diagnoses, investment advice\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eLow\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eHigh liability, expertise, and regulatory risks\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd data-label=\"Task Type\"\u003eDirect Changes to Operating Systems\u003c/td\u003e\n\u003ctd data-label=\"Suitability\"\u003eLow\u003c/td\u003e\n\u003ctd data-label=\"Reason\"\u003eUnauthorized automated loops pose a high risk of incidents\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\u003c/div\u003e\n\u003cp\u003eLoop engineering is most effective for “verifiable tasks.” Decisions where verification criteria are unclear or where liability is high require control by human experts.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#roadmap-for-practical-application\" class=\"anchor\" id=\"roadmap-for-practical-application\"\u003e\u003c/a\u003eRoadmap for Practical Application\u003c/h2\u003e\n\u003ch3\u003e\n\u003ca href=\"#step-1-create-a-single-task-loop\" class=\"anchor\" id=\"step-1-create-a-single-task-loop\"\u003e\u003c/a\u003eStep 1: Create a Single-Task Loop\u003c/h3\u003e\n\u003cp\u003eStart by focusing on a single, small task. Narrow the scope to something like a loop that fixes test failures, corrects broken document links, or resolves typos.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#step-2-secure-the-harness\" class=\"anchor\" id=\"step-2-secure-the-harness\"\u003e\u003c/a\u003eStep 2: Secure the Harness\u003c/h3\u003e\n\u003cp\u003eDocument pre-task checks, editable files, executable commands, prohibited actions, and approval conditions. If this step is weak, the risk increases as the loop expands.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#step-3-create-a-work-tree-and-logging-system\" class=\"anchor\" id=\"step-3-create-a-work-tree-and-logging-system\"\u003e\u003c/a\u003eStep 3: Create a Work Tree and Logging System\u003c/h3\u003e\n\u003cp\u003ePerform all changes in an isolated environment, and log tool calls and test results. Even failed attempts are valuable data.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#step-4-document-skills\" class=\"anchor\" id=\"step-4-document-skills\"\u003e\u003c/a\u003eStep 4: Document Skills\u003c/h3\u003e\n\u003cp\u003eTurn knowledge required repeatedly into documented skills. Documents such as “How to Add Tests in This Project,” “Checklist for API Changes,” and “Front-End Accessibility Standards” are useful.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#step-5-separating-sub-agents\" class=\"anchor\" id=\"step-5-separating-sub-agents\"\u003e\u003c/a\u003eStep 5: Separating Sub-Agents\u003c/h3\u003e\n\u003cp\u003eAs tasks become more complex, separate roles such as planner, implementer, QA, and reviewer. Rather than creating too many agents from the start, it’s better to begin by dividing roles where bottlenecks have been identified.\u003c/p\u003e\n\u003ch3\u003e\n\u003ca href=\"#step-6-improving-memory-usage-and-evaluation-metrics\" class=\"anchor\" id=\"step-6-improving-memory-usage-and-evaluation-metrics\"\u003e\u003c/a\u003eStep 6: Improving Memory Usage and Evaluation Metrics\u003c/h3\u003e\n\u003cp\u003eRecord the causes of repeated failures, patterns of success, costs, and the frequency of human intervention. Use this data to improve the loop’s efficiency and safety.\u003c/p\u003e\n\u003ch2\u003e\n\u003ca href=\"#conclusion\" class=\"anchor\" id=\"conclusion\"\u003e\u003c/a\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eLoop engineering is a design approach that transforms AI agents from simple response generators into \u003cstrong\u003egoal-oriented task-execution systems\u003c/strong\u003e. The key is not to grant the AI blind autonomy, but to create a controlled environment through harness engineering and, within that environment, combine automation, work trees, skills, plugins and connectors, sub-agents, and memory to build a safe iterative structure.\u003c/p\u003e\n\u003cp\u003eA well-designed Loop reduces the burden of repetitive human instructions and increases work speed. However, a Loop without safety measures can lead to increased costs, reduced quality, abuse of authority, and infinite loop problems. Therefore, the core principle of Loop Engineering is “automate, but make it verifiable, and ensure it stops when necessary.”\u003c/p\u003e\n","tags":["AI Agents","Loop engineering","Automation","Development workflow","LLMOps"],"faqs":[{"question":"What is Loop Engineering?","answer":"Loop engineering is a method of designing task systems so that AI agents repeatedly plan, execute, verify, adjust, and retry until they achieve their goals. It involves more than just writing good prompts; it also includes automatic iteration, tool usage, state saving, and termination conditions."},{"question":"What is the difference between loop engineering and prompt engineering?","answer":"Prompt engineering focuses on effectively conveying a single instruction to an AI. Loop engineering is a more systematic approach in that it involves designing a closed-loop feedback structure in which the AI checks the results, takes the causes of failure into account, and then runs the process again."},{"question":"What is the difference between harness engineering and loop engineering?","answer":"Harness engineering involves creating the rules, permissions, tools, and environment that enable AI to work safely. Loop engineering involves ensuring that, within that controlled environment, the AI repeatedly executes tasks until it achieves its goals."},{"question":"Why does Loop Engineering need a work tree?","answer":"WorkTree provides an isolated workspace where AI can experiment without compromising the main code or the production environment. It enhances the safety of the AI coding loop by allowing users to discard failed changes and review only the successful ones."},{"question":"What does \"skill\" mean at Loop Engineering?","answer":"Skills are documented work standards—such as guidelines, checklists, coding rules, testing rules, and security policies—that AI refers to when performing tasks. The clearer the skills are, the more likely the agent is to work in accordance with the organization’s practices."},{"question":"Why Are Plug-Ins and Connectors Important?","answer":"Plugins and connectors allow AI to access tools such as repositories, documents, test runners, issue trackers, and databases. If the necessary tools aren’t connected, the loop may stop midway or rely on guesswork."},{"question":"When is a sub-agent needed?","answer":"Sub-agents are useful when work is divided into various specialized roles, such as design, backend, frontend, QA, and review. However, if the scope of roles and responsibilities is unclear, conflicts may arise, so coordination rules are necessary."},{"question":"What role does memory play in loop engineering?","answer":"Memory stores the current work status, previous attempts, causes of failure, test results, and the next plan. This allows the loop to resume from where it left off even if it is interrupted, thereby reducing the likelihood of repeating the same mistakes."},{"question":"Does \"loop engineering\" mean infinite repetition?","answer":"Conceptually, this means repeating the process until the goal is achieved, but in a real-world system, unlimited repetition is risky. It is essential to set a maximum number of iterations, time limits, cost limits, failure detection mechanisms, and human approval conditions."},{"question":"What kind of work is Loop Engineering best suited for?","answer":"It is well-suited for repetitive tasks with clear validation criteria, such as modifying code with tests, linting and formatting, data cleansing, and document review. Areas involving high levels of responsibility—such as legal judgments, medical diagnoses, and investment decisions—should not be handled solely by automated loops."},{"question":"What is the greatest risk associated with loop engineering?","answer":"The main risks include excessive privileges, unlimited retries, skyrocketing costs, accumulation of incorrect memory, unverified automated deployment, and access to sensitive information. Therefore, privilege minimization, logging, approval steps, and termination conditions are essential."},{"question":"What is the best way to get started with loop engineering?","answer":"It’s best to start with a single small, verifiable task, such as fixing failed tests, checking document links, or correcting typos. After that, it’s safest to proceed step by step, gradually adding the work tree, skill documentation, tool integrations, memory, and subagents."}],"sources":[{"url":"https://git-scm.com/docs/git-worktree","title":"Git documentation: git-worktree","type":"source"},{"url":"https://docs.github.com/en/actions","title":"GitHub Docs: GitHub Actions documentation","type":"source"},{"url":"https://platform.openai.com/docs/guides/function-calling","title":"OpenAI Platform Docs: Function Calls","type":"source"},{"url":"https://modelcontextprotocol.io/introduction","title":"Model Context Protocol: Introduction","type":"source"},{"url":"https://langchain-ai.github.io/langgraph/concepts/persistence/","title":"LangGraph Documentation: Persistence","type":"source"},{"url":"https://arxiv.org/abs/2210.03629","title":"ReAct: Synergizing Reasoning and Acting in Language Models","type":"source"},{"url":"https://arxiv.org/abs/2303.11366","title":"Reflexion: Language Agents with Verbal Reinforcement Learning","type":"source"}],"images":[{"id":234,"url":"https://injoys.com/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MjMwMSwicHVyIjoiYmxvYl9pZCJ9fQ==--e2cc0e235018c6d93b44f9fe5cf3889bea5aa10a/ai-cccc7ad2.webp","is_representative":true,"generation_method":"ai_image","license":"ai_generated","mime_type":"image/webp","translations":{"ko":{"alt":"중앙 AI 로봇과 순환 화살표, 자동화·문서·검증·데이터 아이콘이 둘러싼 다이어그램","caption":"AI 시스템을 반복적으로 설계, 실행, 검증하는 루프 엔지니어링 흐름을 보여준다.","description":null},"en":{"alt":"Central AI bot surrounded by circular workflow arrows and icons for automation, documents, validation, and data","caption":"The diagram illustrates a loop engineering workflow around an AI system.","description":null},"ja":{"alt":"中央のAIロボットを囲む循環矢印と自動化、文書、検証、データのアイコン","caption":"AIシステムを中心に設計、実行、検証を繰り返す流れを示している。","description":null},"es":{"alt":"Bot de IA central rodeado de flechas circulares e iconos de automatización, documentos, validación y datos","caption":"El diagrama muestra un flujo de ingeniería en bucle alrededor de un sistema de IA.","description":null},"id":{"alt":"Bot AI di tengah dikelilingi panah alur melingkar dan ikon otomasi, dokumen, validasi, serta data","caption":"Diagram ini menunjukkan alur rekayasa loop yang berulang di sekitar sistem AI.","description":null},"pt":{"alt":"Bot de IA central cercado por setas de fluxo circular e ícones de automação, documentos, validação e dados","caption":"O diagrama mostra um fluxo de engenharia em loop em torno de um sistema de IA.","description":null},"zh-hant":{"alt":"中央 AI 機器人周圍有循環箭頭，以及自動化、文件、驗證與資料圖示","caption":"此圖呈現圍繞 AI 系統反覆設計、執行與驗證的迴圈工程流程。","description":null}}},{"id":235,"url":"https://injoys.com/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MjMwNywicHVyIjoiYmxvYl9pZCJ9fQ==--6e96b4db0ce479ff3ba8d0cefc6dafb74a3e9ce0/ai-20876eb8.webp","is_representative":false,"generation_method":"ai_image","license":"ai_generated","mime_type":"image/webp","translations":{"ko":{"alt":"로봇과 연결된 작업대가 순환 파이프라인으로 이어진 자동화 검증 시스템","caption":"보안, 테스트, 피드백이 연결된 루프 엔지니어링 흐름을 시각화합니다.","description":null},"en":{"alt":"Automated validation system with robots, connected stations, and a looping pipeline","caption":"The illustration shows a loop engineering workflow linking security, testing, and feedback.","description":null},"ja":{"alt":"ロボットと接続された端末が循環パイプラインでつながる自動検証システム","caption":"セキュリティ、テスト、フィードバックを結ぶループエンジニアリングの流れを示しています。","description":null},"es":{"alt":"Sistema de validación automatizada con robots, estaciones conectadas y canalización en bucle","caption":"La ilustración muestra un flujo de ingeniería en bucle que conecta seguridad, pruebas y retroalimentación.","description":null},"id":{"alt":"Sistem validasi otomatis dengan robot, stasiun terhubung, dan alur pipa berulang","caption":"Ilustrasi ini menampilkan alur rekayasa loop yang menghubungkan keamanan, pengujian, dan umpan balik.","description":null},"pt":{"alt":"Sistema de validação automatizada com robôs, estações conectadas e pipeline em ciclo","caption":"A ilustração mostra um fluxo de engenharia em loop que conecta segurança, testes e feedback.","description":null},"zh-hant":{"alt":"機器人與連接工作站透過循環管線組成的自動化驗證系統","caption":"這張插圖呈現連結安全、測試與回饋的迴圈工程流程。","description":null}}}],"published_at":"2026-07-20T15:26:45+09:00","updated_at":"2026-07-20T15:26:45+09:00","license":"cc_by","translation_status":"reviewed","available_locales":["ko","en","ja","es"],"data_locales":["ko","en","ja","es","id","pt","zh-hant"],"url":"https://injoys.com/en/articles/loop-engineering-concept-components"}