Skip to main content

Operations

In Scribe, operations define the actions a component can perform. These operations are essentially workflows themselves, giving you the flexibility to customize their behavior and control their execution sequence. This unique feature is what we call being "workflow-enabled".

An operation is primarily responsible for performing a particular action or functionality of a component. For instance, a Pipeline has a push operation which is responsible for adding workflows to the pipeline, or a runFor operation which executes the workflow for the given context.

Operations are highly configurable and allow you to define custom workflows for each operation. Each operation's workflow is a sequence of tasks, with the tail performing the core operation. However, the unique feature of these workflows is that you can add other tasks before the tail function, providing a layer of control before the operation's execution.

Currently, you must provide operation workflows explicitly:

import { Scribe } from "https://deno.land/x/scribeai/mod.ts";

// Create a new Scribe instance
const scribe = new Scribe();

const myPipeline = await scribe.createPipeline({
// Operations are defined using the `ops` option
ops: {
// Set up a dummy push operation workflow (a Task in this case)
// This operation is executed each time you `push` a workflow into this pipeline
push: async (_ctx, next) => {
await next();
},
// Set up a dummy runFor operation workflow (a Task in this case)
// This operation is executed each time the pipeline is run
runFor: async (_ctx, next) => {
await next();
},
},
});

This ability to augment operations with their own workflows allows developers to introduce additional logic, such as validation, logging, transformation, and even cancellation, before the actual operation takes place. This extends the flexibility of Scribe, allowing the developer to modify the standard behavior of operations to suit their application's unique requirements.

Embedding workflows into operations epitomizes Scribe's commitment to flexibility, customization, and control, providing developers with a rich, adaptable, and robust tool for crafting intricate and tailored workflows.