AI Coding Agents in Practice: A Guide to Building Small Web Projects
Learn how AI coding agents move beyond code completion to handle project-level tasks such as planning, file editing, command execution, and iterative debugging. This guide explains their operating model, demonstrates a complete workflow for building a small browser game, and outlines practical prompting, validation, cost-management, security, and team-adoption principles.
1. Background: From Code Completion to Task-Oriented Agents
Early coding assistants focused primarily on code completion. They predicted the next block of code based on the text near the cursor. In recent years, large language model-powered coding agents have begun handling broader development tasks. They can read project files, create execution plans, run terminal commands, modify multiple files, and correct their own work based on runtime results.
A typical coding agent consists of three layers:
- Model layer: Understands requirements, reasons about possible solutions, and makes decisions.
- Tool layer: Provides capabilities such as reading and writing files, searching code, running commands, and accessing browser previews.
- Orchestration layer: Manages context, controls the tool-calling loop, tracks task status, and triggers retries when errors occur.
Understanding these layers helps developers determine what an agent can and cannot do. Model capabilities affect reasoning quality, tool permissions determine which resources the agent can access, and orchestration design determines whether it can stay on track during long-running tasks.
2. How Coding Agents Work
2.1 Perception: Reading Project Context
Before starting work, an agent typically scans the project directory to identify the programming language, framework, dependency declarations, and directory structure. Because the model has a limited context window, tools usually load only relevant files rather than the entire repository.
Developers can reduce misinterpretation in several ways:
- Add a concise
READMEfile at the project root explaining the project purpose and how to run it. - Keep the directory structure clear and avoid large amounts of unrelated generated files.
- Identify important file paths explicitly in the task description.
2.2 Planning: Breaking Requirements into Verifiable Steps
After receiving a request, an agent usually generates a task list. A good plan should meet three conditions:
- Each step has a clear deliverable, such as a specific file or runnable feature.
- Dependencies are ordered logically—for example, building the basic structure before adding application logic.
- Each step can be checked by running a command or opening the page to confirm the result.
If the plan is too vague—for example, simply saying “finish the game”—the model may skip important details. Developers should review the plan before execution and correct any deviations early.
2.3 Execution and the Feedback Loop
The core of an agent is an iterative loop. Its logic can be represented by the following pseudocode:
while task is not complete:observation = result of reading files or running commandsaction = model chooses the next step based on the goal, observation, and historyresult = execute(action)record(action, result)if result contains an error:enter the repair branch
The quality of this loop depends on the reliability of its feedback signals. Compilation errors, failed tests, and console output are useful signals. If a project produces little observable output, the agent must rely more heavily on its own assumptions, which significantly increases the likelihood of errors.
2.4 Verification: Trust Runtime Results
Code generated by an agent should not be considered ready automatically. Verification should include at least the following:
- Run the project’s startup command and confirm that it exits or loads without errors.
- Check whether the core behavior matches the requirements.
- Inspect the browser console for uncaught exceptions.
- Write simple tests for important logic.
3. A Complete Example: Building a Small Web Game
Small browser games are useful cases for evaluating coding agents. Their structure is relatively simple, but they include common development requirements such as state management, input handling, collision detection, and rendering loops. This makes them sufficient for testing an agent’s basic capabilities.
3.1 Practical Workflow
- Choose a working directory: Use an empty directory or an existing project as the workspace. Avoid pointing the tool at a folder containing personal data or credentials.
- Confirm the trust boundary: When granting the tool access to a directory for the first time, verify that its source is trustworthy and understand which files it can read or modify.
- Write a clear specification: Define the objective, technical constraints, and acceptance criteria.
- Review the execution plan: Check whether the steps are complete and whether input handling or edge cases have been overlooked.
- Monitor execution: Review which files the tool changes and whether it introduces unnecessary dependencies.
- Run local validation: Open the page in a browser and check each requirement.
- Perform manual acceptance testing and code review: Confirm that the logic is correct before deciding whether to keep the changes.
3.2 How to Write the Specification
The more specific the requirements, the more controllable the generated result. The following template can be reused:
Goal: Build a two-player tank battle game that runs in a web browser.Technical constraints:- Deliver the game as a single HTML file with embedded CSS and vanilla JavaScript;- Use Canvas for rendering and do not add external dependencies.Functional requirements:1. Player One moves with the arrow keys and fires bullets with the Space key;2. Walls can be destroyed by bullets, and tanks cannot pass through each other;3. Display the winner when a round ends and provide a restart button.Acceptance criteria:- The game runs when the file is opened directly in a browser;- The browser console contains no errors;- All functional requirements can be verified manually.
The three sections serve different purposes. Technical constraints limit the implementation scope, functional requirements define expected behavior, and acceptance criteria provide a concrete basis for deciding whether the task is complete.
3.3 Example of a Game Loop
Browser games commonly use a main loop that updates state and renders the scene on every frame. The following code illustrates this structure and can serve as a reference when reviewing generated code:
let lastTime = 0;function gameLoop(timestamp) {const delta = timestamp - lastTime;lastTime = timestamp;update(delta); // Update tank positions, bullet trajectories, and collision staterender(ctx); // Clear the canvas and redraw all objectsrequestAnimationFrame(gameLoop);}requestAnimationFrame(gameLoop);
During review, pay attention to the following points:
- Are
updateandrenderseparated? - Does movement depend on
delta, so that behavior remains consistent across devices with different refresh rates? - Are game states reset correctly when the loop ends or a new round begins?
4. Key Principles for Prompt Design
Prompt quality directly affects an agent’s efficiency. The following four principles apply broadly:
- Keep the goal focused: Describe one deliverable per task instead of combining an entire product into a single instruction.
- State constraints early: Specify the language, framework, directory structure, and dependency restrictions at the beginning to reduce rework.
- Make acceptance measurable: Describe completion through observable behavior, such as “a bullet appears at the tank’s cannon after the Space key is pressed.”
- Work in stages: Implement the core loop first, then add the interface and other details. This makes it easier to validate each stage.
5. Managing Cost and Usage Limits
Coding agents are commonly measured in one of three ways: token-based billing, request-based billing, or subscription and usage quotas. Each approach suits different scenarios.
- Token-based billing: Longer context increases the cost of each request. Keep requirements concise and avoid asking the agent to repeatedly read large files.
- Request-based billing: A single request may include multiple rounds of tool calls. This can suit long, multi-step tasks, but the scope covered by each request should be clear.
- Subscription or quota-based usage: Pay attention to quota refresh rules and what happens when the quota is exhausted, especially during important tasks.
Regardless of the pricing model, teams should record the usage and completion quality of each task. This makes it easier to compare the cost-effectiveness of different tools and models.
6. Quality and Security Risks
Coding agents improve productivity, but they also introduce new risks.
- Logic errors: Generated code may work on common paths but fail under edge conditions, such as collision detection that misses corner cases.
- Security vulnerabilities: Directly concatenating user input into a page can introduce issues such as cross-site scripting. External input should be escaped or validated.
- Dependency risks: An agent may add unnecessary third-party packages. Before adding one, check its source, maintenance status, and license.
- Credential exposure: Plaintext keys should not be stored in the project directory. If credentials are required, inject them through environment variables or a secrets-management service.
- Overly broad permissions: Limit the directories the agent can access, and be cautious with network access and command execution. Require human confirmation for sensitive operations.
- Poor reproducibility: The same requirement may produce different code with different model versions. Record prompts, model versions, and important outputs for traceability.
7. Recommendations for Team Adoption
Teams can introduce coding agents in the following order:
- Run a pilot: Start with prototypes or non-critical projects and measure output quality and rework.
- Establish guidelines: Define which tasks are suitable for agents and which must be completed by humans, such as code involving payments or authorization.
- Create a testing baseline: Configure consistent build and test commands so the agent can validate its own work.
- Require code review: All agent-generated changes should be reviewed by a human before they are merged.
- Build a case library: Record successful and failed prompts, along with the reasons behind the results, to develop internal best practices.
8. Conclusion
The value of coding agents lies in connecting requirements, planning, execution, and verification into a continuous loop. This allows developers to reach a runnable prototype more quickly. Their effectiveness depends on three factors: clear requirements, reliable feedback signals, and strict human review.
For small projects, an agent can complete much of the foundational work. In production systems, however, it is better suited to repetitive tasks and initial drafts, while developers should retain control over critical decisions.
