DEV Community

Cover image for AI Agents aren't magic
patrick0806
patrick0806

Posted on

AI Agents aren't magic

Today, I think all areas, especially IT, are becoming involved with AI. Right now, I think the term I hear most often is AI Agent. For non-technical people, it may seem like it's just the .md files we generate with Claude Code CLI, Codex, and similar tools. But as a engenier or dev, I think it's worth looking a little deeper into what an AI agent actually is.

We know it isn't magic. An AI agent is essentially a LLM combined with orchestration, context, and tools that let it perform actions beyond generating text.

To summarize the "magic" behind tools like Claude Code, you can think of them as a loop. As programmers, imagine something like:

while (true) {
    const response = llm(messages)

    if (response.toolCall) {
        result = executeTool()
        messages.push(result)
        continue
    }

    return response
}
Enter fullscreen mode Exit fullscreen mode

After that, behind the scenes, we add context and provide the model with information about the available tools. I emphasize the tools because an LLM can't do anything other than generate text (tokens). We give it capabilities through predefined "contracts." Conceptually, it's like telling the model:

{
  "action": "tool_call",
  "tool": "tool_name",
  "args": {}
}
Enter fullscreen mode Exit fullscreen mode

If the model responds using the expected structure, our loop invokes the corresponding tool. The function execution is what actually performs the action the model selected to answer your request.
Modern APIs usually expose native tool calling, but conceptually this is what's happening under the hood.

Of course, modern agents involve much more than this. They also include context management, memory, execution limits, retries, guardrails, planning, and support for multiple tool calls. I'm simplifying the architecture to focus on the core idea.

This can sound quite abstract, so I built a small AI agent using TypeScript and Node.js. The repository is here:

https://github.com/patrick0806/Simple-Agent

It has three main files:

  • tools.ts: Contains the tools. Their implementations give the agent the ability to interact with the real world.

  • guardrails.ts: Contains the safeguards. Here we define prompts and validation logic.

  • index.ts: Contains the main agent loop, where I connect to Ollama, receive user prompts, invoke tools, and orchestrate the entire workflow.

This is just a showcase project with simple implementation its not for work or anything like that, its more to see the raw implementation about how a Agent is started to build and how this works

Top comments (1)

Collapse
 
marcusykim profile image
Marcus Kim

The simple loop is a helpful way to demystify agents: the model proposes a tool call, but the real action happens in the function behind that contract. Splitting the sample into tools.ts, guardrails.ts, and index.ts also makes the boundaries clearer, especially with Ollama handling prompts while the loop manages orchestration. The founder/engineer lesson is that the hard part shifts from prompting to product control: tight tool permissions, retry limits, validation, and clear failure behavior matter more than making the agent sound clever.