Documentation menu
Documentation

Workflows

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

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