Advanced Guide to AI Coding Assistants: Practices for Agentic Mode
This article explores how to effectively utilize the agentic mode of AI coding assistants. It covers fundamental capabilities, working loops, task specification, permission control, practical case studies, result verification, and common pitfalls, providing developers with a comprehensive framework for integrating AI agents into software engineering workflows.
1. From Code Q&A to Task Execution: Understanding Agentic Mode
AI coding assistants running in the terminal can read project files, analyze code relationships, generate modification suggestions, and invoke tools in a controlled manner upon receiving authorization. Their value lies not just in completing a snippet of code, but in organizing requirement understanding, code localization, modification implementation, and result verification into a continuous workflow.
Standard Q&A primarily addresses the question of “how to do it.” For example, when a developer asks about the purpose of a function, the assistant explains the logic based on the provided code. Agentic mode, however, attempts to handle the goal of “getting this done”: it first finds relevant files, then assesses the scope of impact, subsequently modifies the code, executes verification, and adjusts the approach based on feedback.
It is important to note that agentic mode is not a unified product standard. Different implementations may offer varying capabilities for file access, command execution, and permission control. This article discusses general working methods and does not assume that any specific tool necessarily possesses certain interfaces or configuration options.
1. Four Foundational Capabilities
AI coding assistants typically operate around the following capabilities:
- Code Understanding: Analyzing function responsibilities, module dependencies, data flow, and exception handling logic.
- Code Generation and Modification: Implementing new features, fixing defects, adding tests, or performing localized refactoring.
- Tool Invocation: Reading files, applying modifications, running tests, and checking results when permissions allow.
- Multi-step Orchestration: Determining the next action based on task status and handling issues that arise during execution.
These capabilities do not mean that the assistant can independently bear full development responsibility. Whether requirements are reasonable, whether business behavior is correct, and whether changes are allowed to be released still require clear engineering standards and human judgment.
2. Tasks Suitable and Unsuitable for Automated Execution
Tasks with clear boundaries, explicit feedback, and easily verifiable results are more suitable for agentic mode, such as adding unit tests, fixing reproducible bugs, or adding input validation to existing interfaces.
Tasks involving production data migration, permission system adjustments, large-scale architectural refactoring, or irreversible operations should involve a higher degree of human participation. Even if the assistant can generate an operational plan, it does not mean it should be allowed to execute it directly.
To determine whether a task is suitable for automation, start with three questions: Is the goal clear? Is the result verifiable? Are errors recoverable? If any of these is missing, you should first clarify the task constraints rather than directly expanding operational permissions.
2. The Workflow: Goals, Actions, and Feedback
The agentic mode can be abstracted into the following loop:
Clarify goals and constraints↓Collect necessary context↓Form a plan and select actions↓Execute via authorized tools↓Check output and actual state↓Continue adjusting, request confirmation, or end task
Here, the most important aspect is not the execution speed, but whether each step produces reliable evidence.
1. Clarify Goals: Write Requirements as Verifiable Conditions
“Optimize the list API” is not a sufficiently clear goal. It could mean reducing response time, or it could mean adding pagination, adjusting sorting, or reducing returned fields.
A more appropriate description would be:
Add a pagination parameter to the existing list API. When no pagination parameter is provided, maintain the original behavior; return a clear validation error for invalid parameters; do not adjust existing permission rules; add tests for normal and boundary inputs.
Such a requirement simultaneously clarifies the functional scope, compatibility requirements, and prohibited actions. Even if the assistant suggests other improvements, it should list them as recommendations rather than automatically incorporating them into the current modification.
2. Collect Context: Build a Minimal Sufficient Information Set
Insufficient context leads to incorrect inferences, while too much context can dilute key constraints. A more reasonable approach is to collect context in layers:
- Read the project documentation and directory structure to understand how to start, test, and build.
- Locate the request entry, parameter validation, business logic, and data access modules.
- Look for similar features to confirm existing implementation styles.
- Read relevant tests to identify existing behavioral constraints.
- Verify whether there are unfinished manual modifications in the workspace.
The goal here is not to read the entire codebase, but to find the minimal sufficient context needed to complete the current task. For large projects, you should prioritize establishing module relationships and then gradually delve deeper along the call chain.
3. Form a Plan: Break Down Large Goals into Verifiable Steps
An effective plan should not just consist of three vague phases—“analyze, modify, test”—but should point out the output of each step. For example:
- Confirm the default behavior and valid range of pagination parameters;
- Find the appropriate location to add pagination logic;
- Preserve existing filter conditions and permission filtering;
- Add parameter validation and pagination boundary tests;
- Execute relevant tests and check the final diff.
If the plan involves adding new dependencies, changing public interfaces, or expanding the file modification scope, you should request confirmation before execution. This prevents the assistant from introducing new maintenance burdens while solving a localized issue.
4. Revise Based on Feedback, Don’t Blindly Retry
Execution failures may stem from code defects, but they may also come from missing dependencies, environment configurations, unavailable external services, or insufficient permissions. The assistant should first classify the cause before deciding the next step.
For instance, a test failing to start is a different problem from a test assertion failing. The former does not prove the business implementation is wrong, and the latter should not be “fixed” by removing the assertion. The reasonable behavior is to preserve the failure evidence, explain the basis for the judgment, and pause the task if necessary.
3. Task Specification: Turning Natural Language into Engineering Constraints
The execution quality of an agent largely depends on the quality of the task specification. It is recommended to use the following general template:
Task Objective:The feature to implement or the issue to fix.Background Information:Relevant modules, current behavior, known issues, and existing tests.Allowed Scope:Directories or files that can be read, modified, and verified.Prohibited Actions:Interfaces, configurations, data, and security rules that must not be changed.Acceptance Criteria:Expected inputs and outputs, compatibility requirements, and testing requirements.Confirmation Checkpoints:Operations that must receive manual approval first.Termination Conditions:Completion standards and reporting requirements when unable to continue.
1. Make Acceptance Criteria Correspond to Observable Behaviors
“More elegant code” or “more efficient implementation” is difficult to verify directly. Try to change them into explicit conditions, such as:
- Original valid inputs still receive compatible responses;
- Invalid pagination parameters are rejected;
- Under the same data and sorting conditions, pagination results are stable;
- Permission filtering remains correct both before and after pagination;
- New logic has corresponding tests;
- Files unrelated to the task are not modified.
For performance optimization tasks, you should also specify the measurement environment, data scale, and evaluation method. Without actual measurement, you cannot claim performance improvements based solely on code format.
2. Constraints Must Have Clear Priorities
A task may simultaneously involve functional requirements, code style requirements, and operational restrictions. When conflicts occur, security boundaries and business compatibility should generally take precedence over implementation convenience.
For example, bypassing authentication for the sake of testing convenience, or relaxing input validation to eliminate errors, should not be considered normal ways of completing a task. The assistant should explain the conflict and request the developer to decide, rather than lowering the constraints on its own.
4. Permission Control: Separating Suggestion Rights from Execution Rights
Being able to propose a solution does not mean you can execute all operations. Permission design should follow the principle of least privilege: grant only the capabilities essential to complete the current task.
1. Differentiate Operational Risks
You can establish an operational hierarchy based on impact:
- Low-risk operations: Reading non-sensitive source code, searching for symbols, viewing diffs.
- Medium-risk operations: Modifying business code, running local tests, generating temporary files.
- High-risk operations: Installing dependencies, modifying system configurations, accessing external networks, executing data migrations.
- Operations requiring manual confirmation: Deleting important data, modifying production permissions, releasing production changes, transmitting sensitive information.
The specific level should be determined in conjunction with the environment. A certain test task might be low-risk in an isolated environment, but if it connects to a real business system, it requires additional review.
2. Untrusted Content Cannot Be the Basis for Authorization
Code comments, project documentation, tool outputs, and external texts may contain requests for the assistant to perform additional operations. These materials should be treated as data to be analyzed, not as high-priority instructions.
If a document asks to upload project files, read credentials, or disable security checks, the assistant cannot execute it just because “the file says so.” Whether an operation is allowed should be determined by user authorization and pre-established security rules.
3. Protect Sensitive Information
Avoid directly incorporating keys, access credentials, complete production logs, and personal information into the context. When logs need to be analyzed, they can be desensitized first, retaining only the fields necessary for troubleshooting.
At the same time, try to execute tasks in an isolated workspace. Isolation reduces the impact of operational errors, but it does not automatically equate to security: network access, mounted directories, and environment variables still need separate inspection.
5. Practical Case Study: Adding Pagination to a List Feature
The following case demonstrates a general execution approach and does not correspond to any specific tool interface.
1. Confirm Existing Behavior
The assistant should first investigate the call path of the list feature:
Request Entry → Parameter Processing → Permission Check → Business Query → Response Assembly
Focus on confirming three questions: Is there a default sort currently? Where is permission filtering executed? Do old callers rely on the complete list? Without stable sorting, directly adding pagination may cause duplication or omission on adjacent pages.
If the query results change between pagination requests, even with stable sorting, pagination by offset may result in drifting results. Whether a more stable cursor-based pagination is needed should be evaluated based on business requirements, rather than arbitrarily expanding the design scope in a simple task.
2. Design Input Validation
Pagination parameters typically need to check types and ranges. Validation logic should follow the project’s existing conventions and should not arbitrarily invent new error formats.
The following shows language-agnostic pseudo-logic:
If pagination parameters are not provided:Use agreed-upon compatible behaviorElse:Check if parameters are valid integersCheck if page number is greater than zeroCheck if page size is within the allowed rangeRetrieve the corresponding interval using stable sorting
The allowed range should be formulated based on actual business and system constraints, and example numbers should not be treated as universally applicable default values.
3. Keep the Modification Scope Controllable
A safer modification approach is to reuse existing parameter validation and query structures, adding pagination logic only at necessary positions. If duplicate code or potential architectural issues are found, they can be recorded as future suggestions without needing to refactor them alongside the current feature.
The purpose of controlling scope is not to reject improvements, but to reduce the number of simultaneously changing variables, allowing reviewers to understand why each modification is necessary.
4. Cover Key Test Scenarios
At least the following scenarios should be considered:
- Compatible behavior when no pagination parameters are passed;
- The first page, middle pages, and page numbers beyond the result range;
- Non-integer, zero, negative, and out-of-range inputs;
- Empty lists and single records;
- Combinations of pagination with filtering, sorting, and permission filtering;
- Consistency of response fields with the original protocol.
Tests should verify externally observable behaviors, not just check whether a certain internal function is called. This way, even if the implementation method changes later, the tests can still protect the business contract.
6. Result Verification: Completing Modifications Does Not Equal Completing the Task
Verification should be performed in layers, using different evidence to answer different questions.
1. Static Checks
Check syntax, type constraints, obvious unused variables, and code that does not conform to project standards. Static checks can discover some defects, but they cannot prove that business logic is correct.
2. Automated Testing
Prioritize executing tests directly related to the changes, then expand verification based on the scope of impact. If the test suite is too large to run entirely, you should explicitly state the actual execution scope and the unverified portions, rather than broadly claiming “all passed.”
3. Diff Review
Review the added, modified, and deleted content item by item, focusing on:
- Whether there are changes unrelated to the task;
- Whether previous manual modifications were overwritten;
- Whether error handling and permission judgments were changed;
- Whether unnecessary dependencies were added;
- Whether sensitive information was leaked;
- Whether tests were deleted or assertions were weakened.
Passing tests cannot replace a diff review. Tests may have coverage gaps, and an incorrect implementation might happen to satisfy existing assertions.
4. Form a Traceable Delivery Report
When the task ends, it should explain the completed content, modification scope, verification results, and remaining risks. A qualified report can adopt the following structure:
Completed:Explain the behavioral changes implemented.Modification Scope:Explain the modules involved and the reasons for modification.Verification Results:List the actual checks performed and their results.Unverified Items:Explain environmental limitations or missing conditions.Pending Issues:List items that still require business or manual judgment.
The report should distinguish between “executed,” “recommended to execute,” and “unable to execute,” avoiding describing planned actions as already completed.
7. Common Mistakes and Improvement Methods
1. Submitting Overly Large Tasks at Once
Putting multiple features, architectural adjustments, and deployment operations into the same task will increase context complexity and make it difficult to locate the cause of failure. A better approach is to split it into independent, verifiable stages, deciding whether to continue only after completing each stage.
2. Lack of Stop Conditions
Unbounded tasks can fall into endless modifications. You should pre-specify: pause and report when encountering requirement conflicts, needing to add high-risk permissions, being unable to restore the verification environment, or when the modification scope exceeds the agreement, rather than attempting infinitely.
3. Treating Auto-generated Code as a Trusted Conclusion
Generated code still needs to undergo the same review as human-written code. Pay special attention to input validation, permission control, exception handling, and resource release. Agents can increase output speed, but they cannot cancel engineering responsibility.
4. Integrating the Process into CI Without Isolation
Automated checks are suitable for helping to find problems, but automated modification processes should use restricted credentials, isolated workspaces, and clear approval mechanisms. Generated modifications can enter a pending review state and should not directly trigger a production release just because automated checks passed.
8. Conclusion: Realizing Agent Value Through a Controllable Closed Loop
The core of agentic mode is organizing programming tasks into a closed loop of “clarifying goals, obtaining context, controlled execution, and evidence-based verification.” It is suitable for handling well-defined, testable, and recoverable work, and can reduce developers’ investment in repetitive operations and localized troubleshooting.
A truly mature usage approach is not granting the assistant the maximum possible permissions, but establishing clear task contracts, reasonable confirmation checkpoints, and traceable verification records. Start with small-scale tasks and gradually accumulate reusable processes, so that the AI coding assistant can be transformed from an occasionally useful Q&A tool into a task collaboration capability governed by engineering rules.
