RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Introduction to AI Agents
  6. /Ch. 1
Introduction to AI Agents

01. What is an AI Agent?

Chapter 1 of 16 · 15 min
KEY INSIGHT

An AI agent is an LLM running inside a reasoning-action loop, extending itself with tools to gather information and act in the real world.

An AI agent is a system where a language model actively decides which actions to take, executes those actions, and uses the results to inform the next decision. Unlike a chatbot that responds once to a single prompt, an agent operates in a loop. It observes state, reasons about what to do next, calls external tools, receives results, and repeats until the task is complete.

The key components are three: an LLM that functions as the brain, a set of tools that extend what the model can do, and a loop that ties reasoning to action. This architecture covers everything from simple calculator-wielding bots to complex multi-agent pipelines.

The core loop

The minimal agent loop looks like this:

  1. Receive a task from the user
  2. The LLM decides whether to call a tool or respond directly
  3. Execute the tool and return results to the LLM
  4. Repeat until the LLM signals completion

This is called the "agent loop," and it is the foundation every agent framework builds on.

Agents vs. chain prompting

You might wonder: why not just use chain-of-thought prompting to get everything done in one shot? The answer is that complex tasks require information the model does not have at inference time. The model cannot know current weather, private file contents, or real-time numbers without calling tools to fetch them. Agents solve this data problem by combining reasoning with retrieval.

A minimal example

def agent_loop(model, tools, user_message, max_turns=10):
    messages = [{"role": "user", "content": user_message}]
    
    for turn in range(max_turns):
        response = model.chat(messages, tools=tools)
        
        if not response.tool_calls:
            return response.content
        
        for call in response.tool_calls:
            result = tools[call.name](**call.arguments)
            messages.append({"role": "assistant", "content": response.content,
                             "tool_calls": [call]})
            messages.append({"role": "tool", "tool_call_id": call.id,
                             "content": str(result)})
    
    return "Max turns reached"

The code above shows the pattern without any framework. The LLM responds with either text or a tool_calls field. Each tool call returns a result that gets appended back to the message history as a tool role message.

Failure modes

The most common failure is the LLM calling a tool that does not exist or passing arguments that do not match the schema. Set a hard limit on turns to prevent infinite loops. Watch for models that refuse to use tools at all—this usually means the system prompt failed to explain the tool availability clearly.

EXERCISE

Run the minimal agent loop with a dummy tool that returns a fixed string. Verify that the model correctly identifies when to call the tool versus when to answer directly.

← Overview
Introduction to AI Agents
Chapter 2 →
Agent Architecture