Cyber For AI Notes

[Lecture] Components of LLMs, RAG and Agents

Base LLM, Instruction tuned LLM, Reinforcement Learning. RAG systems and agents

June 19, 2026

LLM Training Stages

Base LLM

A base model is trained solely to predict the next token. It has no ability to answer questions or follow instructions — it simply continues text based on patterns learned during training.

Instruction-Tuned LLM

Fine-tuning transforms the base model into one that can answer questions, follow instructions, and behave helpfully toward users.

Reinforcement Learning from Human Feedback (RLHF)

Human evaluators compare multiple model responses and select the preferred one, reinforcing better behaviour over time.

LLMs create an illusion of thought — but underlying everything is just mathematics.


Retrieval Augmented Generation (RAG)

RAG allows an LLM to answer questions using external data it was not trained on. The process works as follows:

  1. Source data is broken down into smaller chunks.
  2. Each chunk is converted into a vector using an embedding model.
  3. The vectors are stored in a vector database.
  4. When a user submits a prompt, it is also vectorised and compared against the database.
  5. Semantically similar chunks are retrieved via semantic search.
  6. The LLM combines the original prompt with the retrieved data to generate a response.

Example RAG pipeline

image


Challenges of Building AI Agents

Control (Non-Determinism)

Agent behaviour is inherently unpredictable. Small hallucinations can propagate through subsequent steps and be treated as fact, compounding errors over time.

Latency and User Experience

Reasoning-heavy tasks consume large numbers of tokens. Poorly designed agents can fall into infinite loops, leading to excessive token usage and degraded performance.

Context and Memory

Agent memory is limited and fragile. Polluted conversation history can corrupt the agent's understanding and negatively affect its outputs.

Safety and Security

Agents operating autonomously introduce risks that must be proactively

Agent-User log demo

image