Summary
This course explores the engineering aspects of turning AI models into dependable products. It covers building agents that can plan, use tools, and remember, connecting them to external data and systems via tool calling and MCP. It delves into retrieval augmented generation (RAG) for document-based knowledge, discussing chunking, retrieval failures, and advanced RAG techniques like hybrid search and re-ranking. The course also examines knowledge graphs for connected data, agentic RAG for dynamic searching, and the importance of a living knowledge base. Finally, it addresses model behavior, training data best practices, fine-tuning, and the underlying hardware, emphasizing the need for robust systems around the model for production deployment.
Key Insights
Agents differ from chatbots by working towards a goal and taking actions.
A chatbot answers a question and stops. An agent is given a goal, works through a task, uses tools when necessary, observes outcomes, and decides on subsequent actions. This involves a loop of decision, action, and observation, distinguishing it from simple conversational AI.
Agent memory is crucial for task continuity and is built using short-term, episodic, semantic, and procedural types.
Models don't retain memory between requests; systems must build it. Short-term memory is the current context. Episodic memory logs past events. Semantic memory stores facts, and procedural memory stores 'how-to' knowledge.
The 'lost in the middle' problem means models struggle to use information buried deep in long contexts.
Models perform better with information at the start and end of their context window, while details in the middle are often ignored or misinterpreted, even with larger context windows.
Model Context Protocol (MCP) standardizes AI app connections to tools and data.
MCP acts like shipping containers for AI, providing a standard way for AI applications (hosts) to discover and interact with services (servers) offering tools, resources, and prompts, simplifying integration across an organization.
Clear roles, boundaries, and permissions are vital for multi-agent system integrity.
When agents share tasks, defining each agent's specific job, its limitations (what it must not do), its place in the workflow, and its permissions prevents conflicting or erroneous behaviors.
A living knowledge base requires continuous management: versioning, ownership, deletion, and review.
Maintaining current and accurate information involves treating knowledge like code: managing versions, assigning owners, properly retiring old data, tracking provenance, enforcing access rules, and reviewing proposed changes.
Model behavior originates from training data, goals, and the training process itself.
Unlike traditional code, AI models learn their behavior heavily from the data they are trained on, the objectives they are optimized for, and the specific methods used during training.
Training data requires rigorous pipeline management: source, collection, cleaning, labeling, splitting, and versioning.
Careful curation is essential to avoid issues like data leakage, outdated content, skew, and mixed definitions. Proper versioning and lineage tracking are critical for reproducibility and debugging.
Sections
Introduction to AI Systems Engineering
Building AI products requires engineering around the model, not just the model itself.
Turning an AI model into a product people depend on daily involves building significant engineering infrastructure around it, which is the focus of this course. This includes agents, connections to external data, knowledge bases, hardware, and production deployment strategies. The goal is to enable technical leaders to read and understand AI architecture diagrams and ask informed questions.
Agents differ from chatbots by working towards a goal and taking actions.
A chatbot answers a question and stops. An agent is given a goal, works through a task, uses tools when necessary, observes outcomes, and decides on subsequent actions. This involves a loop of decision, action, and observation, distinguishing it from simple conversational AI.
The agentic loop involves decision, action, observation, and re-decision.
The core of an agent's operation is a loop where it reasons about what to do, takes an action (often using a tool), observes the result, and then reasons again about the next step. This contrasts with a fixed workflow where steps are pre-defined.
Key questions for identifying an agent include action-taking and adaptive step selection.
To identify an agent, ask: Does it take real actions or only write text? Does the model choose the next step dynamically? Does it observe results and change course? If all answers are yes, it's likely an agent.
Core Components of an Agent
Agents comprise core subsystems like perception, reasoning, action, learning, and communication.
These capabilities manifest as concrete components: the model itself, tools for interacting with external systems, memory for retaining information, a control loop to manage the agentic process, and permissions governing access.
Perception involves understanding inputs, similar to grounding but focused on interpretation.
Perception is how an agent interprets its input, understanding the meaning of data beyond just reading it. Grounding ties the agent's output to specific retrieved data, preventing pure guesswork.
Reasoning involves breaking down complex goals and routing requests to appropriate models.
Reasoning allows an agent to decompose large tasks into smaller steps and to select the best model (e.g., smaller/cheaper or larger/more capable) for each sub-task, a process known as routing.
Action components require careful handling to manage real-world consequences and potential errors.
Action involves executing tasks in the real world. A layer between the model's request and the system ensures correct formatting, handles errors gracefully, and can pause for human approval on irreversible actions.
Runtime adaptation (learning) uses past experiences to improve future performance without retraining the model.
This form of learning, often called reflection or reusing successful procedures as 'skills', allows the agent to adapt based on its task history rather than altering the model's core weights.
Communication enables agents to work with humans and other agents, requiring careful context transfer.
Effective communication involves handing off work and results between agents or to humans, ensuring sufficient context is provided for the next participant to continue the task.
Multi-Agent Systems and Memory
Splitting complex tasks among multiple agents mirrors specialized human teams.
Just as home repairs require different specialists, complex AI tasks benefit from multiple agents, each with a specific role and decision-making loop, rather than a single agent burdened with all steps.
Multi-agent systems allow for parallel processing and focused context but increase complexity and cost.
While multiple agents can handle parts of a job concurrently, improving focus and potentially speed, they introduce challenges in coordination, context transfer, cost management, and debugging.
Agent memory is crucial for task continuity and is built using short-term, episodic, semantic, and procedural types.
Models don't retain memory between requests; systems must build it. Short-term memory is the current context. Episodic memory logs past events. Semantic memory stores facts, and procedural memory stores 'how-to' knowledge.
Context is what's actively used in a model call, distinct from the total stored memory.
An agent can store vast amounts of information, but only a relevant subset is placed into the model's context for any given step.
The 'lost in the middle' problem means models struggle to use information buried deep in long contexts.
Models perform better with information at the start and end of their context window, while details in the middle are often ignored or misinterpreted, even with larger context windows.
Managing context involves prioritizing key information and keeping it ordered near the start or end.
Strategies to combat 'lost in the middle' include minimizing context to only what's needed for the current step, strategically ordering important information, and repeating key instructions.
Connecting Agents to the World: Tool Calling and MCP
Tool calling enables models to request actions by normal software via structured descriptions.
Models don't execute actions directly; they generate structured requests for 'tools' (pieces of software). Developers describe tools with names, explanations, and input schemas, which the model uses to formulate requests.
A control loop validates tool requests, enforces permissions, and executes actions.
The control loop, written by engineers, checks the model's tool requests for validity, authorization, and sensible values before executing the actual software function, handling results or errors.
Safe action execution requires validation, error handling, and human oversight for critical tasks.
Robust systems include unique identifiers for requests to prevent duplicates, retry limits, and mechanisms to pause for human approval on high-stakes actions like large refunds.
Traces are crucial for debugging by recording every tool call, its inputs, outputs, and costs.
Detailed logs (traces) of every step in an agent's process are essential for diagnosing failures, whether they originate from the model, the control loop, or external systems.
An excessive number of tools can degrade agent performance due to context bloat and selection errors.
More tools mean more descriptions in the model's context, increasing costs and the likelihood of incorrect tool selection, often leading to 'context rot'. A few well-defined tools are usually better than many.
Model Context Protocol (MCP) standardizes AI app connections to tools and data.
MCP acts like shipping containers for AI, providing a standard way for AI applications (hosts) to discover and interact with services (servers) offering tools, resources, and prompts, simplifying integration across an organization.
Agent skills encapsulate repeatable task know-how, loading instructions progressively.
Skills provide structured instructions for complex tasks, loading details only as needed ('progressive disclosure'), avoiding context bloat from numerous tools and providing reusable procedures.
Clear roles, boundaries, and permissions are vital for multi-agent system integrity.
When agents share tasks, defining each agent's specific job, its limitations (what it must not do), its place in the workflow, and its permissions prevents conflicting or erroneous behaviors.
An AI gateway centralizes model calls for cost control, security, and routing.
An AI gateway acts as a single point of entry for all model requests, managing identity, budget, content checks, model selection, provider failover, and detailed cost/usage tracing.
Knowledge Retrieval: RAG and Beyond
Retrieval Augmented Generation (RAG) adds relevant document text to prompts for grounded answers.
Before answering, RAG systems search documents, chunking and embedding them, then adding the closest matches to the model's context as evidence, improving accuracy over relying solely on training data.
Common RAG failures include poor chunking, irrelevant matches, missed exact terms, and context burial.
Failures occur before the model acts: text splitting rules break rules from exceptions, meaning-based search finds similar but wrong text, product codes are missed, and vital info is lost in long contexts.
Debugging RAG involves tracing the retrieval path, not just blaming the model.
When answers are wrong, inspect the retrieval process: check data freshness, chunking, search relevance, ranking, and context inclusion before assuming the model erred.
Advanced RAG techniques address specific failures: hybrid search for exact terms, reranking for better matches.
Techniques like hybrid retrieval combine meaning and keyword searches, while reranking refines initial broad results for better precision. Corrective RAG (Crag) and self-reflection improve evidence evaluation.
Knowledge graphs store explicit relationships, enabling retrieval of connected facts.
Graphs use nodes and links to represent entities and their relationships, allowing systems to follow chains of information that simple text search cannot easily traverse.
Agentic RAG empowers agents to dynamically choose search strategies and tools.
Instead of a fixed pipeline, agents use search tools like any other tool, deciding when to search, where to search, and when to stop based on intermediate results.
A living knowledge base requires continuous management: versioning, ownership, deletion, and review.
Maintaining current and accurate information involves treating knowledge like code: managing versions, assigning owners, properly retiring old data, tracking provenance, enforcing access rules, and reviewing proposed changes.
Model Behavior and Training
Model behavior originates from training data, goals, and the training process itself.
Unlike traditional code, AI models learn their behavior heavily from the data they are trained on, the objectives they are optimized for, and the specific methods used during training.
Training data requires rigorous pipeline management: source, collection, cleaning, labeling, splitting, and versioning.
Careful curation is essential to avoid issues like data leakage, outdated content, skew, and mixed definitions. Proper versioning and lineage tracking are critical for reproducibility and debugging.
Data leakage, outdated content, skew, and mixed definitions are common pitfalls in training data.
These issues can lead to inflated performance scores, models that use incorrect information, poor generalization, and inconsistent behavior, highlighting the need for meticulous data handling.
Model drift occurs when real-world data diverges from training data over time.
As the world changes, models trained on older data may become less effective. Continuous monitoring and retraining on fresh data are necessary to combat this quiet decay in performance.
Ask a Question
*Uses 1 Wisdom coin from your coin balance









