Fathym
Menu

Operation Patterns

An Operation is the strategy layer. It doesn't carry its own behavior the way a Capability does - it prescribes how behavioral holons collaborate inside a context. Each Operation has its own execution context: ctx.Capabilities, ctx.Agents, ctx.Operations, and ctx.Services contain only what the Operation registered.

The strategy layer

const Greet = Operation('Greet', 'Formats a greeting')
  .Input(z.object({ name: z.string(), formal: z.boolean().default(false) }))
  .Output(z.object({ greeting: z.string() }))
  .Execute(async (ctx) => ({
    greeting: ctx.Input.formal ? `Good day, ${ctx.Input.name}.` : `Hey ${ctx.Input.name}!`,
  }));

Sub-operations

Compose Operations from other Operations with .Operations({}), reached via ctx.Operations - a modular pipeline where each step stays whole.

const ProcessOrder = Operation('ProcessOrder', 'Validate then total')
  .Operations({ Validate: ValidateInputOp, Total: CalculateTotalOp })
  .Execute(async (ctx) => {
    await ctx.Operations.Validate(ctx.Input);
    return ctx.Operations.Total(ctx.Input);
  });

Composing Capabilities and Agents

.Capabilities({}) brings tools in; .Agents({}) brings AI collaborators in. The Operation reuses them without collapsing them.

const AnalyzeFile = Operation('AnalyzeFile', 'Read and review a file')
  .Capabilities({ ReadFile: FileReadCapability })
  .Agents({ Reviewer: CodeReviewAgent })
  .Execute(async (ctx) => {
    const file = await ctx.Capabilities.ReadFile({ path: ctx.Input.path });
    const reviewer = await ctx.Agents!.Reviewer({ code: file.contents });
    const notes = await reviewer.SendMessage('review for bugs');
    await reviewer.Close();
    return { notes };
  });

Full composition

One Operation can layer all of it at once - Services, sub-Operations, Capabilities, and Agents - declaring exactly what it needs and nothing more.

Running operations

Operations never execute standalone; they run inside a Steward, dispatched by a StewardRunner. Three forms:

// 1. Named - registered on a Steward
await StewardRunner(MyPlane).Run('ProcessOrder', input);

// 2. Inline - an Operation defined at the call site
await StewardRunner(MyPlane).Run(SomeOperation, input);

// 3. Pre-built - a Steward composed with .Operations({ ProcessOrder })

Governance attached to an Operation runs at the Operation level - independent of the Steward's defaults, per the no-aggregation rule.


On this page