/directive:building-ai-orchestratorsfrom directive
Builds AI orchestration systems using createAgentOrchestrator and createMultiAgentOrchestrator from @directive-run/ai. Define factsSchema, constraints, and resolvers for LLM-powered workflows, agent pipelines, and multi-agent coordination.
Ships in directive. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill applies when the project uses @directive-run/ai. If not found in package.json, suggest installing it: npm install @directive-run/ai.
createAgentOrchestrator or createMultiAgentOrchestratororchestrator.run() or orchestrator.runStream()testing-ai-systems skillhardening-ai-systems skillNeed AI orchestration?
├── Single agent doing one job → createAgentOrchestrator
│ ├── Simple: runner + factsSchema + init + resolvers
│ └── Complex: add constraints, retry, plugins
└── Multiple agents coordinating → createMultiAgentOrchestrator
├── Agents run in sequence → default sequential
├── Agents run in parallel → parallel: true on agents
└── Dynamic routing → coordinator constraints
import { createAgentOrchestrator } from "@directive-run/ai";
import { createAnthropicRunner } from "@directive-run/ai/anthropic";
import { t } from "@directive-run/core";
const orchestrator = createAgentOrchestrator({
runner: createAnthropicRunner({
model: "claude-opus-4-6",
apiKey: process.env.ANTHROPIC_API_KEY,
}),
// ALWAYS use t.*() builders – never TypeScript type annotations
factsSchema: {
input: t.string(),
output: t.string().optional(),
status: t.string<"idle" | "running" | "done" | "error">(),
attempt: t.number(),
error: t.string().optional(),
},
// init() is required – sets starting state
init: (facts) => {
facts.status = "idle";
facts.attempt = 0;
},
constraints: {
startProcessing: {
when: (facts) => facts.status === "idle" && facts.input.length > 0,
require: { type: "PROCESS_INPUT" },
},
retryOnError: {
priority: 10,
when: (facts) => facts.status === "error" && facts.attempt < 3,
require: { type: "PROCESS_INPUT" },
},
},
resolvers: {
processInput: {
requirement: "PROCESS_INPUT",
resolve: async (req, context) => {
context.facts.status = "running";
context.facts.attempt += 1;
const result = await context.runner.run({
prompt: context.facts.input,
system: "You are a helpful assistant.",
});
context.facts.output = result.text;
context.facts.status = "done";
},
},
},
});
// Execute
const result = await orchestrator.run({ input: "Summarize this text..." });
console.log(result.facts.output);
import { createMultiAgentOrchestrator } from "@directive-run/ai";
import { createAnthropicRunner } from "@directive-run/ai/anthropic";
import { t } from "@directive-run/core";
const orchestrator = createMultiAgentOrchestrator({
// Coordinator defines shared state across all agents
coordinator: {
factsSchema: {
topic: t.string(),
phase: t.string<"research" | "draft" | "review" | "done">(),
researchNotes: t.string().optional(),
draft: t.string().optional(),
finalOutput: t.string().optional(),
},
init: (facts) => {
facts.phase = "research";
},
},
agents: {
researcher: {
runner: createAnthropicRunner({ model: "claude-haiku-4-5" }),
// Per-agent schema – merged with coordinator facts
factsSchema: {
searchDepth: t.number(),
},
init: (facts) => {
facts.searchDepth = 3;
},
constraints: {
doResearch: {
when: (facts) => facts.phase === "research",
require: { type: "RESEARCH" },
},
},
resolvers: {
research: {
requirement: "RESEARCH",
resolve: async (req, context) => {
const result = await context.runner.run({
prompt: `Research this topic: ${context.facts.topic}`,
});
context.facts.researchNotes = result.text;
context.facts.phase = "draft";
},
},
},
},
writer: {
runner: createAnthropicRunner({ model: "claude-opus-4-6" }),
factsSchema: {
style: t.string(),
},
init: (facts) => {
facts.style = "professional";
},
constraints: {
writeDraft: {
when: (facts) => facts.phase === "draft" && !!facts.researchNotes,
require: { type: "WRITE" },
},
},
resolvers: {
write: {
requirement: "WRITE",
resolve: async (req, context) => {
const result = await context.runner.run({
prompt: `Write a ${context.facts.style} article based on: ${context.facts.researchNotes}`,
});
context.facts.draft = result.text;
context.facts.phase = "done";
},
},
},
},
},
});
const result = await orchestrator.run({ topic: "Quantum computing" });
console.log(result.facts.finalOutput);
// runStream() returns AsyncIterable<OrchestratorEvent>
const stream = orchestrator.runStream({ input: "Analyze this..." });
for await (const event of stream) {
switch (event.type) {
case "token": {
process.stdout.write(event.text);
break;
}
case "requirement_met": {
console.log(`Resolved: ${event.requirementType}`);
break;
}
case "done": {
console.log("Final:", event.facts);
break;
}
case "error": {
console.error("Failed:", event.error);
break;
}
}
}
import { createTask } from "@directive-run/ai";
const summarizeTask = createTask({
name: "summarize",
description: "Summarize text to a target length",
input: {
text: t.string(),
maxWords: t.number(),
},
output: {
summary: t.string(),
wordCount: t.number(),
},
// Tasks integrate into orchestrator resolvers
resolve: async (input, context) => {
const result = await context.runner.run({
prompt: `Summarize in ${input.maxWords} words: ${input.text}`,
});
return {
summary: result.text,
wordCount: result.text.split(" ").length,
};
},
});
// Use task inside a resolver
resolvers: {
summarize: {
requirement: "SUMMARIZE",
resolve: async (req, context) => {
const output = await summarizeTask.run(
{ text: context.facts.input, maxWords: 100 },
context
);
context.facts.summary = output.summary;
},
},
},
resolve: async (req, context) => {
context.facts // Read/write orchestrator facts
context.runner // Execute LLM calls
context.signal // AbortSignal for cancellation
context.emit(event) // Emit custom events to stream
context.plugins // Access plugin instances
}
// Primitives
t.string() // string
t.number() // number
t.boolean() // boolean
// Optional / nullable
t.string().optional() // string | undefined
t.string().nullable() // string | null
// Union literal types
t.string<"idle" | "running">() // typed string union
t.number<1 | 2 | 3>() // typed number union
// Objects and arrays
t.object<MyInterface>() // typed object
t.array(t.string()) // string[]
t.array(t.object<Item>()) // Item[]
// Record / map
t.record(t.string(), t.number()) // Record<string, number>
constraints: {
// Trigger on status transition
onIdle: {
when: (facts) => facts.status === "idle" && !!facts.input,
require: { type: "START" },
},
// Priority for conflict resolution (higher = wins)
emergency: {
priority: 100,
when: (facts) => facts.errorCount > 5,
require: { type: "ABORT" },
},
// Pass data in requirement
withPayload: {
when: (facts) => facts.ready,
require: (facts) => ({ type: "PROCESS", model: facts.preferredModel }),
},
}
// WRONG – TypeScript type annotations, not schema builders
factsSchema: {
status: "idle" | "running" | "done", // type annotation, not runtime schema
count: number,
}
// CORRECT – t.*() builders provide runtime validation + TypeScript inference
factsSchema: {
status: t.string<"idle" | "running" | "done">(),
count: t.number(),
}
// WRONG – facts start undefined, constraints fail immediately
const orchestrator = createAgentOrchestrator({
factsSchema: { status: t.string() },
// missing init: facts.status is undefined
constraints: {
start: { when: (facts) => facts.status === "idle", ... },
},
});
// CORRECT
init: (facts) => {
facts.status = "idle";
},
Always use (req, context) – never (req, ctx) or (request, context).
// WRONG
when: (facts) => facts.status === "idle" ? true : false,
// CORRECT – always use multi-line blocks when branching
when: (facts) => {
return facts.status === "idle";
},
// WRONG – direct mutation bypasses reactivity
orchestrator.facts.status = "done";
// CORRECT – always via context.facts inside resolvers
resolve: async (req, context) => {
context.facts.status = "done";
},
ai-orchestrator.md – Full createAgentOrchestrator API, options, lifecycleai-multi-agent.md – createMultiAgentOrchestrator, coordinator pattern, agent communicationai-tasks.md – createTask API, task composition, input/output validationexamples/ai-orchestrator.ts – Complete single-agent exampleexamples/ai-checkpoint.ts – Checkpoint/resume patternexamples/fraud-analysis.ts – Multi-agent fraud detection exampleWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub directive-run/directive --plugin directive12 skills in this plugin
/building-ai-agentsConfigure AI provider runners (Anthropic, OpenAI, Ollama), stream tokens and structured output, and wire cross-agent communication. Use when setting up LLM provider connections, implementing token streaming, choosing between providers, or building agents that communicate results to each other./building-directive-systemsCompose Directive modules into systems: single-module and multi-module createSystem() calls, namespaced fact/derive/event access, cross-module dependencies, initialFacts and hydration, plugins (logging, devtools, persistence, circuit breaker), React adapter hooks (useSelector, useEvent, useSystem, DirectiveProvider), and system lifecycle. Use when creating a system, connecting modules together, adding plugins, or integrating Directive with React./getting-started-with-directiveUnderstand Directive fundamentals: what modules, facts, derivations, constraints, resolvers, and systems are, and how they fit together. Use when someone is new to Directive, asks 'what is Directive', wants to understand the mental model, or needs help choosing between Directive concepts./hardening-ai-systemsAdd guardrails (input/output validation), memory strategies, token budgets, PII detection, prompt injection prevention, and circuit breakers to AI orchestrators. Use when enforcing content policies, managing costs, preventing security vulnerabilities, adding resilience, or implementing agent memory across turns./migrating-to-directiveMigrate state management code from Redux, Zustand, XState, MobX, Recoil, or Jotai to Directive. Provides concept mapping, step-by-step migration patterns, and before/after code examples. Use when asked to migrate, convert, or port existing state management to Directive./reviewing-directive-codeReview Directive code for anti-patterns, naming violations, missing error boundaries, constraint/resolver misuse, and performance issues. Use when asked to review, audit, or improve existing Directive modules, systems, or orchestrators.