AI-Assisted Programming: From Requirement Exploration to Production Engineering

    AI coding assistants are now part of everyday development, but outcomes differ based less on how often you prompt and more on whether you correctly identify the cognitive stage of a task. This article presents a practical framework for collaborating with AI in software development: distinguishing open-ended exploration from constrained implementation, writing checkable contracts (main path, invariants, failure modes, acceptance tests), and separating domain logic from infrastructure concerns. Using a history simulator that models how information propagates and distorts among people as a running example, it covers object modeling, testable transformation rules, engineering concerns like idempotency and observability, prompting and review habits, common failure patterns, and a reusable collaboration sequence for turning AI assistance into a repeatable engineering method.

    AI-assisted programming has become part of daily development, but the difference in results rarely comes from how often you ask. It comes from whether the task’s cognitive stage has been correctly identified. The same requirement calls for open-ended questioning when the concept is still taking shape, and for converging on executable design and implementation once the flows, boundaries, and data structures are clear. Mixing these two states typically produces a pile of conflicting ideas early on, followed by large amounts of unmaintainable code generated without invariants later.

    First, Determine Which Cognitive State the Task Is In

    A simple criterion can divide the work.

    The first state is “abstraction not yet formed.” The developer doesn’t know what roles, constraints, and failure modes exist in the domain; the frontend information architecture, interaction drafts, and relationship diagrams are still unstable. At this point, the goal is not immediately mergeable code, but a vocabulary built as quickly as possible: what the objects are, how events occur, which quantities must be conserved, and which are merely presentation. Broad-spectrum Q&A suits this stage because it lays out scattered common knowledge, analogies from adjacent domains, and multiple formulations, helping people discover the questions they missed.

    The second state is “abstraction is clear.” The developer can explain the main path in their own words: where input comes from, how state changes, how exceptions terminate, and how results are observed. What remains is fitting that flow into the chosen module boundaries, interfaces, and tests. At this point, open-ended brainstorming should be reduced in favor of tightly constrained implementation assistance: given types, given invariants, given acceptance examples—let the assistant generate within the framework rather than reinvent it.

    The two states can alternate within the same requirement. When a sub-mechanism exposes unknowns, fall back to clarification; once boundaries close again, return to implementation. Stage mismatch is more common than insufficient model capability.

    Allocate Collaboration by Nature of the Work, Not by Habit

    Daily development can be roughly divided into categories, each matched with a different style of prompting.

    For unfamiliar business logic, visual hierarchies, information graphs, and interaction drafts, prefer open-ended Q&A. Ask the assistant to list candidate approaches, their premises, and mutually exclusive assumptions—rather than jumping straight to “best practices.” The output of this stage should be question lists, glossaries, and disposable sketches, not direct commits to the main branch.

    For business logic you can already write as steps, switch to closed tasks. The prompt should specify: module responsibilities, invariants that must not be broken, input/output examples, error-handling principles, and the code style to maintain. The value of AI-generated code here is accelerating boilerplate, filling in branches, and cross-checking tests—not deciding the architecture for you.

    Frontends and diagrams are especially prone to being prematurely “finished.” If page structure, component boundaries, and state sources aren’t first written down as constraints, generated results often look complete while failing to align with the backend event model. A safer order: first fix the user-visible states in text, then draw the information relationships, and only then generate the UI skeleton.

    Write the “Clear Abstraction” as Checkable Contracts

    “Having the flow in your head” cannot remain a verbal description. Before implementation, fix at least four things.

    First, the main path. Write the normal-case data movement as numbered steps, with the responsible party for each step.

    Second, invariants. Which facts must hold at all times. For example: “the original text of a message exists in exactly one copy, and derivative tellings must point to their source,” or “an observer cannot read events it has not yet received.”

    Third, failures and deviations. Business-allowed deviations must be separated from system errors. In a history simulation, “a retelling that distorts” is domain behavior; serialization failures, duplicate delivery, and clock rollback are engineering faults.

    Fourth, acceptance. Every invariant should map to at least one automatically executable example: given an initial state and a sequence of events, assert the final observable result.

    Only after the contract is written does AI generation have boundaries. During review, check first whether the contract was violated, then look at naming and performance. Code review without a contract easily degenerates into arguments about stylistic preference.

    Case Study: Information Propagation in a History Simulator

    Let’s use a history simulator to illustrate the path from abstraction to implementation. The core mechanism is not “time moving forward” but information propagating through a population: characters hold subjective views, and when they retell, they distort, filter, or emphasize—so what later generations hear is often not the original fact.

    First, Fix the Domain Objects

    Distinguish at least these concepts:

    • Event: a fact that actually occurred in the world, with a time and participants, never rewritten by tellings.
    • Record (belief): a belief a person holds about an event, including its source, confidence level, and narrative text.
    • Telling: an act of propagation that sends one of the teller’s beliefs to an audience.
    • Lens: the teller’s stable tendencies—loyalty, fear, self-interest, or knowledge limits—explaining why the same record becomes different texts.
    • Audience update: how a listener merges a telling into their own beliefs: accept, doubt, overwrite, or hold in parallel.

    The key abstraction here: separation of fact and belief. The event log is append-only and immutable; each person’s belief store is mutable and must be traceable to a specific telling. If “history” is stored as a single blob of text that keeps getting rewritten, you can no longer explain where disagreements came from, nor run regression tests.

    Propagation Is Not Simple Copying

    A telling can be decomposed into deterministic transformations rather than inexplicable random text.

    1. Selection: the teller picks the subset of their beliefs they’re willing to share—silence is itself a lens.
    2. Distortion: the content is rewritten within allowed transformation rules—exaggerating numbers, omitting motives, stating the uncertain as certain. Rules should be configurable and replayable, so runs are comparable.
    3. Delivery: listeners only receive the telling if it is spatiotemporally reachable, the relationship permits it, or a channel exists.
    4. Merge: the listener assigns credibility according to their own lens. Conflicting beliefs can coexist, with a record of “who I heard it from.”

    The later generations’ stories thus form a traceable derivation tree rather than overwrites. The simulator can then answer two questions: what did a given person believe at a given time, and through which transformations did that belief pass from the original event?

    Constrain Implementation with a Schematic Structure

    The following structure expresses only domain relationships, unbound to any framework. Implementation can adopt whatever type system and persistence the team already uses.

    1. Event: id, time, participants, facts
    2. Belief: id, holder, about_event, source_telling, confidence, narrative
    3. Lens: holder, omit_rules, amplify_rules, certainty_bias
    4. Telling: id, teller, audience, belief_id, time, applied_rules, delivered_text
    5. Invariant: delivered_text must be traceable to belief_id
    6. a belief must not reference a telling that has not yet happened
    7. event.facts must not be modifiable by any telling after creation

    Before generating code, write these invariants into test names. For example: a listener’s belief set is unchanged when no telling is received; two runs with the same random seed and the same lens produce identical derived texts; querying the original event returns no adjectives added by tellers. Writing tests first, watching them fail, then filling in the implementation significantly reduces generated code that “looks plausible but isn’t reproducible.”

    Engineering Concerns to Handle Separately

    Information propagation easily gets entangled with infrastructure concerns—separate them.

    Consistency: event appends and belief updates should follow an explicit ordering. If a message queue carries tellings asynchronously, consumers must be idempotent—duplicate delivery must not create a second independent belief, only link to the same telling.

    Time: separate simulation time from processing time. Lenses and reachability should read only simulation time, so replaying at a different speed doesn’t change history.

    Observability: keep rule identifiers and input belief identifiers for every telling; replay by simulation time in the logging service. Monitoring should target queue backlog, duplicate consumption, and invariant-check failures—not whether a given narrative “reads well.”

    Capacity: shard beliefs by person and by event; object storage suits large derived texts, while indexes keep only queryable fields. Don’t stuff the entire narrative history into a single transaction.

    UI: the character-perspective page renders only that character’s currently visible beliefs; only the omniscient debug view shows event originals and the derivation tree. Don’t mix the data interfaces of the two views, or god-view information leaks into gameplay.

    If the team deploys the simulation service on the cloud, compute, queues, object storage, logging, and monitoring can be composed from general cloud capabilities. For example, on Baidu AI Cloud you might host the simulation service on a container platform, pass tellings through a message queue, store derived texts in object storage, and use logging and monitoring for replay verification. When choosing, compare against your own consistency requirements, retention periods, and permission model—don’t assume any cloud product will automatically understand the domain invariants of history simulation.

    Practical Prompting and Review Habits

    In the implementation stage, prompts should be short and hard: paste type definitions, invariants, and failure examples; require changes only to specified modules; and ask for tests before implementation. If the output starts redesigning the object model, the abstraction isn’t stable yet—stop generating and go back to clarification.

    The exploration stage is the opposite: forbid complete engineering, and instead ask for a comparison of three information-propagation models—how each explains “rumors” and “silence,” and which proposals conflict with “facts are immutable.” Humans make the trade-offs after seeing the comparison.

    Human responsibility cannot be outsourced. AI assistance does not own final judgment on domain correctness. Before merging, check at least: whether generated code introduced implicit state not in the contract; whether randomness is reproducible; whether errors are being swallowed; whether the UI reveals facts a character shouldn’t know. A checklist is more reliable than intuition for these checks.

    Common Failures and Corrections

    Asking for a complete project skeleton too early freezes the wrong abstractions into the directory structure. Correction: get one telling chain working end-to-end with the fewest types first.

    Writing lenses as untestable natural language makes generated histories incomparable across runs. Correction: register distortions as named rules; the text is just a rendering of the rules.

    Using the same oversized prompt for exploration and implementation—with brainstorming and old code both in context—leads the model to mix in discarded assumptions. Correction: switch context by stage, keeping only the current contract.

    Fully trusting compilation success misses semantic errors. A passing build means the type relationships roughly hold; it does not mean beliefs haven’t traveled backward through time.

    A Reusable Collaboration Sequence

    1. Use open-ended Q&A to enumerate unknown concepts and mutually exclusive assumptions, until you can explain the main path in your own words.
    2. Write down the objects, invariants, allowed deviations, and acceptance examples.
    3. Implement the minimal chain and its tests first, then expand lenses and channels.
    4. Only within the contract, request boilerplate, boundary cases, and debug views.
    5. Verify with replay, idempotency, and permission checks before touching performance and UI polish.

    This sequence doesn’t depend on any particular chat or code-completion product, and it doesn’t treat AI as the sole author. The principle: broad clarification reduces the unknown; in-framework implementation reduces deviation; humans own abstraction and trade-offs; the assistant accelerates within boundaries. The history simulator is just a sharp example—once fact and belief are conflated, the system immediately loses explainability. Order states, permission propagation, and configuration drift in other business domains can be organized the same way: immutable facts + traceable derivations + explicit invariants. Separate the stages clearly, and AI-assisted programming turns from random acceleration into a repeatable engineering method.