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

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
- Pick one workflow that is repetitive, high-volume and easy to define, such as invoices, lead research or social posts.
- Choose how to build it: no code in Claude, a workflow builder like n8n, or code with an agent SDK.
- Write the instructions: role, goal, numbered steps, rules, output format and when to stop.
- Connect only the tools it needs, through MCP connectors or APIs, read-only where you can.
- Test it on real, messy inputs and add guardrails, with a human approval step for anything hard to undo.
- 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.)
| Part | What it does | Examples |
|---|---|---|
| Model | Reasons about the task and decides each next step | Claude, GPT, Gemini |
| Instructions | Define the goal, steps, rules and output format | A system prompt, or Project instructions in Claude |
| Tools | Let the agent read and act in your apps | MCP connectors or APIs for Gmail, Google Sheets, HubSpot, QuickBooks, Notion, web search |
| Trigger | Starts a run | You 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:
| Workflow | Done by hand | What the agent does |
|---|---|---|
| Invoice processing | 20–40 min per invoice | Reads the invoice, extracts line items, posts them to QuickBooks or Xero |
| Social media content | 2–3 hours a week | Turns one idea into platform-specific posts, then drafts and schedules them |
| Lead research | 10–15 min per lead | Finds, enriches and researches hundreds of leads overnight |
| CRM and data entry | 5–10 min per contact | Logs calls and emails and updates records as they happen |
| Customer support replies | All day, every day | Answers common questions, ranks the rest by urgency, drafts a solution |
| Follow-ups and review requests | Inconsistent or forgotten | Sends 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 agent | Workflow builder | Code | |
|---|---|---|---|
| Tools | Claude Projects + connectors (MCP) | n8n, Make, Zapier | Anthropic or OpenAI SDKs, Claude Agent SDK, model APIs |
| Skills needed | None | Comfortable with logic and APIs | Basic Python or JavaScript |
| Time to first agent | An afternoon | A day or two | A day for a prototype, weeks for production |
| Runs unattended | No, runs while you chat | Yes, on triggers and schedules | Yes, once you host it |
| Best for | Learning, personal workflows, prototypes | Scheduled, multi-app business workflows | High volume, custom logic, agents inside your product |
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:
- Role: who the agent is and who it works for.
- Goal: what a finished run produces.
- Steps: numbered, in order, including which tool to use at each step.
- Rules: what it must never do, such as inventing data, emailing customers directly or deleting records.
- Output format: exactly what to return and where to save it.
- Stop conditions: when to stop and ask a human instead of guessing.
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:
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.

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.
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.
- 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.
- Add the AI Agent node and paste your instructions into its system message.
- 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.
- 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.
- 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.

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.
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.
# 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_iterationsis 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:
- Starting with a whole department. "Run our marketing" has no clear finish line. "Turn each blog post into three social drafts" does.
- Vague instructions. "Be helpful and professional" gives the agent nothing to follow. Numbered steps and named tools do.
- Too many tools, too much access. Every extra connector is another way to go wrong. Give it the minimum, read-only first.
- 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.
- No stop condition. Without one, an agent that hits missing data will guess, and a confident wrong answer is the most expensive kind.
- 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?
What is the difference between an AI agent and an automation?
How much does it cost to build an AI agent?
Can I build an AI agent with ChatGPT?
What is MCP and do I need it to build an AI agent?
Which AI model is best for building agents?
How long does it take to build an AI agent?
Why does my DIY agent stop halfway through a task?
Keep reading


