In the world of workflow automation and agentic systems, the way we define and execute tasks is the bedrock upon which reliability is built. A complex business process, like onboarding a new customer or fulfilling an e-commerce order, is composed of many smaller steps. But the granularity of these steps—how you define a "task"—has profound implications for your system's resilience, auditability, and scalability.
Today, we're diving into two fundamental approaches to task definition: the monolithic composite task and the granular atomic action. Understanding the difference is key to moving from brittle scripts to robust, reliable Business-as-Code.
Many developers, when first automating a process, start by writing a single, large function or script. This is a composite task.
A composite task is a single function or unit of execution that performs multiple distinct business operations.
Consider a processNewOrder function. A composite version might look like this:
On the surface, this seems efficient. It's all in one place. But this monolithic approach is notoriously fragile and opaque, leading to common failure scenarios:
The modern approach, essential for building durable agentic workflows, is to break down composite tasks into their fundamental components. This is the world of atomic actions.
An atomic action is a single, indivisible operation that either completes successfully or fails entirely, leaving no partial state. It's one thing, done well.
Let's refactor our processNewOrder workflow using atomic actions:
A workflow orchestrator then calls these actions in sequence. This simple change unlocks massive benefits:
Shifting to an atomic action model requires a platform built for it. This is precisely why we created action.do. It provides the fundamental building block for your Business-as-Code, allowing you to define, execute, and audit atomic actions flawlessly.
Instead of writing complex, stateful functions, you define single-purpose actions and execute them with a simple, clean API call.
import { Do } from '@do-sdk/core';
// Initialize the .do client with your API key
const a = new Do(process.env.DO_API_KEY);
// Execute a specific, atomic action with parameters
const { result, error } = await a.action.execute({
name: 'send-welcome-email',
params: {
userId: 'usr_12345',
template: 'new-user-welcome-v2'
}
});
if (error) {
console.error('Action failed:', error);
} else {
console.log('Action Succeeded:', result);
}
With action.do, every piece of business logic becomes a reusable, independently executable, and fully auditable component. This is the foundation of a truly robust workflow automation strategy.
This isn't just a tagline; it's the lifecycle of a reliable system. By defining your business logic as a library of atomic actions, you gain the power to compose complex workflows that are transparent, resilient, and easy to maintain. action.do handles the reliable execution and auditing, so you can focus on the logic itself.
A workflow.do is simply the next layer up—an orchestration of one or more atomic action.do calls to achieve a larger business outcome. You start with the atoms to build the molecules.
By embracing atomic actions, you're not just changing how you write code; you're fundamentally changing how you build, observe, and manage your business processes.
What constitutes an 'atomic action'?
An atomic action is a single, indivisible operation that either completes successfully or fails entirely, leaving no partial state. Examples include sending a single email, making one API call, or writing a single record to a database.
Why is idempotency important for actions?
Idempotency ensures that executing the same action multiple times with the same parameters has the same effect as executing it once. This is crucial for building reliable systems that can recover from failures without causing unintended side effects, like sending duplicate invoices.
How does action.do relate to a workflow.do?
action.do represents the individual steps or building blocks. A workflow.do is a sequence or graph of these actions orchestrated to achieve a larger business outcome. You compose workflows from one or more atomic actions.
Can I define my own custom actions?
Yes. The .do platform allows you to define your own custom actions as functions or microservices, which can then be invoked via the action.do API. This turns your existing business logic into reusable, auditable components.