MS

Engineering notes

Building AI agents with LangGraph and n8n: what works in production

By Muhammad Shahid ยท ยท 3 min read

Quick answer

Use n8n when the job is moving information between tools with a few AI steps, LangGraph when an agent needs several steps that keep state and branch, and plain code when one model call is enough. Whatever you pick, production needs the same things: validated tool calls, evaluation before every release, monitoring of quality, latency and cost, and a backend that handles errors. I apply this on the AI platform Joni (joni.ai).

Key facts
Where I use thisJoni (joni.ai), an AI product platform
FrameworksLangGraph, LangChain, n8n, plain Node.js and Python
ModelsOpenAI and Anthropic (Claude) APIs
CertificationsBuild AI Agents using LangGraph; n8n: No-Code AI Agent Builder
Production must-havesValidated tools, evals, monitoring, cost control

Do you actually need an agent?

Many "agent" projects are one model call: classify this email, summarise this document, extract these fields. Build those as a single call with a clear prompt and a structured output, and keep the agent for work that genuinely needs several steps where the next step depends on the last result. Fewer moving parts means fewer things to break.

When should you use n8n, LangGraph or plain code?

  • n8n: when the job is mostly moving data between apps (a form, a CRM, email, Slack) with an AI step or two in the middle. Non-developers can read and change the workflow.
  • LangGraph: when an agent needs several steps that keep state, branch, loop, or hand work between specialised agents.
  • Plain code (Node.js or Python): when it is one or two model calls inside your existing backend, or performance and testing matter most.

How do you make tool calls safe?

An agent that can call your APIs can also call them wrongly. Define each tool with a strict schema, validate the arguments before anything runs, and keep anything destructive (payments, deletions, sending messages) behind a confirmation or a human approval step. Return clear errors from tools so the model can correct itself instead of guessing.

function runTool(name, input) {
  const tool = tools[name]
  if (!tool) return { error: "Unknown tool " + name }
  const check = tool.schema.safeParse(input)        // validate before acting
  if (!check.success) return { error: check.error.message }
  if (tool.needsApproval) return queueForApproval(name, check.data)
  return tool.run(check.data)
}

How do you know a change made the agent better?

Keep a set of real inputs with the answers or actions you expect, and run it before every change to prompts, tools or models. Compare the score, not a few hand-picked examples. It is the same discipline as regression testing in QA, applied to AI: a change that fixes one case often breaks two others, and only an evaluation set shows that.

What do you monitor in production?

Trace every run: the prompt, the tool calls, the response, the time it took and what it cost. Watch answer quality on a sample of real conversations, latency per step, and cost per feature. Most agent problems show up first as a slow step or a cost jump, before anyone complains.

How do you keep cost and latency down?

  • Cache repeated answers and long, stable prompts.
  • Use smaller models for steps where quality allows, and the strongest model only where it matters.
  • Trim prompts and context to what the step needs.
  • Stream responses to users, and batch background work.

When are multi-agent systems worth it?

When the work splits cleanly: one agent researches, another writes, another checks. Each agent gets a narrow job and only the tools it needs, coordinated with LangGraph. If the split is not clean, a single agent with good tools is easier to debug and usually just as good.

Frequently asked questions

What is the difference between n8n and LangGraph?

n8n is a visual workflow tool for connecting apps with AI steps; LangGraph is a framework for building agents in code that keep state across several steps.

How do you evaluate an AI agent?

Run a fixed set of real inputs with expected results before every change, and compare scores, so you see regressions instead of judging by a few examples.

How do you stop an AI agent from making harmful tool calls?

Strict tool schemas, validation before running anything, and human approval for destructive actions such as payments, deletions or sending messages.

How can I reduce LLM costs?

Cache repeated answers, use smaller models where quality allows, trim prompts and context, stream responses and batch background work, and track cost per feature.

Are multi-agent systems better than one agent?

Only when the work splits cleanly into narrow jobs. Otherwise one agent with good tools is simpler to debug and usually performs as well.

Can you build an AI agent for my product?

Yes. I build production AI agents with LangGraph, n8n and the OpenAI and Anthropic APIs, including evaluation and monitoring. See the AI agent developer service page.