The world of automation is getting smarter. We're moving beyond simple, brittle scripts and into the era of intelligent, agentic workflows. These AI-powered systems can reason, plan, and execute complex tasks. But for an AI agent to be effective, it needs a toolbox of reliable, well-defined tools. How do you give an AI a tool to "process a payment" or "send an invoice" without exposing your entire system's complexity?
The answer lies in a powerful concept: the atomic action.
This is the core philosophy behind action.do. Instead of building monolithic services or tangled functions, you encapsulate every piece of business logic into a reliable, scalable, and observable atomic action. These actions become the fundamental building blocks for sophisticated business automation and agentic systems.
Let's dive in and build our first action, transforming a simple piece of business logic into a flawless, executable API endpoint.
Before we code, let's clarify the concept. Think of an atomic action as a specialist. It does one thing, and it does it perfectly.
An atomic action on the .do platform is a self-contained, single-purpose function that performs one specific task, like sending an email or updating a database record.
This approach, which we call "Business As Code," has several key advantages over traditional serverless functions or microservices:
Let's take a common business task: processing a payment. We'll use the action.do SDK to define this logic as an atomic action.
Here's the code to define a process-payment action.
import { Do } from '@do-sdk/core';
// Define an atomic action to process a payment
const processPayment = Do.action('process-payment', {
inputs: {
customerId: 'string',
amount: 'number',
},
handler: async ({ inputs, context }) => {
// Connect to a payment provider like Stripe
console.log(`Processing payment of $${inputs.amount} for ${inputs.customerId}`);
// ... payment gateway logic here
// This is where you'd securely use an API key from the 'context'
// to call a third-party service.
// Return a structured result
return { success: true, transactionId: `txn_${context.runId}` };
},
});
Let's break down what's happening here:
Once defined, your action is not just a piece of code; it's a live, secure API endpoint on the .do platform. You don't need to worry about servers, scaling, or deployment pipelines.
Here's how you (or an AI agent) would execute it:
// Execute the action securely via the .do API
const result = await processPayment.run({
customerId: 'cust_12345',
amount: 49.99,
});
console.log(result);
// Expected Output:
// { success: true, transactionId: 'txn_a1b2c3d4...' }
That's it. By calling .run(), you are instructing the .do platform to execute your logic in a secure, isolated environment with the provided inputs. The simple success or failure, along with any data returned, can now be used as the input for the next step in a process.
A single atomic action is useful, but the true power is unlocked when you combine them. An agentic workflow is simply a sequence of atomic actions orchestrated to achieve a larger goal.
Imagine a user asks an AI assistant: "Charge customer 'cust_12345' their $49.99 subscription fee and send them a receipt."
The AI can now use your a la carte menu of actions to build a workflow on the fly:
Agent Task: "I need to process a payment."
Agent Task: "The payment was successful. Now I need to send a receipt."
This is the essence of an agentic workflow. Instead of one giant, fragile script, you have a fleet of robust, single-purpose actions that an intelligent agent can orchestrate. If the payment fails, the agent could just as easily call a different action, like create-support-ticket.do.
This composable model turns your business logic into a flexible API for intelligence.
Q: How is an action.do different from a standard serverless function?
A: While similar in concept, an action.do is purpose-built for agentic systems and business automation. It includes native integration with the .do ecosystem for observability, state management, and composition, allowing you to treat business logic as a first-class citizen in your automation stack.
Q: Can actions call other actions?
A: To maintain atomicity, a single action is designed to perform one task. To orchestrate multiple actions, you use a workflow.do, which composes individual actions into a larger, stateful process. This promotes a clean separation of concerns and makes workflows easier to visualize and debug.
Q: What kind of logic can I run inside an action.do?
A: Anything you can code. Actions can perform data transformations, integrate with third-party APIs (e.g., Stripe, SendGrid), query databases, or even run machine learning models. It's designed to encapsulate any unit of business logic you have.
Ready to stop writing brittle scripts and start building the future of automation? Encapsulate your logic, execute it flawlessly, and build your first agentic workflow with action.do.