upstash/workflow-js / skills
upstash-workflow-js
UnverifiedLightweight 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 2.2 KB |
| agents.md | markdown | 6.7 KB |
| basics/client.md | markdown | 4.1 KB |
| basics/context.md | markdown | 5.1 KB |
| basics/serve.md | markdown | 2.4 KB |
| features/flow-control.md | markdown | 3.9 KB |
| features/invoke.md | markdown | 2.6 KB |
| features/retries-failures-reliability.md | markdown | 6.3 KB |
| features/wait-for-event.md | markdown | 2.8 KB |
| features/webhooks.md | markdown | 2.5 KB |
| how-to/local-dev.md | markdown | 3.2 KB |
| how-to/middleware.md | markdown | 4.7 KB |
| how-to/migrations.md | markdown | 4.8 KB |
| how-to/realtime.md | markdown | 4.8 KB |
| rest-api.md | markdown | 6.6 KB |
| troubleshooting.md | markdown | 4.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.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 471k | Updated | Claude CodeCodex | Verified | Install |
| 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: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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 available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |