Skip to content

upstash/workflow-js / skills

upstash-workflow-js

Unverified

Lightweight guidance for using the Upstash Workflow SDK to define, trigger, and manage workflows. Use this Skill whenever a user wants to create workflow endpoints, run steps, or interact with the Upstash Workflow client.

FileKindSize
SKILL.mdskill md2.2 KB
agents.mdmarkdown6.7 KB
basics/client.mdmarkdown4.1 KB
basics/context.mdmarkdown5.1 KB
basics/serve.mdmarkdown2.4 KB
features/flow-control.mdmarkdown3.9 KB
features/invoke.mdmarkdown2.6 KB
features/retries-failures-reliability.mdmarkdown6.3 KB
features/wait-for-event.mdmarkdown2.8 KB
features/webhooks.mdmarkdown2.5 KB
how-to/local-dev.mdmarkdown3.2 KB
how-to/middleware.mdmarkdown4.7 KB
how-to/migrations.mdmarkdown4.8 KB
how-to/realtime.mdmarkdown4.8 KB
rest-api.mdmarkdown6.6 KB
troubleshooting.mdmarkdown4.8 KB

features/invoke.md

View on GitHub
# 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:

```ts
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.

```ts
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.

```ts
// 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

```ts
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.
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall