Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Browse all series

So You Want to Build an Agent

You're likely using an AI agent every day at this point, but do you truly understand how it works under the hood? What separates an agent from a general chat? What's a tool? How do we provide the loop for executing these tools? In this series, we'll demystify some of these concepts by building a basic agent that is capable of interacting with your file system and triggering tools.

Progress

Series Info

Episodes
9
Run Time
1h 56m
Difficulty
Intermediate
Last Updated
Apr 16, 2026
Version
Latest

Series Episodes

  1. The Essentials (7)
    1. Your First AI Response

      Before we discuss agents, let's ensure that everyone is on the same page. We'll begin by building a simple command that sends a prompt to AI and prints its response.
    2. Have A Dialog

      In the previous episode, we captured the AI response...and that was the end of the conversation. To truly have a dialog, we should maintain and track the history.
    3. The Agent Loop

      A key component to an agent is the loop that drives it. I like to think of this loop as the agent's inner dialog. Let's discuss it!
    4. Extract A Tool Class

      The second piece of the agent puzzle is tooling. By default, of course an agent can't interact with your local filesystem. Instead, we must provide that functionality as a tool that the agent can be then request.
    5. Make a Revenue Tool

      A few episodes back we asked the AI about last quarter’s revenue, and, of course, it had no clue. Let's fix that by providing a Revenue tool that it can trigger.
    6. Structured Output

      Now that we have our basic agent loop working, we are going to tighten things up by introducing structured output so each agent can be forced to return the exact shape we expect.
    7. Filesystem Tools

      Let's review some of the core filesystem tools that any agent will require. This includes everything from executing Bash scripts, to reading files, to performing searches.
  2. Going Deeper (2)
    1. Compacting

      Welcome to section two! Now that you know the essentials, let's dig deeper. First up, we need to structure our conversation history in such as way so as to grow endlessly and wreck our context window.
    2. Load a Guidelines File

      Next, we should teach our agent how to pick up on project-level guidelines (think CLAUDE.md or AGENTS.md) and fold them into its instructions.

Continue Learning