Building a Controllable AI Development Workflow with LLMs and AI Coding Tools
AI-assisted programming is powerful but often expensive to run at scale and prone to drifting from project goals. This article presents a practical approach: combine open-source LLMs with AI coding tools, assign collaboration modes by task type, and enforce clear development rules to keep AI behavior auditable and predictable. It covers task classification, model selection, cost estimation, and a sample rule set for confirmation-based execution.
Introduction
AI-assisted programming has become part of many developers’ daily workflow. In practice, though, two problems keep showing up. First, some AI coding tools are expensive to call, so developers hesitate to use them freely for batch refactoring or long-running automated tasks. Second, AI is often treated as a code-completion tool without a grasp of the project as a whole. Under complex requirements, it may drift from the original goal, change more than expected, and leave behind problems that are hard to trace.
This article presents one approach: combine open-source LLMs with AI coding tools, assign collaboration modes by task type, and constrain AI behavior with an explicit set of development rules. The goal is to make AI a development partner that can be reviewed and controlled.
1. Choosing a Collaboration Mode by Task Type
Tasks vary widely in granularity and risk. Handling everything the same way either wastes resources or makes risk hard to control. The following three categories work well in practice.
1.1 New Features and Multi-Module Refactoring
These tasks usually start from requirement analysis and involve architectural design plus coordinated changes across multiple files. Enable the full-pipeline mode of your AI coding tool so the AI participates in requirement decomposition, solution design, and step-by-step implementation. The developer only needs to provide a clear goal, constraints, and acceptance criteria. Because full-pipeline mode touches a large surface area, require the AI to output a plan first and execute only after confirmation.
1.2 Local Fixes and Debugging
Everyday bug fixes, unit test writing, and small logic adjustments fit a terminal-based AI assistant better. Terminal assistants start fast and can read logs, run test commands, and suggest fixes directly. Three precautions apply: grant the assistant the minimum command-execution permissions; run unfamiliar commands in an isolated environment or sandbox; and sanitize logs so secrets and user data never enter the conversation context.
1.3 Understanding Legacy Code
For large legacy codebases, use a model with a large context window to understand the overall structure. A 200K-token window, for example, can hold the source of a reasonably sized core module and is suitable for mapping cross-file dependencies, tracing call chains, and organizing business logic. But window size only sets the upper bound of a single input—it does not guarantee understanding quality. When the codebase exceeds the window, split it by module first, use retrieval to find relevant files, and feed key snippets into the model. Chunking plus retrieval is generally more stable than a single large input, and it is easier to verify the conclusions.
2. Model Selection and Cost Estimation
There are three main reasons to choose open-source LLMs: on-demand deployment, transparent per-call pricing, and easier unified management within a team. Compare models along these dimensions:
| Dimension | Description |
|---|---|
| Coding capability | Check public benchmarks, then run small-scale tests on real tasks from your own project |
| Context window | Determines how much code fits in a single input; must match your task scale |
| Call cost | Computed from input and output token prices; billing conventions vary across providers |
| Deployment and compliance | For sensitive code, prefer private deployment or compliance-compliant options |
| Stability and latency | Affects how long long-running tasks take; measure in your target network environment |
Cost can be estimated with a simple formula:
Cost per task ≈ (input tokens × input price + output tokens × output price) × number of calls × (1 + retry rate)
The retry rate should be derived from actual run logs. Before launching a long automated task, run a small sample through the pipeline, record the average token consumption, and extrapolate the total budget. This is far more reliable than guessing.
3. Development Rules: Making AI Behavior Predictable
Rules make AI behavior predictable. A rule set must answer three questions: whose instructions take priority, what to do when no rule applies, and which operations require prior confirmation.
3.1 Rule Priority
A recommended priority order is:
Explicit user instruction > project memory document > general development rules > AI’s own judgment
The user’s explicit instruction in the current conversation has the highest priority. The AI must not override a user request by claiming “the rules require otherwise.” The project memory document records global constraints such as the tech stack, directory structure, and prohibited actions, and should be read at the start of every session. If the project has no such document yet, the AI may create one with the developer’s consent, gradually accumulating project context.
For cases not covered by the rules, the AI can judge along three dimensions: rework risk, inferability, and scope of impact. Operations with high rework risk or broad impact should be asked about first. Small changes that can be reasonably inferred from context can be executed directly, with the reasoning explained.
3.2 Language and Communication
The rules should require the AI to reply in a language the team is comfortable with, reducing cross-language friction.
Complex requirements should be decomposed into small, verifiable tasks. After completing each step, the AI reports the result and waits for confirmation before proceeding. When requirements are ambiguous, ask before modifying. Key architectural decisions belong to the developer; the AI provides options and trade-off analysis.
3.3 Requirement Confirmation and Risk Control
Not every operation is suitable for direct AI execution. Two categories should require mandatory confirmation:
- Broad-impact operations: database schema changes, global configuration edits, refactoring of shared base modules, etc.
- Irreversible operations: file deletion, large-scale code overwrite, force-pushing code, etc.
For these cases, the AI should first present a change plan and an impact assessment, list the affected files or data, explain the rollback method, and wait for confirmation before executing. For database changes, take a backup first and validate the migration script in a test environment.
An impact assessment can use this template:
- Change objective:
- Affected scope (files, tables, services):
- Main risks:
- Backup and rollback method:
- Verification method:
- Items requiring confirmation:
For local business-logic adjustments or small fixes within a single file, the AI can execute directly, stating its understanding of the requirement and the location of the change.
4. Example Configuration
You can write the rules into the project’s system prompt or project memory document. Below is a simplified example. The exact file name and loading mechanism depend on the tool you use—refer to its official documentation.
# AI Development Rules## Pre-execution CheckBefore every response, confirm the project memory document has been read.## Rule PriorityExplicit user instruction > project memory document > other rules in this document > AI's own judgment## Language and Communication1. Reply in the team's primary language2. Break complex requirements into small tasks; implement step by step and report3. Ask when in doubt; do not make decisions unilaterally## Requirement ConfirmationFor the following cases, present a plan and wait for confirmation before executing:- Database schema changes (back up first)- Changes to global configuration files- Changes affecting shared modules or core business logic- Deleting files or overwriting code at large scale
Adapt the example rules to your team’s situation. The more rules there are, the more important it is to review them regularly to avoid conflicts between rules.
5. Adoption Suggestions
Step one: pilot the approach on a medium-sized project, starting with local fixes and unit tests. Step two: record the scope, time spent, and rework count for every AI change to build baseline data. Step three: refine task classification and rule details based on that data. Throughout the process, keep a human code-review step so that a person confirms whether each AI change matches the design intent.
This method can reduce repetitive work and lower the risk of unwanted AI changes. The actual benefit depends on your codebase size, task mix, and process maturity, and should be validated in your own projects.
