Encapsulate Business Logic

Atomic Functions, Infinite Possibilities

Encapsulate your business logic into discrete, reusable functions. Execute them as simple API endpoints and compose them into powerful, automated services.

Join waitlist

function.do

import { Agent, property } from '@do-sdk/core';

// Define the structure for a line item in an order
interface LineItem {
  productId: string;
  quantity: number;
  unitPrice: number;
}

// Create an agent that encapsulates the 'calculateOrderTotal' function
export class OrderCalculator extends Agent {
  
  @property()
  async calculateOrderTotal(
    items: LineItem[], 
    taxRate: number
  ): Promise<{ subtotal: number; tax: number; total: number }> {
    
    // Calculate the subtotal from the items
    const subtotal = items.reduce(
      (acc, item) => acc + item.quantity * item.unitPrice, 0
    );

    // Calculate tax and the final total
    const tax = subtotal * taxRate;
    const total = subtotal + tax;

    // Return the detailed breakdown
    return { subtotal, tax, total };
  }
}

Deliver economically valuable work

Frequently Asked Questions

Do Work. With AI.