A Practical Guide to AI-Assisted Programming: From Environment Setup to Agent Collaboration
This guide covers AI-assisted programming from setup to safe use. It explains how to install an editor and an AI coding plugin, check your account and quota, choose among three interaction modes, write clear requests, pick models and runtime environments, connect external tools with least privilege, and review AI-generated changes using a sliding-window rate limiter as an example.
1. Why Learn AI-Assisted Programming Systematically
AI coding tools change quickly, and new products appear constantly. Instead of chasing every new name, it is more useful to learn the working methods behind them: how to describe requirements, how to help the model understand project context, how to review generated changes, and how to control execution permissions. Once you master these methods, you can adapt to a different tool much faster.
This article follows a general workflow. It covers environment setup, basic interaction, advanced capabilities, a hands-on example, change review, and security practices.
2. Setting Up the Development Environment
2.1 Prepare a Code Editor
Choose a mainstream code editor that supports extensions, and download the installer for your operating system from the official website. The default options are usually fine during installation.
2.2 Install an AI Coding Plugin
Search the editor’s extension marketplace for “AI coding assistant” plugins, and prefer versions from official or trusted publishers. Before installing, check the publisher information, update history, and permission descriptions. Avoid extensions from unknown sources.
2.3 Sign In and Check Your Quota
Most AI coding plugins require an account. After you sign in, the editor’s status bar usually shows your current plan and remaining quota. Free plans typically limit the number of chat conversations and how often code completions run. Paid plans differ in available models, concurrency, and context length. Quota details are set by the service provider, so check the current announcements before use.
Some services are available in certain network environments but not others. Some may also have requirements for data storage and cross-border data transfer. Before you use a tool for work projects, confirm the access conditions and compliance requirements.
3. Basic Interaction: Conversational Programming
3.1 Open the Chat Panel
Editors usually provide a chat or conversation entry point. In the panel, developers can make requests in natural language, such as asking for an analysis of a module’s responsibilities, an explanation of an error message, or unit tests for a function.
3.2 Understand the Three Working Modes
Most tools offer three interaction modes. They differ in how much the model can do and how often the developer must intervene.
- Q&A mode: The model only answers questions and does not modify files. It suits quickly understanding unfamiliar code or looking up API usage.
- Edit mode: The model proposes changes to selected code or specified files, and the developer applies them after confirming. It suits local refactoring and code completion.
- Autonomous mode: The model can read the project structure, modify multiple files, run commands, and iterate based on execution results. It is the most efficient mode and needs the most careful review.
Start with Q&A mode to learn the model’s answer style. Then move to edit mode, and finally try autonomous mode.
3.3 Write a Good Request
The quality of a request directly determines the quality of the output. A clear request usually includes four elements:
[Goal] Implement an API rate-limiting module that limits the request frequency of each user.[Context] The project uses a layered architecture. The rate-limiting logic lives in the middleware layer, and the configuration is read from environment variables.[Constraints] Do not add new third-party dependencies. Do not modify existing route definitions.[Acceptance] Provide unit tests covering three cases: window boundaries, rejection when the limit is exceeded, and window recovery.
The goal states what to build. The context describes the environment and existing structure. The constraints state what must not be done. The acceptance criteria define what counts as done. When all four are present, the model has to guess less, and fewer rounds of rework are needed.
4. Advanced Capabilities
4.1 Choose a Model for Each Task
Large language models differ in code generation quality, long-context understanding, response speed, and cost. Do not choose based on impressions alone. Instead, compare them: give the same request to two models, then evaluate the results on correctness, code readability, and scope of changes. For complex cross-file tasks, prefer a model with stronger long-context capability. For simple completions or formatting changes, a faster and cheaper model is sufficient.
4.2 Choose a Runtime Environment
AI coding tools generally run in one of three ways. Each suits different scenarios.
- Local execution: Code and some data stay on your machine. Latency is low, which suits projects with sensitive information. Large tasks may run slowly because local compute is limited.
- Cloud execution: Cloud services offer larger compute resources, which suits long-running tasks. Before use, evaluate the scope of code and data sent to the service, and confirm that it complies with your organization’s data management policies.
- Background command-line execution: This mode suits batch processing, scripted workflows, and integration into continuous integration environments. Pay close attention to permission scope so that automated tasks do not run high-risk operations without supervision.
4.3 Extend Tools and Context
Many tools connect to external capabilities through open protocols. Examples include querying project documentation, reading issue tracker records, and accessing database schemas in read-only mode. With these tools, the model gets fuller context and has to guess less.
When you connect tools, follow the principle of least privilege. Check the read and write scope of each tool, and enable only the capabilities the current task requires. Tools that write or delete data should be disabled by default or require manual confirmation each time.
4.4 Split Tasks and Keep the Process Visible
Complex tasks can be split across multiple sub-agents that run in parallel. For example, one sub-task reviews existing interfaces, one writes the implementation, and one adds test cases. After splitting, each sub-task has a narrower goal, and its results are easier to verify.
Whether or not you split tasks, process visibility matters. Every file read, code change, and command execution should be traceable. Developers can judge whether the model’s decisions are reasonable only when they can see the full process.
5. Hands-On Example: Implementing a Sliding-Window Rate Limiter with AI
The following small feature shows the complete workflow.
5.1 Step 1: Make the Request
Organize the request using the four elements from Section 3.3, then give it to the model. The more specific the request, the easier the review.
5.2 Step 2: Review the Generated Implementation
The model’s reference implementation, shown as pseudocode, is:
class SlidingWindowLimiter:init(limit, window):store limit and windowhits = empty queueallow(now):cutoff = now - windowwhile hits is not empty and the timestamp at the front of hits <= cutoff:remove the front element of hitsif the number of elements in hits < limit:enqueue now into hitsreturn truereturn false
Review the following points:
- Time source: Use a monotonic clock instead of system wall-clock time, so that clock adjustments do not cause counting errors.
- Boundary condition:
<=means that a request exactly one window length old is removed from the count. Make sure this matches the definition in your requirements. - Parameter validation:
limitandwindowmust be positive numbers. Otherwise, the initializer should raise an error. - Memory growth: The queue stores only timestamps inside the window, so it does not grow without bound during long runs. In high-concurrency scenarios, however, evaluate the maximum queue length for each user.
5.3 Step 3: Verify Behavior with Tests
For the rate limiter above, you can design the following test scenario, which allows at most 2 requests per second:
| Request time (s) | Records in window | Expected result | Notes |
|---|---|---|---|
| 0.0 | None | Allowed | First request |
| 0.1 | 0.0 | Allowed | Second request, reaches the limit |
| 0.2 | 0.0, 0.1 | Rejected | Exceeds the limit |
| 1.1 | 0.1 | Allowed | 0.0 has left the window, so the count recovers |
Tests must assert real behavior rather than merely pass. If a generated test only checks whether the function can be called, add boundary cases.
6. Checklist for Reviewing AI-Generated Changes
Before you accept any AI-generated change, check each item:
- Does the change stay within the scope of the request? Did it modify unrelated files or configuration?
- Does it introduce new dependencies? Are their licenses, maintenance status, and security records acceptable?
- Are boundary conditions and abnormal inputs handled, such as null values, negative numbers, and very large values?
- Do corresponding tests exist, and do they cover the key branches?
- Does the change contain hardcoded keys, addresses, accounts, or personal information?
