Capabilities
A support generator (a block that calls a model) that answers questions about orders needs the order data, a note in its prompt on how to use that data, and a tool that looks an order up. The data lives in a resource, which is named, stored data a block declares. Wire them by hand and every generator that touches orders repeats the same edits. Adding a second tool means finding all of them again.
A capability is those pieces packaged under one name. A block lists it in uses and gets everything the capability carries. The examples are a support desk with an orders capability.
A capability, defined once
The capability carries a resource, a section of prompt context, and a tool the model can call. The context and the tool sit in named presets, which a block can switch on and off. default lists the presets that are on unless a block says otherwise.
import { handler } from "@flow-state-dev/core";
import { z } from "zod";
export const lookUpOrder = handler({
name: "lookUpOrder",
inputSchema: z.object({ orderId: z.string() }),
outputSchema: z.object({ status: z.string() }),
execute: async (input) => ({ status: `Order ${input.orderId} has shipped.` }),
});
import { defineCapability, defineResource } from "@flow-state-dev/core";
import { z } from "zod";
import { lookUpOrder } from "../tools/look-up-order";
const orderLog = defineResource({
scope: "session",
stateSchema: z.object({ lastOrderId: z.string().nullable().default(null) }),
});
export const orders = defineCapability({
name: "orders",
resources: { orderLog },
presets: {
context: { context: "Quote the order number whenever you mention an order." },
tools: { tools: [lookUpOrder] },
default: ["context", "tools"],
},
});
lookUpOrder is a block the model calls as a tool, and it lives in its own file beside the flow. orderLog is session-scoped, so each session gets its own record.
One line in the block
The generator lists the capability and nothing else.
import { generator } from "@flow-state-dev/core";
import { z } from "zod";
import { orders } from "../capabilities/orders";
export const draftReply = generator({
name: "draftReply",
model: "openai/gpt-6-luna",
prompt: "Answer the customer's question about their order.",
inputSchema: z.string(),
user: (input) => input,
uses: [orders],
});
draftReply has the orderLog resource, the context section in its prompt and lookUpOrder in its tool list. A flow that includes draftReply gets the resource from the block, so the flow declares nothing. Every kind of block takes uses, but context and tools are for generators: a capability that brings them to any other block fails when that block is built.
Turning a part off
An order summarizer that should see the order context but never call a tool switches the tools preset off for that block.
import { generator } from "@flow-state-dev/core";
import { z } from "zod";
import { orders } from "../capabilities/orders";
export const summarizeOrder = generator({
name: "summarizeOrder",
model: "openai/gpt-6-luna",
prompt: "Summarize the order in one sentence.",
inputSchema: z.string(),
user: (input) => input,
uses: [orders.with({ tools: false })],
});
.with() returns a new capability and leaves orders alone, so draftReply keeps its tool. A misspelled preset name throws. The Reference page lists every key .with() accepts.
Tools a block names itself
A generator's tools: replaces the tools a capability would add. A capability's built-in controls, such as a skills loader, come through anyway.
import { generator } from "@flow-state-dev/core";
import { z } from "zod";
import { orders } from "../capabilities/orders";
import { issueRefund } from "../tools/issue-refund";
export const refundReply = generator({
name: "refundReply",
model: "openai/gpt-6-luna",
prompt: "Handle the refund request.",
inputSchema: z.string(),
user: (input) => input,
tools: [issueRefund],
uses: [orders],
});
issueRefund is another tool block, in tools/issue-refund.ts. The context section and the orderLog resource arrive, but lookUpOrder does not. Declaring tools: is what counts: tools: [] drops every capability tool except those built-in controls, and leaving tools: out means the capability's tools reach the model. To keep one, name it in the list yourself.
A capability that takes a value
When a capability needs a value at build time, such as which scope its resource has, export a function that returns the capability.
import { defineCapability, defineResource } from "@flow-state-dev/core";
import { z } from "zod";
import { lookUpOrder } from "../tools/look-up-order";
export function createOrdersCapability(options: { scope: "session" | "user" }) {
return defineCapability({
name: `orders:${options.scope}`,
resources: {
orderLog: defineResource({
scope: options.scope,
stateSchema: z.object({ lastOrderId: z.string().nullable().default(null) }),
}),
},
presets: { tools: { tools: [lookUpOrder] } },
});
}
scope: "session" keeps the order log for one session, and scope: "user" keeps it across a user's sessions. Every block that reads the order log must list a capability built with the same scope. Two calls with different arguments need different names, which is why the scope is in the name.
Who owns what it stores
A capability stores nothing itself. Its resource does, and the resource's scope decides who owns the data. With scope: "session", one orderLog exists per session, and the browser sees it only if the resource's client config exposes fields. Resources covers where it lives and how it is exposed.
What it gets you
- One edit reaches every block. Add a second tool to the
toolspreset and every generator that listsordershas it. - One line per block.
uses: [orders]brings the resource, the context and the tool, so no block repeats the wiring. - A block can opt out of one part.
orders.with({ tools: false })changes one block. The others keep their tools. - Types follow. A block that lists a capability sees the state and resources the capability declares in its
ctx, with no second declaration. - Mistakes show up when the block is built. Context or tools on a block that is not a generator, or two different capabilities with one name, fail before the first request.
How it fits with the others
A kit packages a whole feature, with its flows and screens, that an app installs with one config object. A kit can contain capabilities. A capability never contains a kit, because a block lists a capability in uses and an app installs a kit. Reach for a kit when the feature has screens or flows of its own, and a capability when you are bundling one ability for blocks.
Next
- Write a capability builds one step by step, with helper functions and presets.
- Kits and slots shows how a whole feature is packaged for an app.
- Generators and tools covers the tool list a capability adds to.
- Capabilities reference lists every field, preset rule, config option and limit.