Build a workflow

Chain steps in one workflow file, each running code, a tool or an agent, so each step's result feeds the next.

Before you start

You need a project. See Create a project.

Build a workflow

  1. Add the workflow. Each step names a tool and builds its input from the run's input or an earlier step's result:
    workflows/split-bill.ts
    import { tool } from "veryfront/tool";import { step, workflow } from "veryfront/workflow"; type Bill = { bill: number; tip: number; people: number }; const addTip = tool({  id: "add-tip",  description: "Add a tip, in percent, to a bill.",  inputSchema: {    type: "object",    properties: { bill: { type: "number" }, tip: { type: "number" } },    required: ["bill", "tip"],    additionalProperties: false,  },  execute: async ({ bill, tip }) => ({ total: Math.round(bill * (1 + tip / 100) * 100) / 100 }),}); const splitEvenly = tool({  id: "split-evenly",  description: "Split a total between people.",  inputSchema: {    type: "object",    properties: { total: { type: "number" }, people: { type: "number" } },    required: ["total", "people"],    additionalProperties: false,  },  execute: async ({ total, people }) => ({ share: Math.round((total / people) * 100) / 100 }),}); export default workflow({  id: "split-bill",  description: "Add a tip to a bill and split it between people.",  steps: [    step("add-tip", {      tool: addTip,      input: (ctx) => {        const { bill, tip } = ctx.input as Bill;        return { bill, tip };      },    }),    step("split", {      tool: splitEvenly,      input: (ctx) => ({        total: (ctx["add-tip"] as { total: number }).total,        people: (ctx.input as Bill).people,      }),    }),  ],});
  2. Run it on your machine. --input is the run's input:
    Shell
    npx veryfront workflow run split-bill --input '{"bill": 84.5, "tip": 18, "people": 3}'
  3. Read the result: it prints "share": 33.24.
  4. Start the project with npm run dev (Work locally) and open Building blocks > Workflows in Studio. You should now see split-bill listed.

Try it in a sandbox

  1. Create a project

  2. Add the workflow

  3. Check it

Try it out

Next steps