Site icon Computer Software Today

What Are AI Agents? How They Work, Fail and Stay Safe

Yellow industrial robotic arm at work in a factory, symbolizing AI agents that take actions with tools

Photo by Freek Wolsink on Pexels

An AI agent is a language model running in a loop: it looks at a goal, picks a tool, runs it, reads the result and decides what to do next until the job is done. That simple loop powers today’s coding agents and business automations. Here is how agents actually work, where they break, and how to use them safely.

What is an AI agent, really?

An AI agent is a system where a language model decides its own next steps and calls tools to carry them out, rather than following a fixed script. The model is the brain; the tools are the hands; a loop keeps it going.

The word “agent” gets stretched to cover everything from a chatbot with a search box to a fully autonomous system, so a definition helps. Anthropic’s widely cited engineering post Building Effective Agents draws a useful line:

That distinction matters in practice. A workflow that classifies an email, then drafts a reply from a template, is predictable and easy to test. An agent told to “sort out this customer’s billing problem” might read three systems, issue a refund and email the customer, in an order nobody wrote down in advance. That flexibility is the whole point, and it is also the whole risk.

If you have used Claude Code, GitHub Copilot’s agent mode, OpenAI Codex or any similar tool to fix a bug across several files, you have already used an AI agent.

How does an AI agent actually work?

The core is a loop: send the goal and current context to the model, let it request a tool call, execute that call, append the result to the context, and repeat until the model says it is done or a limit is hit.

The agent loop: the model picks an action, guardrails check it, tools run it, and the result feeds the next decision.

Anthropic’s documentation for Claude Code describes the same loop in three phases: gather context, take action, verify results. For “fix the failing tests,” that means run the tests, read the error, search for the relevant files, read them, edit, then run the tests again. Each result feeds the next decision.

Stripped down, the code looks like this. It is pseudo-C#, but every agent framework is some version of it:

var messages = new List<Message> { System(instructions), User(goal) };

for (int step = 0; step < maxSteps; step++)
{
    var reply = await llm.CompleteAsync(messages, tools);
    messages.Add(reply);

    if (reply.ToolCalls.Count == 0)
        return reply.Text;                  // model says it's done

    foreach (var call in reply.ToolCalls)
    {
        if (!policy.IsAllowed(call))        // guardrail before the world
            { messages.Add(ToolResult(call.Id, "Denied by policy")); continue; }

        var result = await tools.ExecuteAsync(call);
        messages.Add(ToolResult(call.Id, result));
    }
}
throw new AgentBudgetExceededException(maxSteps);

Three things in that snippet do most of the real work: the tool definitions the model can see, the policy check before anything executes, and the step limit. The model itself is the easy part to plug in.

What tools can an AI agent use?

A tool is any function you describe to the model with a name, a description and a schema for its inputs. The model cannot run anything itself; it asks, and your code decides whether to execute.

Typical tools fall into a few groups:

Increasingly, tools come from Model Context Protocol (MCP) servers, a standard way to expose tools to any compatible agent instead of wiring each one by hand.

The tool description is more important than people expect. It is the only documentation the model reads before deciding to call your function. “Deletes a record” invites trouble. “Soft-deletes one order by ID. Never use for bulk changes. Ask the user to confirm first” gets much better behavior. Write them for a reader who takes every word literally, because that is exactly what the model does.

How does AI agent memory work?

Short-term memory is the context window: everything the model can see in the current run. Long-term memory is anything you store outside the model, such as notes files, databases or a vector store, and load back in when needed.

The context window is finite. As an agent works, it fills with tool output, file contents and its own reasoning. Agent harnesses deal with that by trimming old tool results or summarizing the conversation; Claude Code’s docs note that it clears older tool outputs first, then summarizes, and that “detailed instructions from early in the conversation may be lost.” That is why persistent rules belong in a project file the agent reloads each session (CLAUDE.md, AGENTS.md and similar), not in a message you typed an hour ago.

Long-term memory comes in a few flavors:

Memory is also an attack surface. If an agent can write to its own long-term memory, a poisoned web page can plant instructions that persist into future sessions. OWASP lists memory and context poisoning as one of its top agentic risks.

How is an agent different from a chatbot or a workflow?

A chatbot answers; a workflow follows your steps; an agent chooses its own steps. Each step up buys flexibility at the cost of predictability, latency and money.

Chatbot Workflow Agent
Who decides the steps No steps, one reply Your code The model
Uses tools Rarely Yes, in a fixed order Yes, chosen at runtime
Predictability High High Lower
Cost per task Low Low to medium Medium to high
Testing Easy Easy, like normal code Hard; needs evaluation runs
Best for Q&A, drafting Repeatable processes Open-ended, multi-step problems

Anthropic’s advice is to find “the simplest solution possible, and only increasing complexity when needed.” In my experience that is exactly right. Most business problems people bring to “agents” are really workflows with one or two model calls in them, and they are cheaper and more reliable built that way.

Where do AI agents fail?

Agents fail by compounding small errors over many steps, losing track of instructions as context fills, looping, misusing tools, and following instructions hidden in the data they read. None of these are rare.

Prompt injection is the one to take most seriously, because there is no complete fix yet. Simon Willison’s “lethal trifecta” sums up the danger: an agent with access to private data, exposure to untrusted content and the ability to communicate externally can be tricked into leaking that data. Remove any one of the three and the attack gets much harder.

What are real uses of AI agents for developers?

Coding agents are the most mature use today: fixing bugs, writing tests, refactoring across files, upgrading dependencies and reviewing pull requests, with a human reviewing the result.

Where agents earn their keep for a developer:

The pattern that works: a well-defined goal, a way for the agent to check its own work (tests, a build, a linter), and you reviewing the diff before it ships. Remove the check and you are back to trusting a summary.

What are real uses of AI agents for small businesses?

For small businesses, the best uses are back-office tasks with a clear finish line and a human sign-off: triaging email, preparing quotes, reconciling records, and researching suppliers or leads.

Some realistic examples:

Notice the theme: the agent prepares, a human approves. Letting an agent send emails, move money or change customer records without review is where small businesses get hurt, because there is usually no security team to notice before the damage is done.

How do you keep AI agents safe?

Give agents the least access that gets the job done, require human approval for anything irreversible, cap steps and spend, log every tool call, and never combine private data, untrusted input and outbound communication in one agent.

The OWASP Top 10 for Agentic Applications lists the risks to plan for, including agent goal hijack, tool misuse, identity and privilege abuse, supply chain issues, unexpected code execution, memory poisoning and cascading failures. The practical controls:

  1. Least privilege. Read-only database logins, a dedicated service account, file access limited to one folder. If the agent does not need a permission, it does not get it.
  2. Approval for irreversible actions. Sending, paying, deleting and deploying go through a human click. Keep the agent tool’s approval prompts on.
  3. Break the trifecta. An agent that reads untrusted web content should not also hold your customer database and an email tool.
  4. Budgets. Maximum steps, maximum tokens, maximum spend per task. Fail loudly when hit.
  5. Sandboxing. Run code-executing agents in a container or VM, not on your main workstation with your SSH keys.
  6. Logging. Record every tool call with arguments and results. When something odd happens, you want the transcript.
  7. Vet your tools. Treat third-party MCP servers and plugins as dependencies with privileges, because they are.

Bottom line

An AI agent is not magic: it is a model in a loop with tools, some memory and a stop condition. That loop is useful for coding and back-office work when the goal is clear and the agent can check its own results. Start with a workflow if a workflow will do, give agents the narrowest permissions you can, and keep a human on the irreversible buttons. Treat it like a contractor on their first day: helpful, fast, and not yet trusted with the keys.

FAQ

What is the difference between an AI agent and a chatbot?

A chatbot answers a message and stops. An AI agent works toward a goal over several steps, deciding which tools to call, reading the results and continuing until the task is done or a limit is reached.

Do AI agents need a special model?

No. Any capable model that supports tool calling can drive an agent. Results depend heavily on the model’s reasoning, the quality of the tool descriptions and the guardrails around it, which is why coding agents often use the vendor’s strongest models.

What is agent memory?

Short-term memory is the model’s context window for the current task. Long-term memory is information stored outside the model, such as instruction files, saved notes or a document index, that the agent reloads or searches in later sessions.

What is the biggest security risk with AI agents?

Prompt injection: instructions hidden in content the agent reads, such as a web page or email, that hijack its goal. It is most dangerous when one agent has private data, reads untrusted content and can send data out.

Should a small business use AI agents?

Yes, for well-defined back-office tasks where the agent drafts and a person approves, such as inbox triage, quotes or reconciliation. Avoid giving agents unsupervised ability to send messages, move money or change customer records.

How do I stop an AI agent from running up costs?

Set hard limits on steps, tokens and spend per task, use vendor spending caps where offered, and review usage after the first week. Most runaway costs come from loops that retry the same failing action.

Featured image: Photo by Freek Wolsink on Pexels.

Exit mobile version