🦥AI Agents For Dummies

Hello friends!

Welcome to this week’s Sloth Bytes. I hope you had an amazing week!

Latest Posts

If you’re new, or not yet a subscriber, or just plain missed it, here are some of our recent editions:

74% of Companies Are Seeing ROI from AI.

Incomplete data wastes time and stalls ROI. Bright Data connects your AI to real-time public web data so you launch faster, make confident decisions, and achieve real business growth.

How Do Agents Work?

AI agents are one of those things that companies love to make sound way more complicated than they are, but they’re honestly not that complicated.

It’s so simple that by the end of this newsletter, you'll understand the fundamentals and be able to build your own AI agent.

The Problem With LLMs

LLMs are great at things like understanding language and spotting patterns, but they’re not deterministic by default.

The response isn’t the same every time you ask the same question.

You may have heard of the “strawberry” problem, where users asked the most smart LLM models how many “r’s” are in the word “strawberry”.

AI models don't actually "see" letters the way we do. They work with tokens and probabilities. 

When you ask an LLM a question, it's basically predicting the most likely response based on patterns it learned during training.

Now compare that to a regular function in code that counts letters:

countLetters("strawberry", "r")

This is deterministic. The same input gives the same result every single time.

It’s nice, predictable, and boring, which is exactly what we want.

The problem: It can’t handle natural language like LLMs.

I can’t do something like this:

countLetters("how many r’s are in the word 'strawberry'”)

The function expects specific parameters: a word and a letter.

So now we have an interesting situation:

  • LLMs aren't deterministic, but can handle natural language

  • Code is deterministic, but can't handle natural language

So what if we could just combine them both? That would fix both problems.

This is where agents come in.

So what is an agent?

An Agent, specifically an LLM agent is an LLM equipped with tools.

The LLM can use these tools autonomously, meaning you don't need to tell it which tool to use (sometimes.)

If we had an agent equipped with our countLetters function, and we asked:

“How many r’s are in the word ‘strawberry?’”

The agent's flow may look something like this:

  • User: “How many r’s are in the word ‘strawberry’?”

  • LLM thinks: “Wow this is a tough one uhhhh. Do I have a tool for this? Ah, yes, yes, I do.”

    • It calls the countLetters tool with the word “strawberry” and “r” as parameters.

    • The tool returns 3

  • LLM: gets the output and says “seems about right.”

  • LLM: responds back to the user saying “The word "strawberry" has 3 'r's.”

Instead of trying to guess/predict it, it’ll use a tool that gives the same answer.

What is a tool?

Tools can be a lot of things. Web search tool, weather tool, flight tracking tool, etc.

But if we had to put them into categories it would be like this:

  • External tools: Code, APIs, image generation, etc

  • Memory tools: Databases, conversation history, etc

  • Planning tools: Usually the built in “reasoning” that LLMs have.

The quality of tools and the LLM's ability to use the right tool at the right time are sometimes more important than the LLM's intelligence.

Kind of like you and the internet:

  • Without the internet, you’re probably not that smart.

  • With the internet, it’s still questionable, but you’re smarter.

How does an Agent know when to call a tool?

An agent's ability to call the right tool at the right time depends largely on 3 main things.

1,. Tool & Parameter

If your tool description is vague, the LLM will struggle to use it.

Think of it as if you were reading a codebase and you see a function called doesSomething(a,b,c,d,e,f,g) with no comments. You'd be lost, right?

LLMs will have the same problem except it can't even read the actual code.

It only knows what you tell it in the description.

2. System Prompt

This tells the LLM who it is and what it's trying to accomplish.

A vague system prompt = wrong tools being used.

3. The Model

Most models are good at everything, but some models are specifically trained for tool calling, like OpenRouter's Exacto or Claude (which is why developers love it for coding).

Some agentic workflows even use one model just to decide whether to call a tool, and another model to actually do the work.

How To Build your Own Agent

Thanks to modern SDKs, creating an agent is way easier than it used to be.

We’ll use Vercel’s AI SDK since it’s extremely popular (with ~4 million weekly downloads on NPM) and very well documented.

Step 1: Define the tool

import { z } from "zod";
import { tool } from "ai";

const countLettersTool = tool({
  description: "Count how many times a given letter appears in a word or phrase.",
  inputSchema: z.object({
    letter: z
      .string()
      .min(1)
      .max(1)
      .describe("The single letter to count"),
    text: z.string().describe("The text to scan"),
  }),
  execute: async ({ letter, text }) => {
    const count = [...text].filter(char => {
      return char.toLowerCase() === letter.toLowerCase();
    }).length; // See I can code 💪

    return { count };
  },
});

What's happening here:

  1. Description - Tells the LLM what this tool does

  2. Input schema - Defines the parameters using Zod (ensures the LLM passes valid data):

    • letter: a single character

    • text: the text to search

  3. Execute function - The actual logic that runs on your machine and returns the result to the agent

Step 2: Give the LLM the tool

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

async function agent(prompt: string) {

  const result = await generateText({
    model: openai("gpt-5"),
    tools: {
      countLetters: countLettersTool,
      // We can add more tools if needed!
    },
    system: `
      You are a normal conversational chatbot.

      If the user ever asks something that requires deterministic logic (for example:
      counting letters, counting words, numeric checks, or anything where precision matters),
      call the appropriate tool instead of guessing.
    `,
    prompt,
   // This tells the AI how many loops of the tool to call (prevents infinite loops and saves your bank account.)
    stopWhen: stepCountIs(2)
  });
  
  return result;
}

Step 3: Use our cool agent

  const agentResponse = await agent(
    "How many r's are in the word 'strawberry'",
  );
  console.log(agentResponse.text);
  // The word "strawberry" has 3 'r's.

Boom, we technically have an “agent”.

It’s not exactly mind blowing, but our AI can now count letters in a word.

Add some more tools, throw in some buzzwords, and you got yourself an “agentic, multi-platform, B2B SaaS web3 AI-integrated crypto orchestration platform.”

BUT, how do we know that the AI actually called the tool and didn’t just make that up?

Well, we can actually inspect the steps that it took to reach its final output:

console.log(agentResponse.steps);

This would be the output:

{    "type": "tool-call",
    "toolName": "countLetters",
    "input": {
        "letter": "r",
        "text": "strawberry"
{
    "type": "tool-result",
    "toolName": "countLetters",
    "input": {
        "letter": "r",
        "text": "strawberry"
    },
    "output": {
        "count": 3

Looking at the steps here:

  1. The LLM called countLetters with { letter: "r", text: "strawberry" }

  2. Got back an output of { count: 3 }.

  3. Used that output to give the correct answer of “The word "strawberry" has 3 'r's.”

Here’s a visual on what exactly happened:

You’ll notice there’s a cycle there when it calls a tool and that’s the agentic part.

It repeats the cycle until it completes it’s goal or encounters an error.

It’s agentic since we don’t have to tell it anything.

Temperature

Even though the output of the tool is deterministic the final response still varies.

The LLM might say

  • "There are 3 r's in strawberry"

  • "There are three r's"

  • "The word contains three r's."

But now the core logic and answer is the same.

Just like how your coffee is never exactly the same twice, but it's still coffee.

This variation in responses can be controlled through a setting supported by some models called temperature. It’s basically a randomness setting.

  • Ranges from 0 -2

  • Lower temperature = more predictable.

  • Higher temperature = more creative (and chaotic).

For agents you should keep the temperature low at around 0 - 0.5, but you should always experiment with it for your agents.

Agents are pretty simple right?

Agents are just an AI with tools, so don’t be scared or worried that it’s something crazy. The hard part isn't understanding agents, it’s architecting how you want them to use the tools.

So get comfortable with them, because every company seems to be obsessed with agents right now.

Thanks to everyone who submitted!

One, Two, Skip a Few

Create a function which calculates how many numbers are missing from an ordered number line.

This number line starts at the first value of the array, and increases by 1 to the end of the number line, ending at the last value of the array.

Examples

howManyMissing([1, 2, 3, 8, 9])
output = 4
# The numbers missing from this line are 4, 5, 6, and 7.
# 4 numbers are missing.
howManyMissing([1, 3])
output = 1

howManyMissing([7, 10, 11, 12])
output = 2

howManyMissing([1, 3, 5, 7, 9, 11])
output = 5

howManyMissing([5, 6, 7, 8])
output = 0

Notes

If the number line is complete, or the array is empty, return 0.

How To Submit Answers

Reply with

  • A link to your solution (github, twitter, personal blog, portfolio, replit, etc)

  • or if you’re on the web version leave a comment!

  • If you want to be mentioned here, I’d prefer if you sent a GitHub link or Replit!

That’s all from me!

Have a great week, be safe, make good choices, and have fun coding.

If I made a mistake or you have any questions, feel free to comment below or reply to the email!

See you all next week.

What'd you think of today's email?

Login or Subscribe to participate in polls.

Want to advertise in Sloth Bytes?

If your company is interested in reaching an audience of developers and programming enthusiasts, you may want to advertise with us here.

Reply

or to participate.