Prompt and Context Engineering to the AI Software Factory
Compare prompt engineering, context engineering, harness engineering, loop engineering and the AI software factory through one practical coding example

Published
By Hamza Imtiaz
barakodetechnologies@gmail.comFive ways to improve an AI coding workflow
Imagine that an AI coding agent fixes duplicate inventory updates in a warehouse service and every check passes, then two copies of the same notification arrive at once in production and the stock count rises twice
The team could write a clearer task, give the agent better repository information, add a more realistic test, change how attempts are retried or improve the process that decides what reaches production
Each response belongs to a different part of AI software engineering, and the warehouse example makes it possible to see where each part helps without changing the underlying problem
Prompt engineering defines the request, context engineering supplies the evidence, harness engineering provides tools and checks, loop engineering manages repeated attempts and the AI software factory connects that work to delivery and monitoring
A team can use all five practices together, even when the workflow is as simple as one developer reviewing a small patch in a single repository
Prompt engineering defines the task
Prompt engineering turns a broad request into instructions a model can act on, including the expected outcome, the constraints and the form of the result
For the warehouse service, ask the agent to preserve the existing response contract and ensure that one inventory event changes stock at most once per customer account, including when two copies arrive together
The phrase per customer account matters because two customers can receive events with the same identifier, and a change that treats those events as duplicates could quietly discard a legitimate adjustment
Specify what the agent should return, such as a focused patch, a short explanation of the change and integration tests for repeated and simultaneous delivery
Tell the agent what to do when information is missing, for example to identify the relevant storage or queue contract if it cannot tell where an accepted event becomes durable
A useful prompt gives reviewers a shared description of success, so the author and reviewer can discuss whether the change meets the same behavioral rule instead of evaluating only the appearance of the code
Keep the request narrow enough to inspect in one review, since the inventory fix can preserve unrelated reporting, authentication and stock reconciliation behavior while solving the specific duplication problem
Context engineering supplies the right evidence
Context engineering selects the information available to an AI agent as it works, including repository files, instructions, tool results and decisions from earlier attempts
The warehouse task needs a small set of precise references, including the webhook handler, the event storage rules, the worker that updates inventory and the tests that exercise the queue
Start with a short repository index that points to the current specification and the files that implement it, so the model can follow the request from arrival through storage and processing
The database schema can reveal whether event identity is unique per account, while the worker code can show what happens after a vendor request times out and the operation is retried
Check that the examples reflect the current system, because an old diagram can accurately describe a previous design while leading the agent toward the wrong transaction boundary today
When a run gets long, save a compact record of the decisions made, the checks already run and the failure that remains, then point the next session back to the original specification
A summary can help the next attempt start quickly, while the versioned specification preserves important details such as the account boundary and the requirement for one durable stock change
Harness engineering makes behavior testable
An AI coding harness is the environment in which the agent reads, edits and verifies work, with tools such as an isolated checkout, test commands, application logs and automated checks
A useful harness gives the agent enough access to observe the application with realistic test data and gives reviewers evidence they can reproduce without using production credentials
In the warehouse example, the most valuable test sends matching events through two independent requests at the same time, waits for processing and reads the durable records to confirm one inventory adjustment
An HTTP success response alone leaves the central question unanswered, since both requests can look successful even when their combined effect is incorrect
Add a separate scenario for two customer accounts using the same event identifier, where the expected result is one adjustment for each account
Keep the authoritative acceptance check under separate review, especially when the same agent can edit product code and tests, so any change to the release criteria is visible to the people who own them
Make failures specific enough to guide the next decision, for example by reporting that the stock ledger contains two adjustments for a single event instead of printing a generic integration error

Loop engineering controls retries and completion
Loop engineering defines what happens after an attempt, including which feedback reaches the agent, how many times it can retry and when a person needs to make a decision
A simple loop asks the agent for a candidate change and runs the verifier, then returns the relevant evidence if the result shows a behavior the agent can reasonably repair
For example, the first warehouse patch might pass repeated delivery in sequence and fail when two requests run together, so the next attempt should receive the failed scenario and the observed duplicate adjustment
A fresh session can recover the exact acceptance criteria from the specification while using the current change and verification report as its starting point
When the test database fails to start, the team has an infrastructure problem to investigate, and the loop should hold the candidate instead of repeatedly asking the agent to rewrite inventory logic
Give the loop a time or attempt budget and keep a record of the latest useful result, so a reviewer can see what changed and where the work stopped
The Ralph loop described by Geoffrey Huntley illustrates how repeated agent runs can use persistent project files to carry progress, while a bounded delivery workflow adds a clear verifier and an escalation path
The AI software factory connects verification to release
An AI software factory is a repeatable way to take a change from intake through implementation, verification, release and production monitoring while assigning responsibility for each decision
The warehouse team starts with a written specification, builds a candidate in isolation and runs its integration scenarios against the candidate that will actually be deployed
One important scenario models an inventory provider applying a change before its response is lost, so the worker retries and the verifier checks that the provider ledger still records only one adjustment
That test depends on an accurate model of how the provider recognizes duplicate requests, including the scope of its deduplication key and how long it remembers previously accepted operations
Record the identity of the tested build with the verification result, and use that identity when promoting the change so the release job can select the exact artifact the tests exercised
A gradual rollout gives the team time to compare expected stock movements with actual records, and a named owner can pause the rollout when reconciliation shows a mismatch
Human review can remain part of the factory at any stage, especially when a change affects customer data, external dependencies or operational decisions with a large cost of error

Choose the layer that addresses your bottleneck
Look at a recent change that needed human rescue and find the first point where the team had enough information to catch the problem
If the agent misunderstood the result, improve the prompt with a clear outcome and an example, and if it worked from outdated assumptions, make the current repository evidence easier to find
If a reviewer found a defect that the existing checks could have caught, improve the harness and confirm the new check fails against a known broken version
If people repeatedly relay useful failure reports and restart the same task, automate that handoff with a bounded loop and a clear reason to ask for help
If several teams already have reliable loops but struggle to trace approvals and releases, standardize how they record evidence and promote verified builds
Track the time it takes to reach a verified change along with human interventions and defects that escape, since each measure tells you something different about whether the workflow is improving
A practical first project for your team
Choose a recurring change with a clear result, such as updating an inventory rule or adding a field to an internal report, and write down how a reviewer can observe the result before an agent starts work
Have one person run the check against the current behavior and preserve the report in a place the next reviewer can find, then use the same check to compare the candidate with that baseline
After the first delivery, review which step consumed the most time and whether its output helped the next person make a decision, then change that step before expanding the workflow to more repositories
Common questions about AI coding workflows
Prompt engineering shapes the instruction for a task, while context engineering keeps relevant files, evidence and decisions available across the steps the agent takes
The harness supplies the checks and permissions for one attempt, while the loop uses the resulting evidence to choose whether to finish, retry or request human input
A software factory can start with a single repository and a simple release process, as long as the team can trace the request, the tested candidate, the decision to release and the production outcome
- Prompt engineering
- Context engineering
- Harness engineering
- Loop engineering
- AI software factory
Official sources
Product and policy references checked on November 27, 2026. Review the current documentation before implementation.
Want this applied to your project?
Tell us what you are building and we will help you define the technical plan behind it.
Contact via WhatsApp+92 300 8698044