AI Agent Collaboration and Testing Under Attention Constraints

    Reliable AI-assisted software delivery requires more than code generation. This article explains how explicit planning, layered instructions, context management, role-based collaboration, test-driven development, and deterministic safeguards can keep agents aligned with requirements. It also outlines how to preserve audit evidence and use development-process data to evaluate quality, rework, and total delivery cost.

    1. The Core Problem: Long Development Workflows Require Decision Management

    Software development is not a one-time text-generation task. It is a sequence of interdependent decisions: interpreting requirements, dividing modules, handling exceptions, designing interfaces, validating results, and preserving existing behavior. Coding agents can generate local implementations quickly, but that does not mean they can reliably complete an entire delivery workflow without constraints.

    A simplified model illustrates the problem. Suppose a task requires 20 decisions to be correct, and each decision is independent with an 80% probability of being correct. The probability that all decisions are correct is:

    P = 0.8²⁰ ≈ 1.15%

    Independence and a fixed success probability are simplifying assumptions, not statistical findings about real software development. Actual decisions are often dependent: an early misunderstanding can propagate into later implementation, while tests, reviews, and feedback can correct mistakes. The model is useful not for predicting delivery success, but for showing that strong local performance does not automatically produce reliable end-to-end results.

    Planning cannot make every decision perfectly correct. What it can do is turn hidden assumptions into explicit constraints, replace unchecked improvisation with reviewable proposals, and expose ambiguity before implementation.

    Here, attention constraints refer to engineering practices for managing agent inputs and execution workflows—not changes to a model’s internal attention mechanism. The goal is to emphasize information relevant to the current task while reducing interference from irrelevant history, outdated conclusions, and conflicting instructions.

    2. Turn Ambiguous Requirements into a Verifiable Plan

    Define Delivery Boundaries Before Implementation Details

    Task planning should answer four questions:

    • What is the goal? What observable behavior should the user receive?
    • Where are the boundaries? Which modules may change, and which behaviors must remain compatible?
    • How will completion be demonstrated? Which tests, checks, or human acceptance steps are required?
    • When should execution pause? What should happen if requirements conflict, permissions are insufficient, or a critical interface is unclear?

    For example, adding a task completion-rate metric to development-process data requires more than an instruction to “implement the statistics.” The plan must clarify:

    • Which task states exist.
    • Whether canceled tasks belong in the denominator.
    • How duplicate events are handled.
    • Whether the metric uses current state or state at a specific point in time.
    • What to return when no tasks exist.

    These are business semantics, not merely coding details. Without agreement, an agent may produce structurally sound, syntactically valid code that calculates the wrong metric.

    Use a Reviewable Plan Structure

    A practical plan can contain six sections:

    1. Requirement interpretation and open questions.
    2. Relevant implementation locations and dependencies.
    3. Inputs, outputs, and business invariants.
    4. Test design and acceptance criteria.
    5. Modification steps and affected scope.
    6. Risks, rollback options, and prohibited actions.

    Where possible, each step should produce something observable, such as a test case, module change, interface description, or verification record.

    A low-risk change may need only a short plan. Changes involving data migration, permissions, or shared interfaces require deeper review.

    The objective is not a longer document. It is a plan that makes key decisions explicit, gives the implementer actionable guidance, and gives the reviewer a basis for judgment.

    3. Refine Plans Through an Annotation Loop

    An initial plan rarely covers every condition. A more reliable approach is an annotation loop:

    Propose a plan → flag specific issues → revise the plan → approve execution

    Review comments should identify concrete changes. For example:

    • “Filter tasks by creation time, not last update time.”
    • “Deduplicate events using the business event identifier.”
    • “Do not change existing task-state definitions in this task.”
    • “Return zero when there are no valid tasks, and retain the valid sample count.”

    These comments can directly shape implementation and testing. “Think this through more carefully” cannot.

    Each comment should have an explicit status: accepted, awaiting clarification, or rejected with a reason. Agreed decisions should be incorporated into the formal plan so that execution does not depend on scattered discussion.

    Plan annotations and code comments serve different purposes. Annotations can preserve the review process. Code comments should primarily explain business constraints, design rationale, and non-obvious behavior—not mechanically restate the code. Unnecessary process commentary adds reading overhead and makes important information harder to find.

    4. Layer Instructions and Reveal Information When Needed

    Separate Persistent Rules from Task-Specific Rules

    Persistent rules include coding conventions, directory responsibilities, testing requirements, security boundaries, and delivery standards. Task-specific rules include the current requirement, permitted modification scope, acceptance criteria, and temporary restrictions.

    Mixing these categories causes rule files to grow continuously and can turn one-time requirements into unintended permanent conventions.

    A layered structure can help:

    • Project level: Architectural boundaries, general conventions, and security requirements.
    • Module level: Domain terminology, local interface constraints, and module testing requirements.
    • Task level: The current plan, unresolved questions, and permitted changes.
    • Stage level: The step currently being executed and the evidence it requires.

    This is a general organizational approach. In practice, confirm whether the execution environment supports loading rules by directory or task. If it does not, the task orchestration process must explicitly supply the relevant material.

    Progressive Disclosure Is More Than Shorter Input

    Progressive disclosure means providing the minimum sufficient information for the current decision, then adding detail as needed.

    Planning requires requirements, architectural boundaries, and risk information. Implementation requires relevant modules, interface definitions, and tests. Verification requires a change list, execution results, and acceptance criteria.

    There is no need to include the entire historical log at every step. However, reducing input must not hide cross-module consequences.

    Information selection should consider both relevance and importance. Permission rules or compatibility constraints may be far from the current file yet still be essential, high-priority context.

    5. Manage Working Context Without Losing Audit Evidence

    Distinguish Three Types of Information

    Information generated during agent execution can be divided into:

    • Facts: Verifiable information from code, confirmed requirements, and actual test results.
    • Decisions: Agreed approaches, restrictions, and their rationale.
    • Temporary information: Exploratory assumptions, repeated logs, and obsolete attempts.

    Context cleanup should preserve facts and valid decisions while compressing temporary information. It should not mean deleting project documentation or audit records.

    Maintain a Task-State Summary

    At the end of each stage in a long task, create a concise summary containing:

    • Confirmed requirements and business invariants.
    • Completed steps and corresponding changes.
    • Verification performed and its results.
    • Unresolved issues.
    • Next actions and prohibited actions.

    The summary must distinguish planned, executed, and verified work. For example, “preparing to run regression tests” must not become “regression tests passed” during summarization.

    Keep original logs, plan versions, and test records in traceable locations. Working context can be cleaned up; the evidence trail must remain intact. This reduces information interference while supporting task recovery and later review.

    6. Multi-Agent Collaboration: Divide Responsibility, Preserve Semantics

    Parallel agents do not automatically improve efficiency. If they modify the same interface or use different business definitions, integration costs may exceed the benefits of parallel execution.

    A more reliable division of work defines both responsibility and write boundaries:

    • Planning role: Clarifies requirements and organizes the proposed approach.
    • Implementation role: Changes code within specified modules.
    • Testing role: Adds boundary cases and verifies behavior.
    • Review role: Checks modification scope, evidence, and compliance with constraints.

    The number of roles should depend on task risk and complexity. A simple change does not need a full collaboration workflow.

    Use Contracts to Coordinate Parallel Tasks

    A task contract should include inputs, outputs, dependencies, business invariants, error handling, testing requirements, and completion conditions.

    For example, if one role handles data aggregation and another handles API output, they must agree on the data structure, empty-result semantics, and error categories before working independently. Otherwise, both sets of local tests may pass while integration fails.

    Control Writes to Shared Areas

    Shared interfaces, common configuration, and core data structures should have one designated owner. Other roles can propose changes, but the owner integrates them.

    Parallel tasks should operate on non-overlapping modules where possible, with contract consistency checked during integration.

    Handoffs should include a change list, test results, unresolved issues, and risks—not just a statement that the work is “done.”

    7. Test-Driven Development: Make Requirements Executable

    Test-driven development typically follows the red–green–refactor cycle:

    1. Write a test and observe an expected failure.
    2. Implement the minimum behavior needed to pass it.
    3. Improve the structure while preserving behavior through tests.

    For agent-assisted development, tests do more than detect defects. They turn requirements into continuous feedback during execution.

    Derive Tests from the Contract, Not the Implementation

    If tests merely repeat implementation logic, the code and tests can share the same mistake. Tests should come from confirmed requirements, business invariants, and independently derived expected results.

    For a task completion-rate metric, coverage should include:

    • No valid tasks.
    • All tasks completed or all tasks incomplete.
    • Treatment of canceled tasks in the denominator.
    • Duplicate event inputs.
    • Time boundaries.
    • Unknown states and invalid data.

    The following pseudocode is illustrative. The actual calculation rules still require business confirmation:

    1. Test: Canceled tasks are excluded from valid tasks
    2. Input:
    3. 3 completed tasks
    4. 1 incomplete task
    5. 2 canceled tasks
    6. Expected:
    7. Valid task count = 4
    8. Completed task count = 3
    9. Completion rate = 0.75

    Confirm That Tests Fail for the Expected Reason

    During the red phase, confirm that failure comes from the missing target behavior—not a broken test environment, missing dependency, or incorrect assertion. Otherwise, subsequent fixes may drift away from the requirement.

    During the green phase, avoid hard-coding sample-specific behavior merely to pass a small test set. During refactoring, rerun relevant tests to confirm that structural changes have not altered external behavior.

    Verification usually needs several layers:

    • Unit tests check local rules.
    • Integration tests check collaboration between modules.
    • Necessary end-to-end tests check critical user workflows.

    Passing tests do not establish complete correctness. Coverage gaps, performance, security, and compatibility still require consideration.

    8. Deterministic Safeguards: Do Not Rely on Agent Compliance Alone

    Natural language is useful for expressing intent, but critical rules should not depend solely on an agent following instructions. Deterministic checks before and after execution can block out-of-scope actions or detect problems before delivery.

    Common checks include:

    • Whether modified paths are within the authorized scope.
    • Whether changes contain credentials or sensitive data.
    • Whether high-risk operations have approval.
    • Whether required tests actually ran and passed.
    • Whether changes satisfy explicit formatting or static rules.

    An illustrative workflow is:

    1. Before execution:
    2. Check target paths
    3. Assess operation risk
    4. Verify required authorization
    5. Block execution if conditions are not met
    6. After execution:
    7. Save operation results
    8. Run relevant checks
    9. Stop progression to delivery if checks fail

    The effectiveness of these checks depends on the execution environment. They are not a complete security boundary and should be combined with least privilege, isolated execution, and auditing.

    Rules that may produce false positives need a reviewable exception process. Agents should not be allowed to bypass them independently.

    9. Use Development-Process Data to Evaluate Benefits and Costs

    Record Data That Explains Outcomes

    Development-process records should cover task identifiers, plan versions, requirement changes, modification scope, test results, review comments, blocked operations, and final acceptance status.

    Collection should also limit sensitive information and define access permissions and retention periods.

    These records can help answer:

    • Does rework mainly come from unclear requirements or implementation errors?
    • Are failures concentrated in particular modules or collaboration handoffs?
    • Which checks successfully prevented out-of-scope modifications?

    Look Beyond Per-Call Cost

    Useful metrics include:

    • First-pass acceptance rate.
    • Rework caused by requirement misunderstandings.
    • Time spent fixing defects.
    • Human review effort.
    • Resource consumption for valid tasks.
    • Out-of-scope changes and rule-blocking events.

    When comparing workflows, control for differences in task complexity, acceptance criteria, and team experience as far as possible. Easier tasks should not be mistaken for a more effective process.

    Model selection should also reflect task risk. Formatting checks and log filtering may be better handled by deterministic programs or lighter-weight processing. Complex planning, cross-module reasoning, and high-risk review require stronger reasoning capabilities.

    Evaluate the total cost of producing an acceptable deliverable—including retries, rework, verification, and human review—not just the cost of one generation.

    10. Common Failure Modes and a Practical Adoption Sequence

    When an agent repeatedly deviates from requirements, first inspect acceptance criteria, business definitions, and conflicting context instructions rather than adding more explanation.

    When context keeps growing but results become less stable, separate confirmed facts from obsolete assumptions and create a stage summary while retaining original evidence.

    When tests pass but functionality is still wrong, check whether tests are independent of the implementation, cover business boundaries, and account for module interactions.

    When agents overwrite one another’s changes, redefine write ownership, designate owners for shared interfaces, and establish integration checkpoints.

    Teams can start with one low-risk task:

    1. Create a concise plan and acceptance criteria.
    2. Add task-state summaries, a testing cycle, and necessary safeguards.
    3. Use process data to decide whether to expand parallel collaboration.

    Avoid introducing too many rules and roles at once. The workflow itself can become a burden.

    Reliable agent collaboration places open-ended generation inside a reviewable engineering loop. Planning reduces ambiguity, layered context emphasizes critical constraints, tests provide behavioral feedback, deterministic checks enforce execution boundaries, and process data supports continuous improvement.

    The goal is not to make agents perform more actions. It is to ensure that every delivery has a clear basis, verified results, and traceable responsibility.