What it is
An AI agent is a system in which a language model decides what to do next: it reads a goal, chooses a tool (search, database, API, code execution), observes the result, and repeats until the task is done or it needs a human. Where a chatbot answers, an agent acts — filing tickets, reconciling records, researching, writing and testing code.
Agent development is mostly software engineering: well-designed tools, clear permissions, durable state, observability and evaluation. The model supplies judgment; the surrounding system supplies safety and reliability.
How it works
Define the goal
Give the agent a clear objective, constraints, and a definition of done.
Provide tools
Expose narrowly scoped, well-described functions — ideally through a standard such as the Model Context Protocol.
Loop
The model plans, calls a tool, reads the result and decides the next step, within step and budget limits.
Keep state
Persist progress, memory and intermediate results so long tasks can resume and be audited.
Escalate
Pause for human approval before irreversible or high-impact actions.
Evaluate
Test full trajectories — did it reach the goal, with the right tools, safely and efficiently?
Worked example: invoice follow-up agent
A back-office agent that chases overdue invoices. It maps directly onto the loop above: sense the state of the books, plan the next step per invoice, act through tools, verify the result, and hand off to a person when the stakes rise.
The loop and escalation policy
Sense -> poll the accounting system for overdue invoices
Plan -> the model picks one action per invoice (reminder, ping, escalate)
Act -> call the matching tool
Verify -> feed the result back; stop, loop, or escalate| Days overdue | Action |
|---|---|
| Under 14 | Friendly reminder email |
| 14 to 45 | Firm reminder, plus a Slack ping to the account manager |
| Over 45 | Request escalation to collections (needs human approval) |
Tools, scoped by least privilege
The agent gets three narrow tools. None can delete data or move money, and the escalation tool only queues a request for a person to approve.
const tools = [
{
name: "send_reminder_email",
description: "Send a payment reminder for one invoice.",
input_schema: {
type: "object",
properties: {
invoiceId: { type: "string" },
tone: { type: "string", enum: ["friendly", "firm"] },
},
required: ["invoiceId", "tone"],
},
},
{
name: "ping_account_manager",
description: "Notify the account manager in Slack about a risky account.",
input_schema: {
type: "object",
properties: { invoiceId: { type: "string" }, note: { type: "string" } },
required: ["invoiceId", "note"],
},
},
{
name: "request_collections_escalation",
description: "Queue an escalation for human approval. Does not act on its own.",
input_schema: {
type: "object",
properties: { invoiceId: { type: "string" }, reason: { type: "string" } },
required: ["invoiceId", "reason"],
},
},
];The loop in Node.js
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const MAX_STEPS = 5; // step budget: the loop can never run away
async function run(invoices) {
const messages = [
{ role: "user", content: `Overdue invoices:\n${JSON.stringify(invoices)}\nTake the right action for each.` },
];
for (let step = 0; step < MAX_STEPS; step++) {
const res = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
system: "You are an accounts-receivable agent. Follow the escalation policy. One action per invoice per turn.",
tools,
messages,
});
messages.push({ role: "assistant", content: res.content });
const calls = res.content.filter((b) => b.type === "tool_use");
if (calls.length === 0) return; // goal met
const results = [];
for (const call of calls) {
const output = await toolImpl[call.name](call.input); // act
results.push({ type: "tool_result", tool_use_id: call.id, content: JSON.stringify(output) });
}
messages.push({ role: "user", content: results }); // verify: the model sees what happened
}
}The same loop as a graph
LangGraph expresses the stages as named nodes, with routing functions deciding what happens next. The step budget becomes recursionLimit, and escalation becomes a node of its own that ends the run.
const graph = new StateGraph(AgentState)
.addNode("sense", senseNode)
.addNode("plan", planNode)
.addNode("act", actNode)
.addNode("human_review", humanReviewNode)
.addEdge(START, "sense")
.addEdge("sense", "plan")
.addConditionalEdges("plan", planRouter, { act: "act", [END]: END })
.addConditionalEdges("act", verifyAndRoute, { plan: "plan", human_review: "human_review" })
.addEdge("human_review", END)
.compile();
await graph.invoke({ messages: [] }, { recursionLimit: 15 });Unlike a DAG, this graph has a cycle: plan and act can repeat until the goal is met or a limit is hit. That cycle is what makes it an agent rather than a fixed pipeline.
What to notice
- Limits are enforced by the system, not requested from the model. The step budget and the recursion limit stop the loop even if the model never would.
- High-impact steps pause for a person. The escalation tool queues a request and the run ends in human_review.
- State is explicit. The message history (and, in the graph version, a needsHumanReview flag) is the audit trail for what the agent did and why.
- This could be a workflow. The thresholds above are simple enough that a script could apply them. The model earns its place when the next step depends on messy context, such as reading a customer's reply or drafting a tailored message. If it doesn't, use a script.
These samples are illustrative and have not been run against production systems.
Key concepts
- Tool / function calling
- The mechanism by which a model requests an action with structured arguments.
- Model Context Protocol (MCP)
- An open standard for connecting AI applications to tools and data sources through reusable servers.
- Workflows vs. agents
- Fixed, code-defined steps are cheaper and more predictable; use autonomous agents only where flexibility pays.
- Multi-agent systems
- Specialized agents coordinated by an orchestrator, or communicating over protocols such as Agent2Agent (A2A).
- Memory
- Short-term working context plus long-term stores of facts, preferences and past outcomes.
- Least privilege
- Each tool gets only the permissions it needs; destructive actions require confirmation.
- Durable execution
- Checkpointing so long-running agents survive failures and restarts.
Tools & platforms
Agent SDKs and frameworks
Protocols
Runtime and operations
Skills employers look for
- Deciding when a deterministic workflow is better than an autonomous agent.
- Designing tool interfaces with clear names, descriptions, schemas and error messages.
- Building and consuming MCP servers to connect agents to enterprise systems.
- Implementing human approval steps, permission scoping and sandboxing.
- Managing state, memory, retries and long-running execution.
- Tracing and evaluating agent trajectories, cost and success rate.
Enterprise use cases
IT and operations automation
Diagnose alerts, gather logs and propose or apply runbook fixes with approval.
Research and analysis
Search internal and external sources, compare findings and draft a sourced brief.
Back-office processing
Reconcile invoices, update CRM records and chase missing information.
Software engineering
Coding agents that implement, test and document changes for human review.
Common pitfalls
- Agents where a script would do — autonomy adds cost and unpredictability; use it deliberately.
- Over-broad tool permissions — an agent can only do as much damage as its tools allow.
- No step or budget limits — loops can burn tokens and time without making progress.
- Evaluating only final answers — inspect the path taken, not just the result.
How MrAI.dev helps
We identify processes where agents genuinely beat workflows, build the tools and MCP integrations they need, and put approvals, sandboxing, tracing and evaluation in place before anything touches production systems.
Book a discovery call