Build an AI Agent from Scratch

Scott Moss

Scott Moss

Superfilter AI
4 hours, 7 minutes CC
Build an AI Agent from Scratch

Course Description

Create your own AI agent! Build a command line messaging interface and an agent loop to continuously interact with the user. Code tools from scratch for retrieving information and generating images from Dahl-E. Manage the chat history to provide context with each prompt. Learn the bleeding-edge design patterns and resources for building modern agent-based API apps.

This course and others like it are available as part of our Frontend Masters video subscription.

Preview
Close

Course Details

Published: December 10, 2024

Learning Paths

Learn Straight from the Experts Who Shape the Modern Web

Your Path to Senior Developer and Beyond
  • 200+ In-depth courses
  • 18 Learning Paths
  • Industry Leading Experts
  • Live Interactive Workshops
Get Unlimited Access Now

Table of Contents

Introduction

Section Duration: 15 minutes
  • Introduction
    Scott Moss introduces the course by discussing the prerequisites, which include knowledge of JavaScript and familiarity with APIs. He also provides technical setup instructions, such as installing Git and Node, and signing up for an AI API account. - Course Website: https://clumsy-humor-894.notion.site/Agent-from-scratch-13554fed51a380749554c44aa8989406 - Course Repo: https://github.com/Hendrixer/agent-from-scratch
  • AI Agents Overview
    Scott provides an overview of the course project which is an agent that can read from Reddit, generate images, and provide random dad jokes. He also discusses different types of agents, such as conversational agents and transactional agents, and provides examples of their use cases.

LLM Overview

Section Duration: 30 minutes
  • LLMs Overview
    Scott explains what a large language model (LLM) is and how it differs from other AI models. He also introduces the idea of transformers and tokenization and token limits in LLMs.
  • Types of LLMs Overview
    Scott discusses different types of LLMs such as GPT, Claude, and Llama. He explains the concept of weights in AI models and how they are essential for the model's functionality. Scott also mentions the limitations of LLMs, including hallucinations and context window constraints.
  • OpenAI Hello World
    Scott walks through setting up the environment for using OpenAI's API and demonstrates how to make a simple API call to generate a response. He also explains the parameters used in the API call, such as the model and temperature, and shows how to handle the response.

Memory

Section Duration: 42 minutes
  • AI Chat with Memory Overview
    Scott explains that one-off LLM calls are suitable for standalone tasks, while chat-based interactions are used for maintaining conversation history and context. Scott also mentions the importance of managing history and tokens in chat-based LLM interactions.
  • Chat Memory Message Types
    Scott discusses memory in a chat application, which is a collection of previous messages in a conversation. He also covers the different types of messages, including system messages, user messages, assistant messages, and tool messages.
  • Memory & Token Limitations
    Scott discusses the importance of memory in AI systems and how it enables follow-up capabilities and task continuity. He also explains the limitations of memory in language models and different strategies for managing memory constraints. Scott also mentions the concept of retrieval-augmented generation (RAG) and its potential to improve memory and context in AI systems.
  • Building an AI Chat with Memory
    Scott explains how to implement a memory feature in a chat application using a file-based database. He demonstrates how to add and remove metadata from messages and create functions to add and get messages from the database. He also shows how to integrate the memory feature into the chat interface by retrieving previous messages and passing them to the LLM.

AI Agents

Section Duration: 49 minutes
  • Types of AI Agents
    Scott provides examples of different types of agents, including chat-based agents and task-based agents. He discusses the characteristics of agents, such as autonomous decision-making, task persistence, and goal orientation. He also addresses questions from students regarding validating LLM responses and the potential impact of larger AI models on specialized agents.
  • Building an AI Agent
    Scott demonstrates how to add a user message to the database, show a loader, get all the messages, run the LLM with the messages and tools, and add the response to the chat messages. Scott also discusses how to handle tool calls and provides an example of creating a fake tool called "get weather" and passing it to the agent.
  • Building an AI Agent Q&A
    Scott discusses the importance of sending messages in a certain order to prevent the AI from erroring. He also explains how to use the Zod function to describe the purpose of a tool and how to add reasoning to improve the AI's decision-making process. Scott also mentions the use of token counting to manage token limits and the option to set a maximum number of tokens for the response.

Function Calling

Section Duration: 30 minutes
  • Function Calling Overview
    Scott discusses how to handle security when a user is using a tool that may access other users' data. Scott also provides examples of clear and ambiguous matches in tool calling and emphasizes the importance of clear descriptions for tools.
  • Creating a Tool Runner
    Scott demonstrates how to create a tool runner function that matches the tool call with the corresponding function and returns the result. He also shows how to save the tool response in the chat history and handle looping through tool calls.

Agent Loops

Section Duration: 20 minutes
  • Agent Loops Overview
    Scott discusses agent loops and how they allow the agent to feed the answer back to the LLM so it can answer the original question and provide a response. Scott also provides examples of multi-step actions and how to handle dependent actions within the loop.
  • Coding the AI Agent Loop
    Scott demonstrates how to use a while loop to continuously send messages to the model and receive responses until a specific condition is met. Scott also discusses the importance of saving and retrieving the conversation history within the loop.

Real Tools

Section Duration: 35 minutes

Next Level

Section Duration: 21 minutes
  • Improving Agents
    Scott discusses the concept of RAG (Retrieval-Augmented Generation) and embeddings, which are numerical representations of text. Scott also touches on topics such as human-in-a-loop, evaluation strategies, safety mechanisms, integration patterns, and specialized agents.
  • Improving Agents Q&A
    Scott answers student questions regarding recommended tools and resources, including Hugging Face and Brain Trust, and discusses the challenges and considerations when using AI services from providers like OpenAI, Azure, and AWS. The lesson concludes with a brief discussion on fine-tuning models and updating them as needed.

Wrapping Up

Section Duration: 1 minute

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now