Tutorial
Advanced agent patterns: working with loops and more
Take your agents to the next level with advanced workflow patterns — from conditional logic to approval workflows to multi-agent orchestration.
Published on
Written by

Ryan Tanaka

You've built your first agent. It handles simple tasks reliably. Now you want to tackle more complex workflows. This guide covers three advanced patterns that unlock the full power of AI agents.
Pattern 1: Conditional Branching
Real-world workflows rarely follow a straight line. Depending on the input, your agent might need to take completely different paths. That's where conditional branching comes in.
In the Visual Builder, add a "Condition" node after any step. Define your branching logic using natural language or structured rules. For example: "If refund amount > $100, require manager approval. Otherwise, process automatically."
You can chain multiple conditions to create complex decision trees. Each branch can have its own sequence of actions, tools, and even different LLM configurations. The agent evaluates conditions in real-time based on the conversation context and available data.
Pro tip: Use conditions sparingly. Every branch adds complexity and potential failure points. If you find yourself with more than 5-6 branches, consider breaking the workflow into multiple specialized agents instead.
Pattern 2: Loops and Iteration
Some tasks require repetition. Processing a list of items, retrying failed operations, or gathering information until a condition is met. Our loop pattern handles all of these.
The "Loop" node lets you define: what to iterate over (a list, a condition, or a count), what actions to perform each iteration, when to break out of the loop, and how to handle errors within iterations.
For example, imagine an agent that enriches lead data. You give it a list of 100 leads. The loop processes each one: looking up the company, finding contact info, scoring fit, and updating your CRM. If any lookup fails, it logs the error and continues to the next lead.
Without loops, you'd need 100 separate executions. With loops, it's a single workflow that handles everything automatically, including progress tracking and error recovery.
Pattern 3: Human-in-the-Loop
Not everything should be fully automated. Sometimes you want human oversight for high-stakes decisions. The Human-in-the-Loop pattern lets you pause workflows for human approval without losing context.
Add an "Approval" node wherever you need human input. Configure who should approve (specific users, roles, or dynamic assignment), what information to show them, how long to wait before timing out, and what to do if approval is denied.
When the workflow hits this node, it pauses and sends a notification to the approver. They see the full context: what the agent has done so far, what it wants to do next, and why. They can approve, reject, or modify the proposed action.
Once approved, the workflow continues exactly where it left off. All context is preserved. The agent might even learn from the approval patterns — if managers always approve requests under a certain threshold, you might adjust the automation rules.
We see customers using this pattern for: refunds over a certain amount, contract modifications, access provisioning, and any action that affects production systems. It's the perfect balance between automation efficiency and human judgment.
Putting It All Together
The most powerful agents combine all three patterns. Imagine a procurement agent that: loops through purchase requests, branches based on amount and vendor, requires human approval above $10k, and automatically processes everything else.
That's a workflow that used to require multiple people, email chains, and days of delay. Now it runs in minutes with full auditability and consistent enforcement of your policies.
Start simple, add complexity gradually, and always test thoroughly in sandbox before deploying. The patterns are powerful — use them wisely.
OTHER BLOGS
Explore other blogs
Apr 12, 2026
The future of work is agentic and it's already happening
AI agents aren't coming — they're already transforming how companies operate. Here's what we've learned from powering millions of agent interactions every day.
Apr 11, 2026
How Acme Corp cut their costs by 60% using AI agents
A deep dive into how one fast-growing startup automated their customer support without sacrificing quality — and actually improved customer satisfaction.
Apr 25, 2026
Why we're betting everything on the future of AI agents
The future isn't chatbots or copilots — it's autonomous agents that get work done. Here's why we're building the infrastructure to make that happen.
Apr 21, 2026
How to build and deploy your first AI agent in 15 minutes
A step-by-step tutorial to create, test, and deploy a customer support agent that actually resolves tickets — not just responds to them.
Apr 25, 2026
How we scaled our platform to 50 million agent runs daily
A deep dive into the infrastructure decisions that let us handle massive scale without breaking a sweat — or the bank.
Apr 18, 2026
Introducing the new visual workflow builder for AI agents
Design complex agent workflows with drag-and-drop simplicity. Connect LLMs, tools, and APIs visually — no infrastructure code required.
