How to Build a Structured AI Workflow Engine Like Stripe Minions for Your Own Business
Stripe ships 1,300 AI-written PRs weekly using a structured harness. Learn how to build your own agent workflow engine with deterministic and agentic nodes.
Stripe Ships 1,300 AI-Written PRs a Week — Here’s the Architecture Behind It
In early 2025, Stripe revealed something that caught a lot of engineers off guard: their internal AI system — called Minions — was already generating roughly 1,300 pull requests per week, with about 70% merged without any human modification. That’s not a few AI-assisted commits. That’s a substantial portion of their engineering output automated at scale.
What made this possible wasn’t just picking a good model. It was the structured AI workflow engine underneath — a harness that separates deterministic logic from agentic reasoning, enforces reliability at every step, and gives engineers confidence that outputs are auditable and correct.
This article breaks down how that architecture works, why it outperforms raw LLM calls for real business tasks, and how you can build something similar for your own organization — even without Stripe’s engineering resources.
What Stripe’s Minions System Actually Does
Before getting into architecture, it’s worth understanding what Stripe built and why they built it the way they did.
Stripe’s Minions system is an internal AI workflow engine designed to automate software engineering tasks — things like writing tests, fixing bugs, updating documentation, refactoring code, and handling routine maintenance work. The system doesn’t just pass a prompt to GPT-4 and hope for the best. It wraps the model in a structured harness that controls inputs, validates outputs, routes tasks, and handles errors.
The Problem With Unstructured LLM Calls
Most teams start with the same approach: call an LLM, get text back, do something with it. This works fine for simple, one-shot tasks. But it breaks down quickly when you need:
- Consistency — the same task should produce the same quality output every time
- Auditability — you need to know what the model did and why
- Error recovery — if the model produces bad output, the system should handle it
- Integration — the AI needs to interact with real systems, not just produce text
Raw LLM calls can’t meet these requirements reliably. That’s why Stripe built a structured harness around their AI interactions rather than using LLMs as simple text generators.
What the Minions Harness Provides
According to Stripe’s public commentary on the system, the Minions harness provides several key capabilities:
- Task decomposition — breaking complex tasks into smaller, trackable units
- Context management — giving the model exactly the information it needs, no more
- Output validation — checking that what the model returns is actually usable
- Escalation paths — routing to human review when confidence is low
- Feedback loops — learning from what gets accepted vs. rejected
This is the blueprint for a production-grade AI workflow engine. The question is how to build something similar for business use cases beyond software engineering.
The Core Architecture: Deterministic Nodes and Agentic Nodes
The most important concept in any structured AI workflow engine is the distinction between deterministic nodes and agentic nodes. Getting this right is what separates reliable automation from unpredictable chaos.
Deterministic Nodes: Do the Same Thing Every Time
A deterministic node performs a fixed, predictable operation. Given the same input, it always produces the same output. There’s no AI involved — these are pure logic steps.
Examples of deterministic nodes:
- Fetch data from an API
- Format a date or string
- Apply a business rule (e.g., “if revenue > $10k, assign to enterprise tier”)
- Write a record to a database
- Send a webhook
- Validate that a field matches a pattern
Deterministic nodes are the backbone of any reliable workflow. They don’t drift, hallucinate, or produce unexpected outputs. They’re cheap to run and fast to debug.
Agentic Nodes: Reason, Decide, Generate
An agentic node is where the AI lives. These steps require reasoning, generation, or judgment — things that can’t be hard-coded.
Examples of agentic nodes:
- Summarize a customer support ticket
- Classify the intent of an email
- Generate a draft response
- Extract structured data from unstructured text
- Decide which workflow branch to follow based on context
- Write a code change based on a bug description
Agentic nodes are more powerful than deterministic nodes, but they’re also less predictable. The structured harness approach wraps them in constraints — input schemas, output validators, fallback rules — so they can’t go too far off the rails.
Why the Separation Matters
The instinct for most builders is to use AI for everything. If you have an LLM available, why not route all decisions through it?
The problem is that AI introduces variance. Every additional agentic step is a place where the workflow can produce unexpected output. If you have ten agentic steps chained together with no deterministic checks in between, errors compound. You don’t know where things went wrong, and you can’t reliably fix them.
Stripe’s approach — and the right approach for any production workflow engine — is to be deliberate about where AI reasoning is actually needed. Use deterministic logic wherever possible, and only introduce agentic steps when judgment or generation is genuinely required.
Designing Your Workflow Engine: Five Core Components
Building a structured AI workflow engine isn’t a single engineering task. It’s five distinct systems that need to work together. Here’s what each one does and how to think about building it.
1. The Task Router
The task router is the entry point for your workflow engine. Its job is to take incoming tasks — from whatever source triggers your system — and route them to the right workflow template.
A task might come from:
- An email or support ticket
- A webhook from another system
- A scheduled job
- A user input
- An output from a previous workflow
The router needs to classify the task and determine which workflow to run. This can be deterministic (a simple if/else based on task type) or agentic (using an LLM to classify ambiguous inputs). For most use cases, start with deterministic routing and only introduce AI classification when you genuinely need it.
What to build:
- An intake interface (API endpoint, email listener, webhook receiver)
- A routing table that maps task types to workflow templates
- Logging that captures every routing decision and its source
2. The Workflow Orchestrator
The orchestrator is the engine that runs workflow templates. It takes a workflow definition — a sequence of nodes — and executes them in order, passing outputs from one step as inputs to the next.
Key orchestrator requirements:
- State management — track where a workflow is at any point in time
- Error handling — if a node fails, what happens next?
- Retry logic — should the system retry failed steps? How many times?
- Parallelism — can some steps run concurrently to reduce latency?
- Timeout management — agentic steps can run long; the orchestrator needs to handle timeouts
The orchestrator is the most complex part of the system to build from scratch. This is where existing workflow platforms (or frameworks like LangChain, LlamaIndex, or purpose-built tools) can save significant time.
3. The Context Manager
AI models are only as good as the context they receive. The context manager’s job is to assemble the right information for each agentic node — nothing more, nothing less.
Overstuffing the context is a common mistake. More context isn’t always better. Irrelevant information increases token costs, degrades model performance, and makes outputs harder to validate.
Context management best practices:
- Define precisely what each agentic node needs to know
- Fetch only that information, not everything you have
- Structure the context clearly (labeled sections, consistent formatting)
- Strip out sensitive data that the model doesn’t need
- Keep a record of what context was provided for each run
4. The Output Validator
This is the most underrated component. After an agentic node runs, you need to check that what came back is actually usable before passing it to the next step.
Validators can operate at multiple levels:
Schema validation — Is the output in the expected format? If you asked for JSON with specific fields, did you get that?
Business logic validation — Does the output make sense in context? A sentiment classifier that always returns “neutral” regardless of input is technically producing valid output but is clearly broken.
Confidence thresholds — Some models can return confidence scores. You can reject outputs below a threshold and route them to human review.
Adversarial checks — For sensitive workflows, validate that the output doesn’t contain anything unexpected (e.g., a code generation system shouldn’t produce SQL that drops tables).
5. The Escalation and Feedback System
No AI system is perfect. The escalation system handles cases where the workflow can’t complete automatically — either because validation failed, confidence was too low, or a step returned an error.
Escalation paths typically include:
- Retry with modified context — add more information and try again
- Route to a different model — some tasks work better with one model than another
- Queue for human review — surface the task to a human with enough context to handle it quickly
- Fail gracefully — if none of the above works, log the failure and notify the right person
The feedback system closes the loop. When a human reviews and approves or rejects an AI output, that signal should feed back into your system. Over time, this data can be used to improve prompts, tune routing rules, or identify which task types need better context.
Building the Node Library: What Goes in Each Node
Once you have the five core components, you need to populate your node library — the actual building blocks that get assembled into workflow templates.
Deterministic Node Types
Data fetchers — Pull information from external systems. A CRM lookup, a database query, an API call. These should handle auth, rate limiting, and error responses cleanly.
Data transformers — Take an input and convert it. Parsing dates, normalizing strings, mapping fields between schemas. These should be pure functions with no side effects.
Conditional branches — Evaluate a condition and route the workflow accordingly. If/else logic based on deterministic rules. Use these heavily — they’re cheap and reliable.
Write operations — Create, update, or delete records in external systems. These need idempotency — if the step runs twice, it shouldn’t create two records.
Notification senders — Send emails, Slack messages, webhooks. These are write operations with their own failure modes (delivery failures, rate limits, bad addresses).
Agentic Node Types
Classifiers — Take an input and assign it to a category. Sentiment analysis, intent detection, topic tagging, priority scoring. These are often the first agentic step in a workflow.
Extractors — Pull structured data from unstructured text. Extract names, dates, dollar amounts, action items from a document or email. Output should always be validated against a schema.
Generators — Produce new content based on input. Draft an email, write a summary, create a code snippet. These need the most careful prompt engineering and output validation.
Decision makers — Given a set of options and context, choose one. Which template to use, which team to assign to, whether to approve or reject. These should always log their reasoning.
Tool users — Agentic nodes that call external tools — search, calculators, code interpreters — to complete a task. These are the most complex and need robust error handling.
Prompt Engineering for Structured Workflows
In a structured workflow engine, prompts aren’t just text you paste into a chat interface. They’re code. They need to be versioned, tested, and maintained like any other part of your system.
Write Prompts as Templates
Every agentic node should have a prompt template with clearly defined variable slots. Something like:
You are reviewing a customer support ticket for a B2B SaaS company.
**Ticket category:** undefined
**Customer tier:** undefined
**Ticket content:**
undefined
Your task: Classify the urgency of this ticket as HIGH, MEDIUM, or LOW.
Return only a JSON object with the following fields:
- urgency: "HIGH" | "MEDIUM" | "LOW"
- reason: a one-sentence explanation
The template makes it easy to see exactly what the model receives, test with different inputs, and update the prompt without touching application logic.
Use Structured Output Formats
Whenever possible, ask models to return structured data — JSON, YAML, or another parseable format — rather than free text. This makes output validation much simpler.
Most modern LLMs support JSON mode or function calling, which constrains the output to a specific schema. Use these features. They significantly reduce validation complexity and model failure rates.
Version Your Prompts
Treat prompts like code. When you change a prompt, log the change. Track which version of a prompt was used for each workflow run. This makes debugging possible — if your workflow starts producing bad outputs after a prompt update, you can roll back.
Test Prompts With a Fixture Set
Before deploying a new prompt or prompt version, run it against a fixed set of test inputs with known correct outputs. This is the equivalent of unit tests for your AI layer. It won’t catch everything, but it will catch obvious regressions.
Applying the Pattern to Real Business Use Cases
Stripe used their workflow engine for software engineering. But the same architecture applies to almost any business process that involves information processing, classification, generation, or decision-making.
Customer Support Triage
A customer support workflow engine might work like this:
- Deterministic — Receive incoming ticket via API
- Deterministic — Look up customer record in CRM
- Agentic — Classify ticket intent and urgency
- Deterministic — Branch based on urgency: high urgency goes to human queue, others continue
- Agentic — Generate draft response based on ticket content and knowledge base
- Deterministic — Validate draft response against content policy
- Deterministic — Route to agent review queue with draft pre-filled
- Agentic (optional) — If the ticket matches a known pattern with high confidence, send automatically
This workflow reduces the time agents spend on routine tickets while keeping humans in the loop for complex or high-risk cases.
Sales Qualification
A B2B sales workflow engine might handle inbound leads like this:
- Deterministic — Receive lead from web form or enrichment API
- Deterministic — Look up company data (size, industry, existing customer status)
- Agentic — Score the lead based on fit criteria using retrieved data
- Deterministic — Apply scoring threshold: high-score leads go to sales, low-score leads go to nurture
- Agentic — Draft a personalized outreach email based on lead data
- Deterministic — Check email against brand guidelines and compliance rules
- Deterministic — Schedule send via email platform
This kind of workflow can process hundreds of inbound leads per day without any manual work for the majority of cases.
Content Operations
A content team might use a workflow engine to handle content production at scale:
- Deterministic — Pull a content brief from a project management tool
- Agentic — Research relevant sources using web search
- Agentic — Generate a structured outline
- Deterministic — Route outline for human approval
- Agentic — Generate draft sections based on approved outline
- Agentic — Check draft against SEO requirements and brand voice guidelines
- Deterministic — Publish to CMS draft queue for final human review
Each agentic step is bounded and validated. The humans in the loop aren’t replacing AI — they’re quality-checking specific high-stakes steps.
Code Review and Quality Assurance
This is closest to what Stripe built. A software engineering workflow engine might:
- Deterministic — Receive new PR from GitHub webhook
- Deterministic — Fetch changed files and test results
- Agentic — Review code for bugs, security issues, style violations
- Agentic — Generate inline review comments
- Deterministic — Validate that comments reference real line numbers
- Agentic — Generate summary review comment
- Deterministic — Post review via GitHub API
Teams that have implemented versions of this report significant reductions in review cycle time, with engineers saying AI-generated reviews often catch issues they would have missed.
Where MindStudio Fits in This Architecture
Building a structured AI workflow engine from scratch is feasible for engineering teams with the time and resources to do it. But for most businesses — and even many technical teams — the infrastructure work (orchestration, state management, error handling, integrations) is the hard part, and it’s not where you want to spend your energy.
This is where MindStudio provides a meaningful shortcut. MindStudio is a visual platform for building structured AI workflows exactly like the ones described in this article. You can build workflows with a mix of deterministic and agentic nodes — connecting to real business systems without writing the underlying infrastructure code.
How It Maps to the Architecture
The task router — MindStudio supports webhook/API endpoint agents, email-triggered agents, and scheduled agents. You can point any incoming trigger at a MindStudio workflow without building a custom intake system.
The workflow orchestrator — The visual builder handles sequencing, branching, and state management. You define the nodes and connections; MindStudio handles execution, retries, and error routing.
The context manager — You control exactly what information flows into each AI step. MindStudio has 1,000+ pre-built integrations, so pulling CRM data, looking up a customer record, or fetching a knowledge base article is a configuration step, not a coding task.
The output validator — You can add conditional branches that validate AI outputs before proceeding. If an AI classifier returns an unexpected value, a deterministic branch can catch it and route appropriately.
Escalation paths — MindStudio workflows can send notifications via Slack or email, create tasks in project management tools, or surface items for human review — all as deterministic steps triggered by validation failure.
200+ Models, No Infrastructure
One practical advantage: MindStudio gives you access to 200+ AI models — Claude, GPT-4o, Gemini, and others — without managing API keys, rate limits, or billing for each one separately. For a workflow engine that might use different models for different node types (a fast, cheap model for classification; a more capable model for generation), this matters.
You can try MindStudio free at mindstudio.ai — most workflows take 15 minutes to an hour to build, and you can connect to your existing tools without any infrastructure setup.
Common Mistakes When Building AI Workflow Engines
Teams new to this architecture tend to make the same set of mistakes. Knowing them in advance saves a lot of frustration.
Making Everything Agentic
It feels natural to reach for AI at every step, but it’s expensive, slow, and unpredictable. Map out your workflow and ask: “Does this step genuinely require reasoning or generation?” If the answer is no, make it deterministic. Reserve AI for the steps where it actually adds value.
Skipping Output Validation
This is the most common mistake. Teams wire up an agentic node, see it produce good output in testing, and assume it’ll always work. In production, LLMs produce unexpected outputs regularly — especially as input data gets messier and more varied than your test cases. Build validators for every agentic step before deploying to production.
Building Monolithic Workflows
The temptation is to build one big workflow that handles everything. This makes debugging nearly impossible. When a step fails, you need to trace exactly where it went wrong. Build modular workflows — each one handles a specific task type — and compose them.
Ignoring Latency
Agentic steps take time. A workflow with five LLM calls chained sequentially might take 30-60 seconds to complete. For use cases where speed matters (customer-facing interactions, real-time decisions), design your workflow to minimize sequential AI steps. Use parallelism where possible, and consider which steps can be moved to async background processing.
Not Logging Enough
When something goes wrong, you need to be able to reconstruct exactly what happened. Log every step input and output, the model version used, the prompt version used, and the time taken. This seems like overkill until the first time something goes wrong in production and you have no idea why.
Treating Prompts as Afterthoughts
Prompts in a production workflow engine are critical code. They should be version-controlled, reviewed, tested, and deployed with the same rigor as application code. Teams that treat prompts as quick text snippets inevitably end up with prompt debt — a collection of fragile, inconsistent instructions that nobody fully understands.
Operational Considerations: Running a Workflow Engine in Production
Getting a workflow engine to work is one thing. Running it reliably in production is another.
Cost Management
LLM costs compound quickly when you’re running thousands of workflow executions per day. A few practices that help:
- Cache deterministic results — If multiple workflows need the same data (e.g., the same customer record), cache it rather than fetching it multiple times.
- Right-size models to tasks — Use smaller, faster models for simple classification tasks. Only use expensive, capable models when the task genuinely requires it.
- Monitor token usage per node — Identify which agentic nodes are consuming the most tokens and look for opportunities to reduce context size.
- Set budget alerts — Get notified when daily or monthly spend exceeds a threshold, before it becomes a problem.
Reliability and Uptime
LLM APIs go down, return errors, and experience latency spikes. Your workflow engine needs to handle this gracefully:
- Implement exponential backoff — Don’t hammer a failing API. Wait and retry with increasing delays.
- Use circuit breakers — If an API is consistently failing, stop sending requests for a period and alert the team.
- Design for idempotency — If a workflow step runs twice due to a retry, it should produce the same result without side effects.
- Build a dead letter queue — Failed workflows should land somewhere they can be inspected and rerun, not disappear silently.
Monitoring and Observability
You need visibility into what your workflow engine is doing at all times:
- Track success rate per workflow template — If a specific workflow’s success rate drops, investigate immediately.
- Monitor AI output quality — This is harder to automate, but regular sampling of AI outputs for human review helps catch quality degradation.
- Alert on escalation rate — If the rate at which tasks escalate to human review increases sharply, something has changed in your input distribution or model behavior.
- End-to-end latency tracking — Monitor how long each workflow takes to complete. Significant increases often indicate API issues or context bloat.
Frequently Asked Questions
What is a structured AI workflow engine?
A structured AI workflow engine is a system that combines deterministic logic (fixed, rule-based steps) with agentic AI steps (where a model reasons, generates, or decides) in a controlled, validated sequence. Rather than passing raw prompts to an LLM and hoping for usable output, a structured workflow engine wraps every AI interaction in constraints — defined inputs, validated outputs, error handling, and escalation paths. The result is AI automation that’s reliable enough to run in production on real business processes.
How is this different from just using ChatGPT or an LLM API directly?
Using an LLM API directly gives you a model that takes text and returns text. That’s useful for one-shot tasks, but it doesn’t give you orchestration, state management, error handling, or integration with external systems. A workflow engine adds all of that. It determines what information gets sent to the model, validates what comes back, connects to your business tools, handles failures, and keeps a record of what happened. The model is just one component in a larger system.
What’s the difference between deterministic and agentic nodes?
A deterministic node performs a fixed operation — the same input always produces the same output. Fetching a database record, applying a business rule, formatting a string: these are deterministic. An agentic node uses an AI model to reason, generate, or decide — the output depends on the model’s interpretation of the input. Classifying an email, drafting a response, extracting data from unstructured text: these are agentic. Good workflow design uses deterministic nodes wherever possible and reserves agentic nodes for steps where AI genuinely adds value.
Do I need to be an engineer to build an AI workflow engine?
Not necessarily. Platforms like MindStudio make it possible to build structured AI workflows without writing code — you connect nodes visually and configure each step’s inputs, outputs, and behavior. That said, understanding the underlying concepts (deterministic vs. agentic steps, output validation, escalation paths) will make you a much more effective builder regardless of the tool you use.
How do I know when to use AI vs. deterministic logic in a workflow?
Ask this question for every step: “Could this be done correctly with a simple rule, lookup, or calculation?” If yes, make it deterministic. Only use an agentic (AI) step when the task genuinely requires understanding, generation, or judgment that can’t be coded with fixed rules. Common cases for AI: classifying ambiguous inputs, extracting information from unstructured text, drafting content, making nuanced decisions. Common cases for deterministic logic: fetching data, applying thresholds, routing based on known categories, formatting outputs.
How does Stripe’s Minions system handle errors and edge cases?
Stripe has indicated that the Minions system includes confidence thresholds and escalation paths — when the AI’s output doesn’t meet a confidence threshold or when validation fails, the task is routed to human review rather than proceeding automatically. This keeps the 70% of PRs that merge without modification from pulling the other 30% along with them. The system learns over time which task types it can handle reliably and which ones need more human involvement. The key insight is that the system is designed to fail gracefully, not just to succeed in the average case.
Key Takeaways
Building a structured AI workflow engine is an engineering discipline, not a prompt-writing exercise. Here’s what matters:
- Separate deterministic and agentic nodes — Use AI where it’s needed, not everywhere. Deterministic steps are cheaper, faster, and more reliable.
- Validate every agentic output — Don’t assume the model’s response is usable. Check the format, the content, and the business logic before proceeding.
- Build modular workflows — Small, focused workflow templates are easier to debug, test, and improve than monolithic pipelines.
- Treat prompts as code — Version them, test them, and review changes with the same rigor as application code.
- Design for failure — Retry logic, escalation paths, and dead letter queues aren’t optional in production systems.
- Log everything — When something goes wrong, you need to reconstruct exactly what happened. Comprehensive logging is the only way to do that.
The Stripe Minions system represents what’s possible when these principles are applied rigorously at scale. But the same architecture — applied to customer support, sales, content operations, or any other business process — can produce similar results for organizations orders of magnitude smaller than Stripe.
If you want to start building without setting up your own infrastructure, MindStudio gives you the visual tools to build exactly this kind of structured workflow, with 200+ AI models and 1,000+ business tool integrations ready to go. You can build your first workflow in an afternoon and have it running in production the same day.