Skip to content

Allow defining workflows with declarative DSL / dispatch #29

@ianmacartney

Description

@ianmacartney

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.
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)
 )
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions