All skills
upstash avatar

/upstash-workflow-js

@36daab8
by upstashupstash/skills27 stars
7

Work with the @upstash/workflow TypeScript/JavaScript SDK for durable, long-running workflows in serverless functions, multi-step processes that survive timeouts, retries, and restarts (built on QStash). Use when defining a workflow endpoint with serve(), running steps with context.run, sleeping for minutes to days without holding a function open, calling external APIs with context.call, waiting for an external event or webhook, invoking other workflows, configuring retries, failure callbacks, and a DLQ, controlling concurrency, rate, and parallelism, triggering, cancelling, or inspecting runs with the Workflow client, building AI agents and orchestrators, human-in-the-loop approvals, realtime updates, local development with the QStash dev server, adding middleware, or migrating workflows safely. Also use when the user asks for durable execution, step functions, saga or orchestration patterns, background jobs with checkpoints, or long-running tasks on Vercel, Next.js, Cloudflare Workers, or other serverless platforms.

Use this Skill: https://skilld.dev/gh/upstash/skills/upstash-workflow-js

This session only. Nothing lands on disk.

featuresinvoke.md

≈678 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Workflow Invocation

This documentation covers how to invoke one workflow from another using context.invoke, along with how to define and expose multiple workflows using createWorkflow and serveMany.


Invoking Another Workflow

A workflow can start another workflow run and wait for it to finish before continuing. This enables orchestration and dependency chains across workflows.

Use context.invoke to trigger another workflow:

const result = await context.invoke("analyze content", {
  workflow: analyzeContent, // workflow object or function
  body: "input payload", // request body passed to invoked workflow
  headers: { "x-user": "123" }, // optional headers
  retries: 5, // optional, default 3
  flowControl: {
    /* ... */
  },
  workflowRunId: "optional-custom-id",
});

const {
  body, // response returned by invoked workflow
  isFailed, // true if invoked workflow failed
  isCanceled, // true if invoked workflow was canceled
} = result;

Returning a Value

A workflow may return any serializable value, which becomes body for the caller.

Depth Limitation

Workflow invocation depth is limited to 100. Any recursive or cyclic chain exceeding this will fail.


Defining Workflows Without Exposing Endpoints

Use createWorkflow to define workflows as objects. These are not automatically exposed as HTTP endpoints.

const analyzeContent = createWorkflow(async (context) => {
  await context.sleep("delay", 1);
  return { message: "processed" };
});

const processUser = createWorkflow(async (context) => {
  const { body } = await context.invoke("invoke analyze", {
    workflow: analyzeContent, // type‑safe invocation
    body: "user-1",
  });

  return { result: body };
});

Exposing Multiple Workflows With serveMany

To allow workflows to invoke each other without requiring explicit URLs, define all related workflows under a shared parent path.

// app/workflows/[...any]/route.ts
export const { POST } = serveMany({
  analyze: analyzeContent,
  process: processUser,
});
  • Keys become route names.
  • All workflows that need to invoke each other must appear in the same serveMany call.
  • Requests are routed based on the key names.

Triggering a Workflow

import { Client } from "@upstash/workflow";

const client = new Client({ token: "<QSTASH_TOKEN>" });

await client.trigger({
  url: "https://your-app/workflows/analyze",
});

Common Pitfalls

  • Missing workflow in serveMany: If a workflow invokes another that was not included in the same serveMany definition, the call will fail.
  • Infinite invocation loops: Depth limit of 100 prevents runaway recursive chains.

Source: SKILL.md on GitHub

1 warning17d3 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill is a comprehensive documentation and implementation guide for the Upstash Workflow SDK. It covers durable serverless workflows, agent orchestration, and reliability features. All identified external resources and tool downloads are official components of the Upstash platform or well-known development services. No security issues or malicious patterns were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: MEDIUM · 1 issue

Signed by skilld at 36daab8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last month
metadata
{
  "author": "Upstash",
  "homepage": "https://upstash.com"
}

README badge

README badge for upstash/skills/upstash-workflow-js