Arun Pandian M

Arun Pandian M

Android Dev | Full-Stack & AI Learner

Written by: Arun Pandian M•Published on: Nov 29, 2026

Becoming an AI Engineer — Part 2: RAG and Agents

AI applications are no longer limited to answering questions. Many applications now need to work with external information, perform multi-step tasks, and interact with other systems. Two important patterns for building these applications are Retrieval-Augmented Generation (RAG) and AI agents.

https://storage.googleapis.com/lambdabricks-cd393.firebasestorage.app/ai_eng_blog_part2.svg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=firebase-adminsdk-fbsvc%40lambdabricks-cd393.iam.gserviceaccount.com%2F20261130%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20261130T053019Z&X-Goog-Expires=3600&X-Goog-SignedHeaders=host&X-Goog-Signature=0f29c89635827baaead75275246cc7af7c89244593219a306c20a4f0e9287f5809aa3355696334e696ad851742a800a74c2df8b2dc934e8613ee5c9b9be68807caf027f1b335ac622d1ccc9248d268f5b96f6b93acd7bcf3049c85041da641cad4b4b5514baca9ba57c35a26fb2f5b6c8687355322808dd091d22fc0346073d2af5a42addb224ac08728267e44df63a6775b7514e805ef091471e7176e2998e950f89adbf0b01fef0f8c1a8723383106e27ec5c6b511f0021806208469ae6bc955cfb0b102e0eb1801e3928e14b30e0f76e4373489a7d583231f8125bfcf384c01b2cf6bf0a253ef06aecf0b2223ee50a0951b7cde31827f32e3e3879ec94461

Why AI Applications Need More Than a Model

A simple model call is useful for answering questions, but it has limitations. A model call by itself does not automatically have access to an application’s private data or external systems, nor can it directly perform actions such as searching a database or updating a record. These capabilities need to be provided by the surrounding application. Real-world applications need more than just a model; they need systems that can retrieve information, determine what actions to take, and execute those actions.

To address some of these limitations, two useful patterns are Retrieval-Augmented Generation (RAG) and AI agents.

Understanding RAG: Retrieval-Augmented Generation

RAG enhances a model’s ability to perform tasks using relevant external information as context. Instead of relying solely on information learned during training, the application retrieves relevant content from one or more knowledge sources and provides that content to the model when generating a response.

How RAG Works

The RAG process involves three main steps:

Retrieval: The user’s query is used to search a knowledge source for relevant content. This may involve vector search, keyword search, hybrid search, metadata filtering, or a combination of these techniques.

Context Integration: The retrieved content is selected and provided to the model as context.

Model Response: The model uses the provided context to generate a response.

Embeddings and Vector Search

One common approach to retrieval uses embeddings. An embedding represents text as a numerical vector that captures patterns and relationships learned by the embedding model, which can be useful for measuring semantic similarity. Documents and queries can be converted into embeddings and compared using a similarity measure to find content that is semantically related.

For example:

Document
    ↓
Embedding Model
    ↓
Vector
    ↓
Vector Database

At query time:

User Query
    ↓
Embedding Model
    ↓
Query Vector
    ↓
Similarity Search
    ↓
Relevant Documents

Embeddings are one retrieval technique, rather than a requirement for every RAG system.

Conceptual RAG Flow:

query = "What is the capital of France?"

query_vector = embed(query)

documents = vector_search(query_vector, top_k=5)

context = combine(documents)

response = model.generate(
    prompt=query,
    context=context
)

The important idea is not the specific framework API. The application first retrieves relevant information and then provides that information to the model as context.

This example demonstrates how RAG integrates external information into a model’s context. Effective retrieval can provide the model with relevant evidence and may improve the quality and factual grounding of its responses. However, retrieval quality directly affects the final result, so RAG does not guarantee correct answers.

Introduction to AI Agents

AI agents are systems that use a model to determine what actions to take toward a goal, often by interacting with tools and using the results of previous actions. Unlike simple model calls, agent systems can dynamically control the flow of an application, using the results of previous actions to determine what should happen next.

Key Components of an Agent

  • Goal: The objective the agent is trying to achieve.
  • Model: The model used to reason about the current situation and determine the next action.
  • Tools: Capabilities exposed to the agent, such as searching the web, reading files, calling an API, or updating a database.
  • State: Information about the current progress and results of previous steps that the system needs to continue execution.
  • Example Agent Workflow

    Consider an agent that writes a blog post:

    Goal: Publish technical blog
              ↓
      Read available sources
              ↓
     Model determines next action
              ↓
       ┌──────┴───────┐
       │              │
    Need more info   Enough context
       │              │
    Read more      Generate draft
       │              │
       └──────→    Evaluate
                      ↓
                ┌─────┴─────┐
                │           │
              Revise       Good
                │           │
                └──→ Evaluate
                            ↓
                          Upload

    Unlike a fixed workflow, the agent can determine whether it needs more information, whether the draft needs revision, or whether it is ready to be uploaded.

    Each step may involve calling a tool, such as read_markdown() or upload_blog(). The model can determine which tool should be called next based on the available tools and the current state. The application then validates and executes the requested tool and provides the result back to the model.

    Agent vs. Fixed Workflow

    Fixed workflows follow a predefined sequence of steps, which can make them easier to test, debug, and control. Agents introduce more dynamic behavior by allowing the model to determine which action to take next based on the current state and available tools. This flexibility can make agents useful for less predictable tasks, but it also introduces additional complexity and failure modes.

    Combining RAG and Agents

    RAG and agents solve different problems but can work together to build powerful AI applications.

    RAG provides relevant information; agents determine and execute actions.

  • RAG provides relevant information that can be used as context by the agent or the model.
  • The agent controls the dynamic execution flow by determining which actions or tools to use based on the current state.
  • Example: Education Assistant with RAG and Agents

    An education assistant might work like this:

    Student question
          ↓
    Agent
          ↓
    Retrieve learning material (RAG)
          ↓
    Generate explanation
          ↓
    Create practice questions
          ↓
    Evaluate answers
          ↓
    Determine next activity

    In this example, the agent uses RAG to find relevant learning material and then uses that information to generate explanations and practice questions. The agent controls the flow of the interaction and can use information about the student’s current task or previous results to determine the next activity.

    Challenges in RAG and Agents

    Both RAG and agents can fail in ways that simple model calls cannot.

  • RAG failures can occur when the retrieval step returns irrelevant, incomplete, outdated, or poorly structured information.
  • Agent failures can include repeated or unnecessary tool calls, incorrect tool usage, getting stuck in execution loops, or performing actions outside the intended scope.
  • To reduce these risks, agent systems should set clear boundaries, restrict available tools, validate tool inputs and outputs, and define limits on execution.

    Retrieval Quality

    A RAG system is only as useful as the information it retrieves.

    Two important concepts are recall and precision:

    Recall: How much of the relevant information was successfully retrieved.

    Precision: How much of the retrieved information is actually relevant.

    A system might retrieve many documents and achieve high recall, but if many of them are irrelevant, the model may receive noisy context and have more difficulty identifying the useful information.

    A common approach is to retrieve a larger set of candidates and then use a reranker to identify the most relevant documents before sending them to the model.

    Query
      ↓
    Retrieve 20 documents
      ↓
    Rerank
      ↓
    Select best 5
      ↓
    Model

    This retrieval-and-reranking process can improve the quality of the context provided to the model.

    Conclusion

    RAG and agents are two powerful patterns for building advanced AI applications. RAG enhances a model’s ability to perform tasks using relevant external knowledge, while agents enable dynamic decision-making and control flow in applications.

    By combining these two patterns, we can build AI systems that have access to relevant external information while also being capable of performing multi-step tasks and interacting with external tools. Understanding RAG and agents is valuable for AI engineers building real-world applications that need external knowledge, multi-step execution, or interaction with external systems.

    #GenerativeAI#ComputerScience#AgenticAI#AI#AIEngineeringJourney#SoftwareEngineering#InformationRetrieval#AIArchitecture#ArtificialIntelligence#AIEngineer#Embeddings#AIWorkflows#AIEngineering#SemanticSearch#AIDevelopment#RAG#VectorSearch#TechLearning#Reranking#ToolCalling#AIApplications#AIAgents#RetrievalAugmentedGeneration#LLM
    LAMBDA BRICKS