Generative AI: LLMs, prompts, RAG, and AI agents
Back to the AI-901 path
AI-901Chapter 2

Microsoft AI-901 Certification Study

Generative AI: LLMs, prompts, RAG, and AI agents

Tokenization, transformers, embeddings, attention, completion generation, prompt engineering, and multi-agent systems

Suggested study time: 32 minutes • Beginner level • Original rewrite based on Microsoft Learn objectives

Neon Microsoft Certified AI-901 Azure AI Fundamentals shield surrounded by generative AI, vision, speech, cloud, and agent symbols

1. Introduction to generative AI

Learning objectives

  • Explain how large and small language models represent linguistic and semantic relationships.
  • Describe tokenization, vectors, embeddings, attention, encoders, decoders, and completion prediction.
  • Distinguish system and user prompts and apply history, RAG, and effective prompting practices.
  • Identify the components of AI agents and collaboration in multi-agent systems.

Generative AI has become highly visible because it can create original material that resembles human work, including poetry, prose, images, and code. The result can feel extraordinary, but it comes from mathematical methods refined over many years of research in statistics, data science, and machine learning.

A high-level understanding makes today’s technology easier to evaluate and helps reveal future possibilities. It also explains how generative models support a new generation of agents that can find information, choose next steps, and carry out tasks.

The original Microsoft Learn material can be completed through video or through text and images. The written version generally contains more detail and can supplement the video presentation.

2. Language models and completion prediction

Large language models, or LLMs, and their more compact relatives, small language models, or SLMs, encode relationships among words, passages, and meanings in a vocabulary. Those relationships support reasoning over natural-language input and the generation of coherent, relevant responses.

Fundamentally, training teaches a model to complete sequences that begin with a prompt. It resembles predictive text on a phone, but at a far larger scale: at each step, the model considers what has appeared, estimates which elements most influence the continuation, and chooses a likely next token.

In “I heard a dog...”, for example, “heard” suggests that a sound will follow, while “dog” points toward sounds associated with that animal. A person predicts “bark” because they have a vocabulary, understand language structure, and connect words to concepts. Training aims to give the model comparable capabilities.

Foundations of linguistic prediction.
FoundationContribution
Large vocabularyProvides many possible units for a continuation.
Linguistic structureRepresents ordering patterns and relationships that form meaningful sentences.
SemanticsConnects words and passages with concepts, contexts, and similar uses.

3. Tokenization: from text to identifiers

The first step is to build a very large vocabulary from extensive training corpora, including public Internet content and other sources. Current models may work with hundreds of thousands of tokens.

A token is not limited to a whole word. The vocabulary can also contain subwords, punctuation, and common character sequences. A prefix such as “un” in “unbelievable” can therefore be its own unit. Every distinct token receives a unique integer ID, and repeated occurrences reuse that identifier.

Simplified word-level tokenization.
TokenID
I1
heard2
a3
dog4
bark5
loudly6
at7
cat8

This teaching example uses whole words for readability. A production model also includes subwords and punctuation, and its vocabulary grows as more training material is processed.

4. Transformer: encoder, attention, and decoder

IDs alone do not express meaning. Each token first receives a vector, which is an array of numbers. A transformer converts these initial vectors into representations containing linguistic and semantic properties. Because those properties are embedded in the vectors, the results are called embeddings.

A simplified view divides a transformer into two blocks. The encoder creates embeddings with attention: it examines a token in the context of neighboring tokens, assigns influence weights, and passes the result through a fully connected neural network. Multi-head attention evaluates several characteristics in parallel to make the process more efficient.

The decoder uses the embeddings to estimate the next token in a prompt-started sequence. It also combines attention with a feed-forward network. The real architecture is more elaborate; the key idea is that attention captures token characteristics from the contexts in which tokens occur.

Flow from tokens through encoder, embeddings, decoder, and next-token prediction.
The SVG redraws the conceptual architecture: tokens and position enter the encoder, embeddings provide context, and the decoder predicts a continuation.

5. Position, attention, and embeddings

Before training, token-vector values may start randomly. They enter the model together with positional encoding because sequence order changes meaning and token relationships. A teaching table might use only three dimensions, while real model vectors contain thousands of elements.

During training, attention evaluates every token in context. In “I heard a dog bark,” “heard” and “dog” influence “bark” more strongly than articles or pronouns. The model does not know those weights initially; repeated exposure to large text collections reveals proximity and frequency patterns, and its parameters are adjusted iteratively.

The result is a vector space where tokens used in similar settings point in similar directions. Embeddings for “dog,” “puppy,” and “cat” are likely to be closer than those for “car” or “skateboard.” Cosine similarity provides a mathematical measure of this semantic proximity.

Simplified view of embeddings in vector space.
Semantically related vectors point in similar directions; a real model uses far more than three dimensions.

6. How the decoder generates a completion

Once embeddings represent contextual relationships, the decoder can predict a continuation one token at a time. During training it uses masked attention: when predicting a position, the model can consider only preceding tokens and ignores everything after it.

Because the correct sequence is known during training, the prediction can be compared with the actual next token. The error guides weight adjustments in later iterations. During generation, the next token is unknown; attention and the feed-forward network score candidates, the selected token is appended, and the cycle repeats until the model predicts an ending.

Given “When my dog was a...,” context makes “puppy” more likely than “cat” or “skateboard.” The full output emerges from repeatedly conditioning each prediction on everything generated so far.

7. System prompts and user prompts

A prompt is the input sent to an LLM to obtain a completion. It may be a question, a command, or a casual remark that starts a conversation.

The two main prompt types.
TypeResponsibilityReworded example
System promptSets behavior, tone, role, and persistent constraints.Act as a helpful assistant and respond in a friendly manner.
User promptRequests an answer to a specific question or instruction.Summarize generative AI adoption points for an executive in no more than six professional bullets.

The application usually supplies the system prompt. A user prompt may be written by a person in a chat or generated by the application on that person’s behalf. The response should address the specific request while following the overall guidance.

System and user prompts flowing into a language model.
The system establishes global rules; the user provides the task that produces a completion.

8. Conversation history and RAG

Conversational applications often retain history and include summarized versions of earlier turns in later prompts. This preserves continuity and lets the model understand a follow-up such as “What are the privacy risks?” after discussing corporate generative AI adoption.

Summarized history preserving conversational context.
Earlier messages and the follow-up form context that supports a coherent answer.

Retrieval-augmented generation, or RAG, adds external context. The application searches documents, email, or other sources, selects relevant passages, and inserts them into the prompt. The answer is then grounded in retrieved information rather than relying only on the model’s general knowledge.

An expense assistant might receive a question about the business-travel allowance, search the company policy, retrieve the relevant section, and send it with the question. Without retrieval, a model would probably offer generic advice to consult the policy; with RAG, it can answer from the organization’s actual rules.

RAG flow from question and document retrieval to an augmented prompt and grounded answer.
RAG connects a question to relevant sources and grounds the model’s completion.

9. Writing better prompts

Response quality depends on both the selected model and the instructions it receives. A well-designed prompt reduces ambiguity and explicitly communicates the desired outcome.

  • Be clear and specific: express the question or task without vague wording.
  • Add context: state the subject, audience, goal, and required format.
  • Provide examples when a particular style or pattern should be followed.
  • Ask for structure: request bullets, tables, numbered steps, or another useful layout.
Four recommendations for better prompts.
Clarity, context, examples, and structure make an instruction easier to follow.

10. AI agents and multi-agent systems

An AI agent is a generative-AI application that does more than answer. It reasons over natural language, uses tools, considers contextual conditions, and performs an appropriate action on a user’s behalf.

The three elements of an agent.
ElementPurpose
Large language modelProvides the core language understanding and reasoning capability.
InstructionsA system prompt describes the agent’s role, behavior, and boundaries.
ToolsKnowledge tools access search and databases; action tools send email, update calendars, or control devices.
Language model, instructions, and tools assembled into an AI agent.
Together, the three components let an assistant turn context into a controlled action.

Agents can also collaborate. In a multi-agent system, each participant has a specialty: one gathers data, another analyzes it, and a third takes action. They exchange prompts to determine required work, assign responsibility, and share results, creating a workflow that can handle more complex processes.

Multi-agent system with data-gathering, analysis, and action specialists.
Prompt-based coordination divides a complex workflow among specialized agents.

11. Hands-on exploration and knowledge check

The module exercise uses a chat playground to interact with a generative model and observe the practical effects of system prompts, tools, and grounding with data.

Original screenshot of the chat playground used in the generative AI exercise.
The real interface capture is preserved as a PNG in accordance with the screenshot rule.

Reworded questions

  1. Which option describes an LLM: a model that produces human-like text, an image-only model, or a small mobile model?
  2. What is tokenization for: sorting words, breaking text into smaller units, or directly converting a message to binary?
  3. What are embeddings: extra words, task-specific SLMs, or vector representations of tokens that capture meaning?
  4. What does attention do: delete words, assess relationships among nearby tokens, or filter inappropriate content?
  5. What is a system prompt for: providing context and instructions, selecting an operating system, or storing preferences?
  6. In AI, what is an agent: a system that performs tasks for a user, a secret model, or a human escalation operator?

Answer key

  • An LLM is an AI model designed to understand and generate human-like text.
  • Tokenization divides text into smaller units that receive identifiers.
  • Embeddings are vector representations that incorporate semantic and contextual properties.
  • Attention examines how each token relates to and is influenced by surrounding tokens.
  • A system prompt provides the model’s overall context, behavior, and constraints.
  • An agent is an AI system that can use tools and perform tasks on behalf of a user.

12. Chapter summary

  • LLMs and SLMs learn linguistic and semantic relationships to predict completions.
  • Tokenization creates identified units; transformers convert initial vectors into contextual embeddings.
  • Attention, positional encoding, and vector similarity represent context and semantic proximity.
  • A decoder uses masked attention and generates output iteratively, one token at a time.
  • System and user prompts, conversation history, and RAG control behavior and supply context.
  • Agents combine a model, instructions, and tools; multi-agent systems divide complex workflows among specialists.