Function createCommitAction

Creates a commit action handler that executes actions and modifies system state (WRITE pattern).

Execution flow:

  1. Checks if agent hasn't changed during execution
  2. If validateParams provided: validates parameters
    • If invalid: commits error message → executes failureMessage (or error message) → stops
  3. Calls executeAction to perform the action (wrapped in trycatch)
    • If executeAction throws: calls fallback handler (if provided) → commits error message → executes failureMessage → stops
  4. Commits action result (or emptyContent if result is empty)
  5. Executes successMessage via executeForce

If validation, action execution, commit, or execution operations fail

// Create payment handler with error handling
const handlePayment = createCommitAction({
fallback: (error, clientId, agentName) => {
logger.error("Payment execution failed", { error, clientId, agentName });
},
validateParams: async ({ params, clientId, agentName, toolCalls }) => {
if (!params.amount) return "Amount is required";
return null;
},
executeAction: async (params, clientId) => {
await commitAppAction(clientId, "payment", params);
return "Payment processed successfully";
},
emptyContent: () => "Payment failed - no result",
successMessage: "Check your balance",
failureMessage: "Payment validation failed",
});
// Usage: called internally by addCommitAction
await handlePayment("tool-123", "client-456", "PaymentAgent", "pay", { amount: 100 }, [], true);
  • Type Parameters

    • T = Record<string, any>

      The type of parameters expected by the action

    Parameters

    Returns (
        toolId: string,
        clientId: string,
        agentName: string,
        toolName: string,
        params: T,
        toolCalls: IToolCall[],
        isLast: boolean,
    ) => Promise<void>

    Handler function that executes the action with validation