AI Agents

How to Build an AI Agent: A Step-by-Step Guide for 2026

NasBy NasUpdated 16 min read
How to build an AI agent in 6 steps: workflow, route, instructions, tools, test and run, next to the Talk to me Data agent working on a laptop
On this page

To build an AI agent, pick one repetitive workflow, give a capable model (such as Claude) clear instructions for it, connect the tools it needs to act (through MCP connectors or APIs), then test it on real inputs and decide how it gets triggered. You can do this with no code in Claude, with a visual builder like n8n, or in one short Python script. This guide walks through all three, with instructions and code you can copy.

We build AI agents for small and medium businesses every week: agents that process invoices, triage support tickets, research leads, and write and publish content. The steps below are the same ones we follow, including the parts that usually go wrong when people build their first agent on their own.

How to build an AI agent in 6 steps

  1. Pick one workflow that is repetitive, high-volume and easy to define, such as invoices, lead research or social posts.
  2. Choose how to build it: no code in Claude, a workflow builder like n8n, or code with an agent SDK.
  3. Write the instructions: role, goal, numbered steps, rules, output format and when to stop.
  4. Connect only the tools it needs, through MCP connectors or APIs, read-only where you can.
  5. Test it on real, messy inputs and add guardrails, with a human approval step for anything hard to undo.
  6. Decide how it runs: on demand in chat, or on a schedule or trigger with hosting and monitoring.

What Do You Need to Build an AI Agent?

You need three things: a model that reasons, instructions that define the job, and tools that let it act in your apps. To run it, you also need a trigger that starts it. Every tool and framework is just a different way of supplying these parts. (New to the idea? Start with our plain-English guide to what AI agents are, or our AI agents for beginners guide.)

Anatomy of an AI agent: a trigger starts it, the model follows its instructions, calls tools, and produces an outputTriggerMessage, schedule,form, email, webhookModel + instructionsPlans the steps,decides what to do nextToolsCRM, Sheets, Gmail,web search, APIsOutputUpdated records,drafts, reports, repliesresults feed back until the goal is met
Every AI agent is a model, instructions and tools, plus a trigger that starts it. Building one means choosing each part for your workflow.
PartWhat it doesExamples
ModelReasons about the task and decides each next stepClaude, GPT, Gemini
InstructionsDefine the goal, steps, rules and output formatA system prompt, or Project instructions in Claude
ToolsLet the agent read and act in your appsMCP connectors or APIs for Gmail, Google Sheets, HubSpot, QuickBooks, Notion, web search
TriggerStarts a runYou send a message, a schedule (every Monday 8am), a new form entry, a new email, a webhook

Step 1: Pick a Workflow Worth Automating

Pick a task that is repetitive, high-volume and well-defined: one you could write down once and hand to a new hire. The most common mistake is starting too big ("automate our marketing"). Agents struggle with strategy, high-stakes judgment and relationship-critical conversations.

Good first agents, with the manual time they typically replace:

WorkflowDone by handWhat the agent does
Invoice processing20–40 min per invoiceReads the invoice, extracts line items, posts them to QuickBooks or Xero
Social media content2–3 hours a weekTurns one idea into platform-specific posts, then drafts and schedules them
Lead research10–15 min per leadFinds, enriches and researches hundreds of leads overnight
CRM and data entry5–10 min per contactLogs calls and emails and updates records as they happen
Customer support repliesAll day, every dayAnswers common questions, ranks the rest by urgency, drafts a solution
Follow-ups and review requestsInconsistent or forgottenSends timed, personalised follow-ups and review requests at the right moment

Pick the one that costs you the most hours and has the clearest definition of "done". You can add more agents later; one that works reliably is worth more than five that half-work.

Step 2: Choose How You Will Build It

Choose between three routes: a no-code agent in Claude, a workflow builder such as n8n, or code. They supply the same parts in different ways, and differ mostly in how much control you get and whether the agent can run without you.

No-code chat agentWorkflow builderCode
ToolsClaude Projects + connectors (MCP)n8n, Make, ZapierAnthropic or OpenAI SDKs, Claude Agent SDK, model APIs
Skills neededNoneComfortable with logic and APIsBasic Python or JavaScript
Time to first agentAn afternoonA day or twoA day for a prototype, weeks for production
Runs unattendedNo, runs while you chatYes, on triggers and schedulesYes, once you host it
Best forLearning, personal workflows, prototypesScheduled, multi-app business workflowsHigh volume, custom logic, agents inside your product
Which way to build an AI agent: if it doesn't need to run without you, use a no-code agent; if it does, use a workflow builder, or code for high volume and agents inside your productDoes it need to runwithout you?High volume, or builtinto your product?No-code agentClaude Project + connectorsWorkflow buildern8n, Make, ZapierCodeAgent SDK or model APINoYesNoYes
Two questions decide the route. Most first agents belong in the top box, and move down only once the workflow has proved itself.

If you are building your first agent, start with the no-code route. It is the fastest way to find out whether the workflow is a good fit before you invest in anything more robust. Steps 3 to 6 use that route; the n8n and Python versions follow after them.

Step 3: Write the Agent's Instructions

Write the instructions like a job description for a new hire, because they decide most of the agent's quality. In Claude, create a new Project named after the workflow ("Invoice Processor", "Lead Research Agent") and put the instructions in the Project, so every chat inside it follows them.

Strong agent instructions always cover six things:

  1. Role: who the agent is and who it works for.
  2. Goal: what a finished run produces.
  3. Steps: numbered, in order, including which tool to use at each step.
  4. Rules: what it must never do, such as inventing data, emailing customers directly or deleting records.
  5. Output format: exactly what to return and where to save it.
  6. Stop conditions: when to stop and ask a human instead of guessing.
The six parts of AI agent instructions: role, goal, steps, rules, output format and stop conditions, with an example of each1. RoleSocial media assistantfor [Business Name]2. GoalReady-to-publish postsfor three platforms3. StepsRead the source, pick oneidea, write, save to a doc4. RulesNever invent statistics,customers or quotes5. OutputThree posts and thelink to the doc6. Stop conditionsSource unreachable oroff-topic: stop, say why
The six parts, filled in for the social content agent below. If one is missing, that is usually where the agent goes wrong.

Here is the complete example for a social content agent. Copy it, swap the brackets for your details, and paste it into a Claude Project:

Example agent instructions
You are a social media assistant for [Business Name].

GOAL
When given a topic or a URL, turn it into ready-to-publish posts for three platforms.

STEPS
1. Read the source (fetch the URL if one is given).
2. Pick the single most useful idea for our audience: [describe your audience].
3. Write:
   (1) a LinkedIn post of 150–200 words with a hook and 3 bullet points
   (2) an X thread of 5 posts
   (3) an Instagram caption with 5 relevant hashtags
4. Save all three to the Google Doc "Social drafts" under today's date.

RULES
- Write in first person, professional but conversational.
- Never invent statistics, customers or quotes. If the source has no data, don't use numbers.
- If the source is unreachable or off-topic, stop and say why instead of guessing.

OUTPUT
Reply with the three posts and the link to the doc.

For full, production-tested prompts, see our guides to building a customer service agent, an SEO agent and a lead generation agent.

Step 4: Connect the Tools It Needs

Connect only the apps the workflow touches, because tools are what turn a model that writes text into an agent that acts: it reads your inbox, updates a spreadsheet, creates a CRM record or posts an invoice. In Claude, you give it tools by enabling connectors in settings. These use MCP (Model Context Protocol), an open standard for connecting AI models to apps and data. Connectors exist for Gmail, Google Drive, Notion, Airtable, Slack, HubSpot, QuickBooks and hundreds more.

Two rules save a lot of pain here:

  • Connect only what the workflow needs. An invoice agent needs your invoices folder and your accounting software, not your whole Google account.
  • Start read-only where you can. Let the agent draft and propose before you let it send, post or delete.
Illustration: a plain-language instruction to qualify a new form lead and book a call, followed by the agent's actions in Forms, the CRM, Calendar and Gmail
Each line is a different connected tool. Without connectors the agent could only describe these steps; with them, one instruction becomes four actions.

Step 5: Test on Real Inputs and Add Guardrails

Test the agent on the messiest real inputs you can find, because each failure tells you which rule or step to add. Start a chat inside the Project and give it a real trigger, such as "Process the invoices in the /Invoices/Pending folder". Then feed it the hard cases: a blurry scan, a duplicate lead, an email in another language, a request it shouldn't handle.

  • Human approval for irreversible actions. Sending emails, paying bills and deleting records should wait for a yes until you trust the agent.
  • Deduplication. Have the agent check existing records before writing, or every run will add the same rows again.
  • A run log. Ask it to report what it did on every run (items found, processed, skipped and why), so you can audit it.
  • No guessing. Tell it to stop and flag missing data rather than fill gaps. A fabricated value is worse than an empty one.
The AI agent autonomy ladder: start read only, then let it draft, then act after approval, and only act alone on proven, reversible tasks1. Read onlyLooks and reportsback to you2. DraftPrepares the work,you press send3. ApproveActs afteryour yes4. Act aloneProven, reversibletasks onlymore trust, earned on real inputs
Move an agent up one rung at a time, and only after it has handled real inputs correctly on the rung below.

Step 6: Decide How It Runs

Decide whether the agent runs when you ask it to, or on its own. A Claude Project agent runs when you open a chat, which is fine for on-demand work. Many workflows need to run every morning, whenever a form is submitted, or whenever a new invoice arrives. This is where most do-it-yourself builds stall, for structural reasons:

  • Usage limits stop long runs. Consumer AI plans cap usage within a rolling window. A long run (100 invoices, 200 leads, a week of content) can hit the cap and stop mid-task, leaving a partial batch to clean up by hand.
  • The agent competes with you. The same allowance that runs your agent is the one you use for everything else.
  • Running it properly is infrastructure work. Moving to an API means managing keys, rate limits, hosting, retries, error alerts and monitoring.

For scheduled, multi-app workflows, a workflow builder or code is the right next step; both are covered below. If you would rather skip the setup entirely, we build, host and monitor agents for you: you describe the work in plain language and get a running agent connected to your tools.

In the video: building an AI agent from scratch in Claude, from creating the Project and writing its instructions to connecting tools and running the workflow.

How Do You Build an AI Agent in n8n?

In n8n, you build an agent by adding an AI Agent node to a workflow and attaching a chat model and tools to it. The six steps above stay the same; n8n just gives the agent a trigger and lets it run on its own.

  1. Add a trigger. A Schedule Trigger for "every Monday at 8am", a form or webhook for new leads, or a Chat Trigger while you test.
  2. Add the AI Agent node and paste your instructions into its system message.
  3. Attach a chat model. The Anthropic Chat Model sub-node runs Claude; OpenAI and Gemini models work the same way. You need an API key for the model.
  4. Attach tools. Add Gmail, Google Sheets, HubSpot or an HTTP Request node as tools the agent can call. Add a memory sub-node only if it holds conversations.
  5. Test with real data, then switch it on. Run a few test executions, read each step's input and output, and fix the instructions before the workflow goes live.
An n8n workflow with a schedule trigger, data-fetching steps and several AI model nodes connected to a Google Gemini chat model
The workflow-builder route: in n8n, a schedule trigger feeds data through ordinary steps and AI model nodes, which is how agents run unattended on a timer.

How Do You Build an AI Agent in Python?

In Python, an AI agent is a loop: you send the model your instructions and a list of tools, it asks for a tool, your code runs it and sends the result back, and this repeats until the task is done. The Anthropic Python SDK includes a tool runner that writes that loop for you, so a working agent fits on one screen.

How an AI agent works in code: the model asks for a tool, your code runs it, the result goes back to the model, and the loop repeats until the model gives a final answerModel (Claude)Decides the next step,or gives the final answerYour codeThe loop: runs whatevertool the model asks forYour toolsInvoices, email drafts,CRM, any API1. asks for a tool2. runs it3. returns data4. sends resultrepeats until the model replies with a final answer instead of a tool request
Every agent framework runs this loop. The Python SDK's tool runner writes it for you, so you only write the tools and the instructions.

This example chases overdue invoices. It has two tools, one that lists overdue invoices and one that saves a reminder email as a draft. It never sends anything, so it sits on the "draft" rung of the ladder above. Swap the two placeholder functions for real calls to your accounting software and email.

agent.py
# pip install anthropic
# export ANTHROPIC_API_KEY=your-key
import anthropic
from anthropic import beta_tool

client = anthropic.Anthropic()


@beta_tool
def list_overdue_invoices() -> str:
    """List unpaid invoices that are past their due date."""
    # Replace with a real call to QuickBooks, Xero or a Google Sheet
    return '[{"customer": "Acme Ltd", "email": "ap@acme.example", "amount": 1200, "days_overdue": 14}]'


@beta_tool
def save_draft_email(to: str, subject: str, body: str) -> str:
    """Save a payment reminder as a draft for a human to review. Never sends it.

    Args:
        to: The customer's email address.
        subject: The email subject line.
        body: The email text.
    """
    # Replace with a Gmail or Outlook "create draft" call
    return f"Draft saved for {to}"


runner = client.beta.messages.tool_runner(
    model="claude-opus-5-5",
    max_tokens=16000,
    max_iterations=10,  # guardrail: never more than 10 model turns per run
    system=(
        "You are an accounts assistant. Find overdue invoices and draft one polite "
        "payment reminder per customer. Never invent amounts or dates. "
        "Finish with a short report: invoices found, drafts saved, anything skipped and why."
    ),
    tools=[list_overdue_invoices, save_draft_email],
    messages=[{"role": "user", "content": "Chase this week's overdue invoices."}],
)

# The SDK runs the loop: model asks for a tool, the tool runs, the result goes back
for message in runner:
    for block in message.content:
        if block.type == "text":
            print(block.text)

A few things worth noticing in that code, because they apply to any agent you write:

  • The docstrings are instructions. The model reads each tool's description to decide when to use it, so "Never sends it" matters.
  • The system prompt follows the same six parts as the no-code version: role, goal, rules and a required report at the end.
  • max_iterations is a guardrail. It caps how many turns one run can take, so a confused agent can't loop forever.

To run it on a schedule, call the script from a cron job or a cloud function, or use a hosted option such as Anthropic's Managed Agents, which runs the loop and the schedule for you. If you prefer OpenAI models, the OpenAI Agents SDK follows the same pattern. For agents that need to read files and run commands, the Claude Agent SDK gives you the same harness that powers Claude Code.

Free guide

Take this guide with you as a PDF

Our free guide covers the workflows worth automating, the Claude setup step by step, and the honest limits of the DIY route, in a format you can share with your team.

Get the free guide →

What Are the Most Common Mistakes When Building an AI Agent?

Most first agents fail for the same few reasons, and none of them is the choice of model. These are the ones we see most often:

  1. Starting with a whole department. "Run our marketing" has no clear finish line. "Turn each blog post into three social drafts" does.
  2. Vague instructions. "Be helpful and professional" gives the agent nothing to follow. Numbered steps and named tools do.
  3. Too many tools, too much access. Every extra connector is another way to go wrong. Give it the minimum, read-only first.
  4. Testing only the clean cases. An agent that works on three tidy examples will still break on the first scanned PDF or forwarded email chain.
  5. No stop condition. Without one, an agent that hits missing data will guess, and a confident wrong answer is the most expensive kind.
  6. Treating a chat agent as a system. If the business depends on it running daily, it needs a schedule, retries and someone who gets an alert when it fails.

Summary

Building an AI agent comes down to a model, instructions and tools, plus a trigger that starts it. Start with one repetitive, well-defined workflow, write instructions with clear steps, rules and stop conditions, connect only the tools it needs, and test it against messy real inputs before you let it act on its own.

A no-code agent in Claude is the fastest way to prove a workflow. When it needs to run every day without you, move it to n8n, to a short Python script, or to a hosted agent.

Frequently Asked Questions

Can I build an AI agent without coding?

Yes. You can build a working agent with no code in Claude by creating a Project, writing instructions, and enabling connectors for tools like Gmail, Google Drive or Notion. Visual workflow builders such as n8n, Make and Zapier also let you add AI agent steps without writing code. Code (an agent SDK or a model API) only becomes necessary when you need the agent to run unattended at high volume, or inside your own product.

What is the difference between an AI agent and an automation?

A traditional automation follows fixed if/then rules: when X happens, do Y. It breaks when an input doesn't match the expected pattern. An AI agent is given a goal and decides the steps itself, so it can read a messy email, work out what the person meant, look up missing information and choose which tool to use next. Many good systems combine both: an automation triggers the agent, and the agent handles the judgment.

How much does it cost to build an AI agent?

A no-code agent costs nothing beyond the paid AI plan you may already have. Agents built on a model API are billed per token: at October 2026 prices, Claude Sonnet 5.5 costs $2 per million input tokens and $10 per million output tokens, so a run that reads about 20,000 tokens and writes 2,000 costs roughly 6 cents. Workflow builders such as n8n add a plan fee unless you self-host. For most small businesses the real cost is build and maintenance time, not model usage.

Can I build an AI agent with ChatGPT?

Yes. The same six steps apply: pick a workflow, write the instructions, connect the apps the agent needs, test it and decide how it runs. ChatGPT supports custom instructions and connectors for the no-code route, and OpenAI's Agents SDK covers the code route. Pick the model that handles your real inputs best, and test at least two before committing.

What is MCP and do I need it to build an AI agent?

MCP (Model Context Protocol) is an open standard for connecting AI models to tools and data, such as your email, CRM, file storage or databases. You don't strictly need it, since an agent can also call APIs directly, but MCP connectors are the fastest no-code way to give an agent like Claude access to the apps it needs to act in.

Which AI model is best for building agents?

Most production agents run on frontier models from Anthropic (Claude), OpenAI (GPT) or Google (Gemini). What matters most for agents is reliable instruction-following, good tool use and a long context window. Claude is widely used for agentic workflows for these reasons. Test your actual workflow on two models before committing, because results vary by task.

How long does it take to build an AI agent?

A simple single-task agent, such as one that turns a blog post into social posts, can be running in an afternoon. A production agent that connects several tools, handles edge cases, runs on a schedule and is monitored usually takes days to a couple of weeks, most of which goes into testing and guardrails rather than the prompt.

Why does my DIY agent stop halfway through a task?

Consumer AI apps limit how much you can use the model within a rolling time window. A long agent run, such as processing 100 invoices or researching 200 leads, can exhaust that allowance and stop mid-task, leaving a partial batch. Agents that need to run reliably in the background are usually moved to the model's API with their own hosting, retries and monitoring.
Done for youSkip the build: browse ready-built AI agents

Keep reading

All AI Agents guides