Building AI Agents & Automations
You've built an insight report automation and a Contentful translation agent. This module formalizes the mental model — how to think about agents, when to use n8n vs code vs APIs, and how to design reliable multi-step workflows.
- The 4-step agent loop and how your existing automations fit it
- When to use n8n vs direct API vs agent frameworks
- Why prompt reliability matters more in automation than one-off use
- Spec a complete automation from scratch: trigger, AI step, output, destination, error handling
- Audit an existing automation for failure modes
- Treat your prompts like production code
Step 1 of 5 · Read the lesson
The 4-step agent pattern
- Receive a goal
- Use tools (APIs, files, search)
- Reason about what's next
- Repeat until done or stuck
Decision framework
n8n — linear logic, existing integrations, non-engineers can edit.
Direct API — custom logic, performance-critical, tight integration with your code.
Agent framework (LangChain, CrewAI) — multi-step reasoning, dynamic tool selection.
Reliability
Most AI automations work 80% of the time and fail silently. Add: input validation, output schema checks, retry with backoff, human-in-the-loop for high-stakes paths, observability.
Prompts as code
Version them. Test edge cases. Document the expected output contract. A regression suite for prompts is not overkill — it's table stakes once a flow runs in prod.
Prompt templates as code (in practice)
In automations, treat your prompts like code. Version them. Test edge cases. Document the expected input format and output schema. A prompt that works 90% of the time is a function with a 10% bug rate — which is fine in one-off use and unacceptable in automation.
Specific practices:
- Save your automation prompts in a version-controlled doc (Notion, GitHub, anywhere with history)
- Write test cases: what happens when the input is empty? When it's in a language you didn't expect? When it's 10x longer than normal?
- Specify the output format as a schema, not just a description: "Return a JSON array of objects with keys:
theme(string),count(integer),confidence(high|medium|low)" - When a prompt starts producing worse output over time, treat it like a bug: investigate, iterate, document the fix