AI Coding Agents: A Model-Agnostic Approach to Building Your Workflow
AI coding has moved from single-line autocomplete to autonomous agents that read repositories, run tests, and modify code. Rather than asking which tool or model to buy, this article reframes the decision as building a workflow organized into five layers: interaction, orchestration, execution, context, and cost. It explains how to treat models as replaceable compute behind a unified interface, route tasks across models using capability tags, separate orchestration from execution so strong models plan and fast models execute, manage context as a finite and expensive resource through budgeting and compaction, and turn unpredictable token spend into an attributable budget. It also covers multimodal inputs, security and governance boundaries, and a two-week pilot plan, ending with the idea that once models, context, and cost are handled deliberately, choosing a tool becomes a matter of configuration rather than allegiance.
Since code completion first appeared, the way developers collaborate with AI has gone through roughly three phases:
- Completion phase: AI only completes single or multiple lines of code in the editor, and the developer remains the sole decision maker.
- Conversation phase: The developer pastes an error message or code snippet to the AI, and the two go back and forth.
- Agent phase: AI can read the repository, retrieve files, execute commands, run tests, and modify code autonomously. The developer shifts from a “line-by-line author” to “the one who defines tasks, reviews approaches, and signs off on results.”
Today, all kinds of coding assistants and agentic command-line tools are appearing. The developer’s question has shifted accordingly: from “which model should I use” and “which tool should I buy” to “which agentic tool should I use.” This shift itself signals that the industry is maturing: the availability of tools is no longer the bottleneck, and the real difference comes from how work is organized.
This article does not judge which tool is better. Instead, it breaks these questions down into three problems that can be optimized independently: how to choose a model, how to manage context, and how to account for cost. Answer these three questions clearly, and you can build an AI coding workflow that fits your own codebase and team process.
1. Redefining the Problem: From “Picking a Tool” to “Building a Workflow”
If you see an AI coding assistant only as a “smarter input box,” then every choice means lock-in: to a model provider, a client, an extension ecosystem. A more subtle risk lies in lock-in at the level of habits. Using only one tool for a long time easily breeds a habit of coding by feel: direction is decided on intuition, results are verified by manually digging through logs, and usage is only revealed by the end-of-month bill.
It helps to adopt a “layered view” and split a complete AI coding workflow into five layers:
| Layer | Responsibility | Core question |
|---|---|---|
| Interaction layer | Provides the interface for conversation, diff review, terminal integration, and so on | How can developers express intent efficiently and review changes? |
| Orchestration layer | Understands the goal, makes a plan, dispatches tools, coordinates multi-agent collaboration | Who decides what to do, in what order, and to what degree? |
| Execution layer | Reads and writes files, runs commands, invokes tests and build tools | Who performs the concrete operations and keeps each step verifiable? |
| Context layer | Organizes system prompts, project rules, code retrieval results, and conversation history | What information should the model “see” at each step? |
| Cost layer | Measures token consumption, calculates spend, sets budgets and alerts | Is a task worth spending this way? |
This view yields two key conclusions.
First, each layer can be replaced independently. Today you might use an agentic command-line tool with broad model support; tomorrow you could switch to a graphical agent, or even call a model provider’s API directly and build your own flow. The underlying methodology can be reused. The tool is the carrier; the workflow is the asset.
Second, each layer can be optimized independently. Many teams’ pain points are not that the model is not strong enough, but that the layers are mixed together: all operations are done by the same set of prompts, all content is stuffed into the same context window, and all consumption is recorded on the same bill. Once you separate the layers, optimization gets a clear direction. The following sections take up these layers one by one.
2. First Principles: Treat the Model as a Replaceable “Compute Resource”
In the past, developers worried about “locking into one model,” largely out of fear of being tied to a single capability leader. Over the past couple of years, the situation has changed structurally:
- Newer models from multiple vendors have clearly narrowed the gap on key tasks such as code understanding, multi-file editing, and tool calling, and a single model’s advantage now shows up mainly on specific task types;
- Mainstream model services generally offer compatible interface shapes, so the engineering cost of switching models has dropped significantly;
- Price competition continues, and the amount of inference capability you can buy for the same budget is rising quickly.
In this landscape, a more sensible approach is to treat the model as a “replaceable compute resource”: do not bet on any single ecosystem, but route each task to the most suitable model based on difficulty, latency needs, and budget.
(1) A Unified Interface Layer: Write the Adapter Code Once
If you write a separate calling logic for each model, the cost of switching providers stays high. A more robust approach is to design a thin unified interface layer that business code depends on only. Example code:
# Unified model interface: hide differences between underlying providers (illustrative)from dataclasses import dataclassfrom typing import Iterable@dataclassclass ModelRequest:system: str # System promptmessages: list[dict] # Conversation historytools: list[dict] # Tool definitions available to the modelmax_output_tokens: int # Maximum output lengthtemperature: float = 0.2 # Lower values suit code tasksstream: bool = True@dataclassclass ModelResponse:text: strtool_calls: list[dict]input_tokens: int # Used for cost accountingoutput_tokens: intclass ModelProvider:def chat(self, req: ModelRequest) -> ModelResponse:raise NotImplementedError
To add a provider, you only implement the chat method and register it in a registry. The orchestration logic, prompt templates, and cost accounting code do not change at all.
(2) Capability Tags and Routing Policy
Maintain a set of capability tags for each model (such as reasoning depth, context length, response speed, vision support, cost tier), and define routing rules accordingly:
# Model routing policy (illustrative)roles:planner: # Orchestration: decompose requirements, design solutions, tackle hard problemsprefer: ["reasoning-strong"]fallback: ["general-strong"]executor: # Execution: file read/write, batch small changesprefer: ["fast-general", "cost-low"]vision: # Multimodal: screenshot understanding, chart interpretationprefer: ["vision-capable"]review: # Review: use a different model to reduce self-evaluation biasprefer: ["general-strong"]exclude_same_as: ["planner"]policy:max_retries: 2 # Fall back to backup models on failuremax_cost_per_task: 0.30 # Per-task budget cap (illustrative)
The value of multi-model collaboration lies in cross-validation. Having different model families evaluate the same solution often exposes a single model’s blind spots.
(3) Choose Models with a Private Task Set, Not Leaderboards
The payoff from evaluating model capability ultimately depends on how well the evaluation set matches your actual tasks. Public leaderboards are a useful reference, but they cannot replace a private task set of just a few dozen problems. When building a private task set, you can select representative samples from historical commits:
- A real bug and its fix commit: tests whether the model can locate the root cause;
- A cross-module refactor: tests multi-file consistency when making changes;
- A dependency upgrade: tests understanding of the build system and version constraints;
- A test addition: tests understanding of business semantics.
Define a clear acceptance criterion for each problem, for example “all specified tests pass,” “zero warnings from static checks,” “number of changed files does not exceed expectations.” Then fix the model version and prompt template, score under a consistent methodology, and track over the long term. Metrics that reflect real gains are often not just “pass on the first try,” but also the number of interaction rounds and token consumption needed to reach the same quality.
3. Separate the Orchestration and Execution Layers: Don’t Make the “Brain” Do Manual Labor
Many teams find in practice that the same model sometimes performs excellently and sometimes keeps “going in circles,” making contradictory changes before and after. The reason often lies not in the model itself, but in unreasonable task allocation.
The orchestration layer needs strong reasoning to understand requirements, break down steps, judge whether an approach is viable, and decide when to converge. The execution layer mostly faces concrete operations with clear goals, such as changing ten config entries in a specified format, completing a function implementation, or running tests and categorizing failures. Having an expensive model take on the latter is like using an expert’s time for assembly-line work: both costly and slow.
So the better architecture is “a strong model makes the plan, a fast model does the execution”:
- The orchestration layer breaks the goal into several independently verifiable subtasks, each with clear input, output, and acceptance conditions;
- Subtasks are dispatched to the execution layer, which returns results with a structured change summary;
- The orchestration layer only validates and decides: if it passes, move to the next step; if it fails, re-dispatch with the error information.
# Task dispatch template (illustrative)[Task ID] T-03[Goal] Add unit tests for the order module, covering stacked coupon scenarios[Input] Relevant source paths, interface contracts, existing test style[Constraints] Do not modify the source under test; add test files only[Acceptance] The specified test command exits with code 0; coverage no lower than existing modules[Budget] At most 8 tool calls; if exceeded, return "needs human intervention"
This kind of dispatch brings three direct benefits:
- Cost control: The expensive model handles only a few decision points;
- Clean context: The execution layer only needs to see code relevant to the subtask, and does not have to carry the whole conversation history;
- Recoverable failures: When a subtask fails, you only re-run that subtask, not tear down and rebuild the entire chain.
Going further, you can let multiple execution-layer instances process non-conflicting subtasks in parallel, for example adding tests for different modules. Here you must restrict each instance to a set of writable paths to avoid conflicts from parallel writes. The full orchestration logic can be summarized as follows:
def orchestrate(goal: str) -> Result:plan = call_model("planner", plan_prompt(goal)) # Strong model: make the planctx = ContextBudget(limit=120_000) # Global context budgetfor task in plan.tasks: # Allocate context per taskresult = run_with_budget(model="executor", # Fast model: executetask=task,budget=ctx.slice(task.max_tokens),max_steps=task.max_steps,tools=task.allowed_tools, # Least privilege)if not result.accepted: # Re-dispatch with feedback if validation failstask.feedback = result.error_summarycontinuereturn summarize(plan, ctx.usage)
Finally, one point deserves emphasis: separating orchestration from execution still relies on automatic verification as the safety net. In a repository without tests and static checks, no amount of layering can prevent “self-confirming” errors from the model. So before building the workflow, first make sure the project has a one-command test command and a set of static check tools. This is the infrastructure that determines whether an agent can work reliably.
4. Context Engineering: The Key to Whether an Agent’s Core Is “Usable”
If the model sets the upper bound of an agent’s capability, context determines how much of that capability can actually be realized. In practice, most of the “it doesn’t feel smooth” complaints come from missing context management, not from a model that is not strong enough.
(1) Budget Awareness: Context Is a Finite and Expensive Resource
Every reasoning step carries the system prompt, project rules, retrieved code snippets, and the entire conversation history. A rough estimate:
- A full directory tree description takes several thousand tokens;
- A moderately sized service file can consume tens of thousands of tokens;
- A single command output of hundreds of log lines quickly accumulates into a considerable token volume.
When context approaches the window limit, the model shows two typical problems:
- Attention dilution: Key information gets buried by large amounts of irrelevant content, leading to omissions or misjudgments;
- Cost spike: Input cost for long context grows linearly or even accelerates.
So the context budget should be treated as a first-class citizen in the design, with a clear quota for each type of content:
# Context budget allocation example (illustrative, 120K tokens total)├─ System prompt + tool definitions ≈ 8K fixed overhead├─ Project rules (loaded on demand) ≤ 6K loaded per workspace, avoid global injection├─ Code retrieval results (Top-K) ≤ 24K selected dynamically by task relevance├─ Task instructions + change summary ≤ 12K structured, de-duplicated├─ Tool returns (truncated) ≤ 30K logs keep only errors and key paths└─ Reserved ≈ 40K left for multi-turn reasoning and output
(2) Context Ingestion and Digestion: Narrow Down First, Then Summarize
Context management can be split into two actions in opposite directions: ingestion brings external information into the context, while digestion compresses and distills it when there is too much.
The ingestion phase follows the principle of “load on demand, progressive disclosure”:
- First read the directory structure and key config files to understand the project skeleton;
- Then retrieve the most relevant files based on the task description, rather than reading the whole repository;
- When you need external docs, first get a summary, and only after confirming relevance get the full text.
The digestion phase has two strategies that can be combined:
- Compaction: When history approaches the budget limit, distill early conversation into a structured summary (actions completed, facts confirmed, problems outstanding), keeping the most recent few turns verbatim;
- Offloading: Write intermediate artifacts to files, such as a plan checklist, command output, or a list of failing cases, and keep only pointers in the context, reading them on demand.
An example of a context assembly function that can be put into practice:
def assemble_context(task, project_index, history, budget=120_000):ctx = []ctx += load_rules(task.workspace) # Workspace-level rulesctx += retrieve_code(task.query, project_index, top_k=8) # Retrieve on demandctx += build_task_brief(task) # Structured task briefctx += recent_turns(history, keep=8) # Keep recent turns verbatimif count_tokens(ctx) > budget * 0.7: # Summarize earlier content when over thresholdsummary = summarize(history[:-8])ctx = ctx[:3] + [summary] + ctx[-2:]return ctx
Here recent_turns trims the history, and summarize compresses the trimmed part into a structured summary:
def recent_turns(history, keep=8):# Keep the most recent `keep` turns; earlier content is compressed by summarizereturn history[-keep:] if len(history) > keep else historydef summarize(turns):# Structured summary: done, confirmed, todos, risks (illustrative)facts, todos, risks = [], [], []for t in turns:facts.extend(t.get("facts", []))todos.extend(t.get("todos", []))risks.extend(t.get("risks", []))return {"role": "summary","facts": facts[-20:], # Keep only the most recent key facts"todos": todos[-10:], # Deduplicated todos"risks": risks[-5:], # Unresolved risks}
(3) Externalize the Rules: From Coding by Feel to a Reviewable Plan
The typical “coding by feel” flow is: describe the requirement in one sentence, the model jumps right in, and the developer afterward flips through a large set of changes and hopes for the best. A more robust approach is to externalize rules and plans into readable, version-controlled files.
- Project-level rules: Maintain a description file in the repository that spells out tech stack versions, directory conventions, code style, test commands, directories that must not be modified, and so on, so every session loads it automatically and you avoid repeating yourself;
- Session-level plan: Before a complex task, have the orchestration layer first output a plan checklist (which files to change, how many steps, how to verify each step), and let the developer review and approve it before execution proceeds;
- Change list: After each task, automatically summarize “which files changed, what was done, which verifications ran, and what issues remain” for human review.
This way, the developer’s energy shifts from “staring at the screen line by line” to “reviewing plans and acceptance results,” and controllability improves significantly. At the same time, be clear that context management cannot eliminate model hallucinations; it can only lower the probability that hallucinations are triggered. Making the verification step solid is the fundamental guarantee.
(4) Extension Mechanisms: Fill Experience Gaps with Pluggable Capabilities
An agent’s core usually provides only the minimum viable capabilities, such as conversation, tool calling, and permission control. This is both restraint in design and a sign that after onboarding it may feel like “something is missing”: no context budget management, no custom commands, no integration with internal systems.
Extension mechanisms are designed exactly for this, and developers can install or build extensions as needed:
- Context management: budget control, summary compaction, retrieval augmentation;
- Workflow: custom commands, plan templates, review checklists;
- Integration: connecting to an internal knowledge base, requirement management system, or CI/CD pipeline.
A practical piece of advice: install only the extensions you actually need right now, and verify each one’s permission scope and behavior one at a time. The more extensions you have, the harder behavior is to predict and the higher the troubleshooting cost.
5. Cost Management: Turn Unpredictable Spend into an Accountable Budget
AI coding spend usually comes from three parts:
- Fixed spend: subscription fees, seat fees, tool license fees;
- Variable spend: API calls billed by token;
- Hidden spend: rework, review, and the extra cost of building tests to verify AI output.
Focusing only on the first part often leads to misjudgment.
(1) Combine Subscription and Pay-as-You-Go: Cover the Daily with “Free Quota,” Handle the Long Tail with “Pay-as-You-Go”
Subscriptions usually come with a periodic quota, are friendly to everyday interactive use, and have predictable marginal cost; pay-as-you-go is flexible and transparent, and suits scripted batch processing and multi-model switching. Using both together reduces waste while preserving flexibility.
If your organization has already purchased a uniformly licensed AI coding tool, try using its periodic quota to cover daily tasks and reserve the pay-as-you-go budget for more complex scenarios, such as cross-repository refactoring, large-scale test generation, and multi-model cross-review. Staying actively engaged within the quota allowance is far more cost-effective than “buy it and not use it, then lose it at month end.”
(2) Attribute Cost to Tasks, Not Billing Periods
With only total quota data, it is hard to tell which task types are consuming budget. It is worth adding unified tracking at the call layer, recording input and output tokens, model, elapsed time, and final status (success, retry, abort) per task:
# Unified metering at the call layer (illustrative)def record(task_id, role, model, resp, status):usage.append({"task_id": task_id,"role": role, # planner / executor / vision / review"model": model,"input": resp.input_tokens,"output": resp.output_tokens,"status": status, # success / retry / aborted})
With this data, you can answer a few key questions:
- Which role accounts for the largest share of consumption?
- Are there many tasks that “still fail after retries”?
- How many tokens does each requirement consume on average, and is the trend rising or falling?
(3) Put Waste in a Cage of Rules
Common token waste mainly comes from four sources:
- Repeatedly rebuilding context: Every session re-reads a large number of files. You can build a project index and reuse it across sessions;
- Blindly expanding the search scope: Too many retrieval results. You can set a Top-K limit and prioritize retrieving modules directly related to the task;
- Unbounded loops: The model gets stuck in a “wrong change → error → wrong change again” loop. You can set a per-task limit on the number of tool calls and a budget cap, handing it over to a human when exceeded;
- Unconstrained exploration: Letting the model refactor over a wide area without limiting the scope. You should specify in advance the list of files allowed to change, especially for projects where the repository root may contain large binary files, and you should not let the model traverse freely.
The goal of cost management is not “the less the better,” but “every dollar spent corresponds to a verifiable output.” A sample budget table can be designed like this:
| Task type | Suggested role combination | Per-task budget (illustrative) | Acceptance criterion |
|---|---|---|---|
| Single-line / small-scope change | Execution layer | ≤ 0.01 | Compilation and static checks pass |
| Feature addition (single module) | Orchestration + execution layer | ≤ 0.10 | New tests pass, human review |
| Bug localization and fix | Orchestration + execution + review layer | ≤ 0.30 | All regression tests green |
| Cross-module refactor | Multiple layers + parallel instances | ≤ 1.00 | Staged commits, verified piece by piece |
The amounts in the table are only there to illustrate the management idea of “layered limits,” and teams should re-calibrate them based on their own model pricing and task difficulty.
6. Multimodal Capabilities: Fill the “Look and Speak” Gap
Many engineering tasks inherently contain visual information, such as reproducing designs, UI walkthroughs, interpreting architecture and flow diagrams, and analyzing error screenshots. When relying only on a pure-text interface, developers often have to describe the image in words first, which is time-consuming and easy to miss details.
By adding vision-capable models to the routing table, you can plug these tasks directly into the workflow. Typical uses include:
- Generate a component skeleton from a design mockup, then have a text model complete the logic;
- Compare a design mockup with a running screenshot, output a difference list, and use it as the basis for changes;
- Interpret an architecture or sequence diagram and produce a first draft of module documentation for human editing.
Note that a vision model’s output should be treated as “a draft to be verified.” For concrete values such as dimensions, spacing, and colors, cross-check against the design spec rather than adopting them directly.
7. Security and Governance: Set Boundaries First, Then Talk About Efficiency
Agents can read and write files and execute commands, which is both a source of efficiency and a source of risk. Before expanding usage, it is worth establishing some basic security boundaries:
- Tool whitelist: Only allow the agent to invoke necessary commands, and require human confirmation for destructive operations (such as deleting directories, force-pushing, or changing permissions);
- Path restrictions: Limit writable directories and forbid out-of-bounds changes to config or system files;
- Environment isolation: Run in a container or a separate cloud development environment to avoid mistakes affecting the local machine;
- Secret management: Inject all secrets via environment variables or a secret management service, and never commit them to the repository or paste them into a conversation;
- Handling untrusted content: Issue descriptions, web pages, dependency packages, and other external inputs all have a chance to enter the context. Treat their content as data rather than instructions, and guard against prompt injection attacks.
If your code assets have high compliance requirements, you can consider cloud platforms such as Baidu AI Cloud, using capabilities like cloud development environments, code hosting, and model services, together with unified identity authentication, access auditing, and logging services, to meet internal management and compliance requirements and form a “develop–verify–release” loop.
8. A Rollout Checklist: Start with One Pilot
You don’t need to refactor all processes at once. You can run a small-scope pilot over two weeks:
- Week 1
- Set up the unified model interface and routing configuration;
- Select 10–20 representative historical tasks to build a private evaluation set;
- Establish token metering and budget alerts.
- Week 2
- Pilot the separation of the orchestration and execution layers in a small group of 2–3 developers;
- Record each task type’s elapsed time, number of reworks, and cost;
- Adjust the budget table and routing policy based on the data.
After the pilot, decide whether to roll it out to the team and whether to introduce stricter permission and audit mechanisms. To judge whether the pilot succeeded, look at four signals: whether the requirement delivery cycle shortens, whether the rework rate in code review drops, whether average token consumption per task tends to stabilize, and whether developers are willing to keep using it unsupervised.
9. Conclusion: Put the Choice in Your Own Hands
Back to the opening question: which agentic tool are you using? The answer this article wants to give is: tools will keep iterating, and models will keep changing, but the layered methodology, the habit of managing context, and the ability to visualize cost are what can accumulate over the long term.
When the model is treated as a replaceable compute resource, context is treated as a resource that needs a budget, and cost is treated as data that needs attribution, choosing shifts from “picking a side” to “configuration.” As for which model and which tool to use, leave that to your evaluation set and budget table to answer, not to public opinion or habit.
