Agent Engineering in Practice: Main Loops and Progressive Capability Loading
This article examines how to build reliable agent applications by starting with a unified main loop, structured task state, progressive capability disclosure, and deterministic tool governance. It explains how to decide when sub-agents are justified, how to evaluate architectures against business outcomes and full execution cost, and how to evolve from a minimal closed-loop system instead of adding roles by default.
1. From “Adding Agents” to Reducing System Complexity
When building agent applications, a common approach is to split complex tasks across multiple roles: one for planning, one for retrieval, one for execution, and another for review. This design looks similar to team collaboration, but adding more roles does not automatically improve task quality.
Each additional sub-agent usually requires another context set, another task handoff, and corresponding result aggregation and exception-handling logic. If task boundaries are unclear, multiple execution units may investigate the same issue repeatedly, adopt inconsistent assumptions, or produce conclusions that are locally correct but globally conflicting.
For engineering design, the first question is therefore not “How many agents should be configured?” but:
- Which steps must share the full task state?
- Which work can be executed and verified independently?
- Is the current bottleneck insufficient knowledge, insufficient tool capability, or inefficient task coordination?
- After adding an execution unit, does the benefit outweigh the added communication and governance cost?
For many tasks with relatively continuous workflows and clear context dependencies, “one main agent loop plus capability instructions and tools loaded on demand” is worth evaluating as a baseline option. It is not universally better than multi-agent architectures. The final choice should be validated through real tasks, not judged only by architectural form.
2. Understanding the Main Loop: Unified Management of Decisions and Task State
The main agent loop can be understood as a continuously running decision process: receive a goal, read the current state, choose the next action, execute it, observe the result, and then decide whether to continue, adjust, or stop.
A typical flow is:
Task input → state organization → action selection → tool execution → result validation → state update → continue or stop.
Here, “single” means that the main decision path remains unified. It does not require all computation to be serial. The main loop can still call parallel retrieval, batch processing, and other tools. The same control entity maintains the task goal, key constraints, and final delivery responsibility.
1. Unified State Reduces Handoff Loss
Suppose the system needs to analyze a business report. The user first asks for an explanation of revenue changes and then adds “excluding unconfirmed orders.” If planning, querying, and analysis are handled by different sub-agents, this constraint must be accurately passed to every relevant execution unit.
When the main loop maintains a unified task state, it can record this restriction directly as a condition that subsequent operations must follow. This does not eliminate all errors, but it reduces deviations caused by information retelling, omitted summaries, and out-of-sync context.
2. State Should Be Structured, Not an Ever-Growing Conversation
Unified context does not mean storing all historical content. For long-running tasks, information should be divided into categories:
- Goals and constraints: final deliverables, allowed scope, prohibited operations.
- Confirmed facts: information obtained through queries or validation, along with its sources.
- Assumptions to verify: explanations or inferences that have not yet been confirmed.
- Execution log: completed actions, failure reasons, and changes in external resources.
- Next-step plan: remaining questions and possible paths.
Structured state helps the system preserve key constraints when compressing history and prevents guesses from being solidified as facts. For important conclusions, evidence references should also be retained rather than leaving only natural-language summaries.
3. Progressive Disclosure: Load Only the Capability Instructions Needed
If all rules, business processes, and tool instructions are placed into the initial context at once, the system may face information redundancy, rule conflicts, and difficulty in selection. Conversely, if instructions are too brief, tools may be misused or key steps may be omitted.
The core of progressive disclosure is to match information supply with the current task stage.
1. Organize Capabilities into Three Layers
The first layer is global constraints that are always visible, such as data access boundaries, approval requirements for external operations, and completion conditions.
The second layer is a capability catalog that uses short descriptions to tell the main loop what kinds of work can be done, such as document lookup, data statistics, configuration checks, and report generation. The catalog should be sufficient to support initial selection without containing all operational details.
The third layer is specific capability instructions, loaded only when a relevant task appears. It can include applicability conditions, input requirements, operational steps, validation methods, and stopping conditions.
For example, when the task is only to explain a piece of text, there is no need to load data-change procedures. When the task involves modifying business records, instructions for pre-change checks, approval, execution, and rollback should be loaded.
2. Design Capability Instructions and Tools Separately
Capability instructions describe how to complete a class of tasks, while tools provide operations that can actually be executed. The two should not be conflated.
“Verify statistical definitions” is a process capability that may require reading field definitions, querying sample data, and comparing calculation results. “Read a specified record” is a concrete tool action.
Separating the two has two benefits. First, the same process can combine different underlying tools. Second, tool permissions can be controlled independently. Loading a capability instruction does not mean the system automatically receives all operational permissions involved in that capability.
3. Dynamic Loading Still Requires Rule Governance
Progressive disclosure only reduces the scope of information exposure. It does not automatically resolve rule conflicts. In engineering implementation, it should be explicit that security constraints take priority over task convenience, capability instructions cannot expand existing permissions, and external documents cannot modify system execution rules.
Capability instructions should also record versions and applicability conditions. When a process changes, the system must be able to trace which version of the instructions a given task used; otherwise, problem reproduction and auditing become difficult.
4. Tool Governance: Isolate Model Intent from Real Execution
When a model proposes a tool call, it does not mean that the call can be executed directly. A reliable system should place a deterministic validation layer between the model and external resources.
1. Validate Inputs and Business Prerequisites
Tool requests should at least check input format, field ranges, resource identifiers, and necessary prerequisites. For example, before deleting a record, the system needs to confirm that the target exists, the current identity has permission, and relevant business rules are satisfied.
These checks should not rely only on the model “remembering to comply.” Constraints that can be explicitly verified by programs should be enforced by programs.
2. Distinguish Read and Write Operations
Reading information and changing external state carry different risks. Querying documents and reading reports are usually low-risk actions. Modifying configurations, sending notifications, and deleting data may have real impact.
The system can set execution requirements based on risk levels:
- Low-risk read operations can be executed directly when permissions allow.
- Reversible change operations should record the original state before controlled execution.
- High-impact or difficult-to-reverse operations require human confirmation or stricter approval.
Write operations should also include idempotency protection wherever possible. A tool request timeout does not necessarily mean execution failed. Direct retries may cause duplicate submissions, so execution status should be confirmed first.
3. Constrain How Tool Results Affect Decisions
External documents, retrieval results, and tool return content should be treated as data to be processed, not as new system instructions. Even if returned text asks the system to ignore existing rules, the main loop should not use it to expand permissions or change security boundaries.
For critical decisions, it is better to form a basis through explicit fields, trusted sources, and independent validation rather than relying only on a plausible explanation.
5. When to Introduce Sub-Agents
Sub-agents should not be avoided automatically. They need a clear engineering benefit.
1. Work Can Be Completed Independently
When a task contains well-bounded subproblems, independent execution is more likely to create value. For example, facts can be extracted separately from different document sets, or the same analysis can be performed on multiple independent data partitions.
However, if every step depends on the latest global judgment, splitting the work may require frequent synchronization, and coordination overhead can offset the benefit.
2. Results Can Be Accepted and Verified
Tasks suitable for delegation should have clear inputs, outputs, and completion conditions. Compared with “research this issue for me,” the following description is easier to execute and verify:
“Extract relevant facts from the specified materials, provide sources for each item, mark content that cannot be confirmed, and do not make final business judgments.”
After receiving the result, the main loop still needs to check coverage, evidence consistency, and conflicting conclusions rather than assuming that sub-agent output is correct by default.
3. Isolation Is Truly Necessary
Some tasks require different permission scopes, temporary contexts, or restricted execution environments. In such cases, independent execution units can help establish boundaries. However, real isolation must be implemented by the execution environment and permission system, not merely by assigning a role description to a sub-agent.
When introducing sub-agents, the system should also define budgets, timeouts, failure return methods, and cancellation mechanisms to prevent a branch from running indefinitely.
6. Choose Architecture Through Evaluation, Not Presupposition
When comparing main-loop and multi-agent approaches, task sets, tool permissions, and resource budgets should be kept as consistent as possible. If one approach receives more calls or broader permissions, differences in results cannot be attributed simply to architecture.
1. Quality Metrics Should Stay Close to Business Outcomes
Key metrics can include:
- Task completion rate and manual rework rate.
- Whether conclusions are supported by sufficient evidence.
- Whether user constraints are omitted.
- Whether tool operations are correct.
- Whether the system can recover after an exception.
- Whether unauthorized or unconfirmed changes occur.
Language fluency and rich steps do not mean the task is truly completed.
2. Cost Should Cover the Full Execution Path
In addition to model invocation cost, the system should record the number of tool requests, duplicate retrieval counts, total latency, human intervention counts, and troubleshooting cost.
Multi-agent parallelism may shorten waiting time for some tasks, but it may also increase total cost through result aggregation and repeated coordination. Both cases should be judged from execution records.
3. Test Sets Need Abnormal Scenarios
Testing only ideal inputs makes architectural differences hard to see. More valuable scenarios include: users changing constraints mid-task, incomplete tool data, conflicting external materials, execution timeouts, insufficient permissions, and operation results that cannot be confirmed immediately.
These scenarios can test whether the system stops risky operations, preserves uncertainty, and explains to the user what additional information is needed.
7. Start with a Minimal System and Evolve Gradually
In practice, teams can first build a minimal system with a complete closed loop:
Step 1: Define the task scope and completion conditions, and limit open-ended goals.
Step 2: Establish a unified task state that separates facts, assumptions, and execution records.
Step 3: Add input validation, permission checks, and risk levels to tools.
Step 4: Organize complex processes into capability instructions that can be loaded on demand.
Step 5: Record the decisions, tool calls, errors, and acceptance results of each task.
Step 6: Use failure samples to locate bottlenecks, then decide whether to add independent execution units.
If failures come from insufficient field validation, fix the validation. If they come from missing instructions, improve the capability documentation. Only when failures come from multiple independent work items waiting serially does it become necessary to further evaluate parallel delegation. Do not attribute every problem to “not having enough agents.”
8. Conclusion: Architectural Value Comes from Controllability and Verifiability
The core of agent engineering is not the number of roles. It is making goals, state, permissions, execution, and acceptance form a reliable closed loop.
A main loop helps maintain task constraints centrally. Progressive disclosure helps control context burden. Tool governance helps constrain real operations. Sub-agents are suitable for independent work with clear boundaries and verifiable benefits. These mechanisms are not mutually exclusive.
A more reliable strategy is to establish a baseline with a simple architecture first, then add complexity based on evidence. Architectural expansion has practical value only when new components clearly improve quality, latency, or isolation and their coordination cost remains manageable.
