Documentation menu
Documentation

Workflows

Use durable steps for multi-stage work that must survive retries, pauses, and human approval.

Start from a fresh project

This guide is self-contained. Create an empty Ayjnt project, then replace the starter agent with the files shown below. Run commands from the new project directory unless a step says otherwise.

terminal
bunx ayjnt new try-workflows --empty
cd try-workflows
bun install

# remove agents/alive once you are ready to add the guide's files

Co-located AgentWorkflow

Place workflow.ts beside agent.ts. Extend AgentWorkflow when the workflow should call back into the originating agent, report progress, update state, or wait for approval.

agents/review/workflow.ts
import {
  AgentWorkflow,
  type AgentWorkflowEvent,
  type AgentWorkflowStep,
} from "ayjnt/workflows";

type Params = { documentId: string };

export default class ReviewWorkflow extends AgentWorkflow<Params> {
  async run(
    event: Readonly<AgentWorkflowEvent<Params>>,
    step: AgentWorkflowStep,
  ) {
    const result = await step.do("analyze", async () => {
      return analyze(event.payload.documentId);
    });
    await step.reportComplete(result);
    return result;
  }
}

Start it from the agent

Co-location is the relationship: extend Ayjnt’s Agent and call this.workflow(params). Generated declarations carry the workflow payload type into the agent, so there is no agent-name generic, mixin, or binding string to repeat.

example
import { Agent, callable } from "ayjnt";

export default class ReviewAgent extends Agent {
  @callable()
  async start(documentId: string) {
    return this.workflow({ documentId });
  }
}

Run it and verify the result

Start the workflow from the agent UI and watch the workflow ID, durable steps, and completion callback appear.

terminal
bun run build
bun run dev

# the local app is now available at http://localhost:8787