AWS Builder Center

From Prompt to Production: Choosing Prompt Engineering, RAG, Fine-Tuning, and Agents

A practical framework for choosing the lightest AI customization method that can meet an application's quality, freshness, cost, and governance requirements.

Generative AI teams often begin with a model and immediately ask how to customize it. Should they write a better prompt, connect a knowledge base, fine-tune the model, or build an agent?
The answer should come from the problem. Each technique solves a different limitation, and a production system can combine them. The practical rule I use is simple: start with the least complex approach that can meet the requirement, evaluate it, and add another layer only when evidence shows that it is necessary.

Start by identifying the real gap

Before choosing a technique, ask four questions:
  1. Does the model understand the task?
  1. Does it have access to the information required to answer?
  1. Does it consistently follow the expected behavior and format?
  1. Does the application need to take actions or coordinate multiple steps?
These questions map naturally to prompt engineering, retrieval-augmented generation (RAG), fine-tuning, and agents.

Use prompt engineering when the model knows enough

Prompt engineering is usually the fastest and cheapest place to start. It works well when the model already has the necessary knowledge but needs clearer guidance about the task.
A useful prompt can include four elements:
  • Instruction: what the model must do.
  • Context: the purpose, audience, domain, and relevant constraints.
  • Input data: the content the model must analyze or transform.
  • Output indicator: the expected structure, tone, length, or format.
For example, “Create a market analysis” leaves too many decisions to the model. A stronger prompt identifies the financial sector, the small-business audience, the required sections, the professional tone, and the evidence that should support each recommendation.
Examples can make the behavior even clearer. A zero-shot prompt gives instructions without a demonstration. A few-shot prompt includes representative input-output pairs. For a multi-step problem, a structured reasoning prompt can ask the model to break the task into smaller steps and verify intermediate results.
Inference parameters also matter. Lower temperature values favor predictable outputs, which can help classification and extraction tasks. Higher values increase variation and may help brainstorming. Top-p and top-k restrict the set of possible next tokens in different ways, while maximum length and stop sequences control when generation ends.
Prompt engineering is a good choice when:
  • the task is already within the model's capabilities;
  • the required information fits in the available context;
  • the desired behavior can be described with instructions and examples;
  • fast iteration and low operational complexity are priorities.
However, a prompt cannot provide information that is missing, private, or newer than the model's knowledge.

Use RAG when the missing piece is knowledge

Retrieval-augmented generation connects the model to an external source of information. Instead of expecting the model to remember every fact, the application retrieves relevant passages and adds them to the context before generating the answer.
A basic RAG workflow is:
  1. ingest and split documents into useful chunks;
  1. create embeddings that represent their meaning;
  1. store and search those representations;
  1. retrieve the passages most relevant to a query;
  1. generate an answer grounded in the retrieved context.
RAG is especially useful for internal documentation, product catalogs, policies, research collections, support knowledge, and frequently updated information. The source can be updated without retraining the model, and the application can return references that allow users to inspect the evidence.
RAG quality depends on more than the model. Poor document extraction, arbitrary chunk boundaries, missing metadata, weak retrieval, or irrelevant context can all degrade the final answer. Evaluation should therefore measure retrieval and generation separately. Useful questions include whether the correct source was retrieved, whether the answer is supported by that source, and whether the response admits when the evidence is insufficient.
On AWS, services such as Knowledge Bases for Amazon Bedrock can support managed retrieval workflows, while access controls and encryption still need to reflect the sensitivity of the underlying data.
RAG is a good choice when:
  • answers depend on private, domain-specific, or current information;
  • sources change more frequently than a model should be retrained;
  • users need traceability or citations;
  • the organization wants to keep knowledge separate from model behavior.

Use fine-tuning when the gap is consistent behavior

Fine-tuning changes a model using a curated dataset of task-specific examples. It can improve consistency for a repeated behavior, terminology, tone, or specialized output pattern.
It is useful when good prompts and representative few-shot examples still cannot produce reliable results at the required scale. Examples include a stable classification scheme, a distinctive writing pattern, or a domain task with many high-quality labeled demonstrations.
Fine-tuning is not the best tool for teaching the model facts that change every week. Updating a knowledge source through RAG is usually more manageable for that requirement. Fine-tuning also introduces a data lifecycle: examples must be collected, cleaned, reviewed, split for training and evaluation, versioned, and monitored after deployment.
The decision must include operational trade-offs. Training has a cost, customized models require evaluation, and new versions of the base model or dataset may require another training cycle. A small but accurate dataset is more valuable than a large collection of noisy or contradictory examples.
Fine-tuning is a good choice when:
  • the desired behavior must be highly consistent across many requests;
  • the task has enough high-quality examples;
  • prompts have become long, fragile, or insufficient;
  • the expected benefit justifies training and lifecycle costs.

Use agents when the application must decide and act

An agent adds a control loop around a model. It can interpret a goal, select a tool, inspect the result, and decide what to do next. This is useful for workflows whose steps cannot be fully predicted in advance.
For example, a research assistant might search a knowledge base, compare documents, request another source when evidence conflicts, generate a report, and send the draft for human review. RAG provides relevant knowledge; the agent decides when and how to use it.
This flexibility creates risk. Every tool expands what the system can affect. Production agents need narrowly scoped permissions, validated inputs, clear stopping conditions, audit logs, and human approval before consequential actions. A workflow that can be expressed as deterministic code should not become an autonomous loop only because agents are available.
Amazon Bedrock Agents can help orchestrate models, knowledge sources, and action groups. Services such as AWS Identity and Access Management (IAM), AWS Key Management Service (AWS KMS), AWS CloudTrail, and Amazon CloudWatch support access control, encryption, auditability, and monitoring around the application.
Agents are a good choice when:
  • the task requires multiple tools or changing sequences of steps;
  • the next action depends on an intermediate result;
  • permissions can be limited to the minimum required scope;
  • failures, costs, and high-impact actions can be monitored and controlled.

These techniques are layers, not competitors

A production application may use all four techniques:
  • a prompt defines the role, task, constraints, and output format;
  • RAG supplies relevant and current evidence;
  • fine-tuning improves a repeated behavior that prompting alone cannot stabilize;
  • an agent chooses tools and coordinates a multi-step workflow.
Consider a financial market-analysis assistant. The prompt specifies the audience, report sections, and tone. RAG retrieves internal research and current approved documents. Few-shot examples demonstrate the organization's reporting format. An agent can decide whether more evidence is needed and prepare a draft for review. Fine-tuning becomes reasonable only if evaluation shows that the required behavior remains inconsistent across a large volume of reports.

Evaluate before adding complexity

Architecture decisions should be based on measurable failure modes. A useful evaluation set includes realistic requests, difficult edge cases, and examples where the correct response is to state that information is unavailable.
Measure what matters to the use case:
  • task accuracy and completeness;
  • groundedness and retrieval relevance;
  • format adherence;
  • latency and token cost;
  • harmful or biased output rates;
  • tool-selection accuracy and agent task completion;
  • human acceptance or correction rate.
Security and governance belong in the same evaluation process. Protect confidential data, filter or reject untrusted instructions, test for prompt injection and information leakage, document model and dataset choices, and define who can approve changes.

A practical decision sequence

When starting a generative AI application, I would use this order:
  1. Build a clear prompt and a small evaluation set.
  1. Add examples or structured steps when the task needs them.
  1. Add RAG when answers require external knowledge.
  1. Consider fine-tuning when behavior remains inconsistent and sufficient data exists.
  1. Add an agent only when dynamic tool use creates real value.
  1. Re-evaluate quality, cost, latency, security, and operational risk after every change.
The most advanced architecture is not automatically the best one. A strong solution uses enough complexity to solve the problem reliably, while remaining understandable, testable, and safe to operate.


This article reflects lessons I consolidated while studying prompt engineering, foundation-model optimization, generative AI solution development, and security and governance for AI solutions in AWS Skill Builder.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article