get-convex / get-convex/workflow

Allow defining workflows with declarative DSL / dispatch

Open
#29 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
81
Forks
17
Avg merge
1d 3h
Merged PRs (30d)
4

Description

For agents whose top-level behavior is a pre-defined graph.

Desired features:
- Max depth / max loop iterations to avoid infinite loops
- Easy forking & joining
- join on all tasks in the workflow
- create a semaphore, add tasks, check if all tasks are done
- “Pause” for user input
- Read the output of any parent step, by name or by traversing graph
- Allow returning a status (e.g. expected failure) return value, and optionally a mutation handle to call exactly once and args for it (if you want more than the state in the graph journal)

## Sample syntax

- In the `s.doWhatTheLLMSaid` (brain) mutation, it does `addChild` for all LLM tool calls / other actions, waiting for them to finish before continuing. The whole loop could be run from a brain mutation.
- In the future, we could add inline mutation functions, since `.define` is registering a mutation & can get called as the step, with a cursor pointing to the step it should execute & with what context.

```tsx
import { WorkflowManager, workflowBrain, chain, loop, parallel } from "@convex-dev/workflow";

const workflow = new WorkflowManager(components.workflow, {
workpool: components.workpool, // you can share it between agents
});

// for conciseness
const s = internal.mySteps;

export const support = workflow.define({
name: "supportOrchestrator",
args: { userId: v.id("users"), initialComplaint: v.string() },
steps: chain()
.mutation(s.createThread) // args are typed as workflow initial args
.parallel([
chain().action(s.investigateUserHistory),
chain().action(s.detectProductOutage)
])
.loop({
maxIterations: 10,
steps: chain()
.action(s.askLLMWhatToDo)
.mutation(s.doWhatTheLLMSaid), // this step dispatches children
shouldContinue: s.askLLMToContinue
})
.action(s.askLLMForNextStep)
.mutation(s.updateStatusAndDispatch)
)
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.