Install
openclaw skills install @jose-compu/cpa-agentsManage AI agent workflows using concurrent process algebra patterns like parallel tasks, branch-fix loops, fan-out comparisons, and session status tracking.
openclaw skills install @jose-compu/cpa-agentsSkill version: 2.1.0
Requires: cpa-agents@0.4.0 exactly
Use concurrent process algebra for multi-agent orchestration in OpenClaw: parallel execution, branch-fix loops, model fan-out, retries, fallbacks, rollback sagas, and session-tree introspection.
This skill can change the current workspace and can send task text to more than one model provider.
branch-fix and saga may create branches, write files, and request rollback. Run them only after the user explicitly asks for that repository change in this session. Show the planned steps before applying them.fan-out sends the task text to every named model. Do not put secrets, credentials, tokens, private keys, or private file contents in that text.fan-out with an empty models list. The library would otherwise send the task to claude-sonnet-4-20250514 and gpt-4o. Ask the user which models to use.Install the reviewed package exactly. Do not use npm install cpa-agents or a range such as ^0.4.0.
npm install cpa-agents@0.4.0 --save-exact
Expected integrity:
sha512-hx2Nnqk1g9cZgSO9uVZRlh4zKr7YbZPbNapV3tcU302EI+BqkCzUMhNuXVv88esVuyKn55ni13O2/sb4YYHuoQ==
Commit package-lock.json and install from it with npm ci. The code that runs is that npm package, not this markdown file.
import { createOpenClawSkill } from "cpa-agents/adapters/openclaw";
export default createOpenClawSkill();
The skill object exposes:
name — "cpa-agents"version — library version from the installed package (0.4.0; distinct from this skill doc 2.1.0)skillMd — embedded markdown referencehandleCommand(command, args, openclawCtx) — runs CPA workflowsCommands delegate to the OpenClaw host agent. Your skill host must provide:
interface OpenClawContext {
session?: {
id: string;
appendEvent?: (event: TraceEvent) => void; // trace streaming
};
agent: {
run: (
task: string,
opts?: { signal?: AbortSignal; model?: string }
) => Promise<{ output: string; errors?: string[] }>;
};
}
agent.run() is required for all skill commands.{ errors: [...] } from run() to signal fixable failures (used by branch-fix).session.appendEvent is optional but recommended for live trace trees.For custom workflows outside handleCommand, wire gateway helpers explicitly:
import { configureOpenClawBridge, openclawTool, workspaceAgent } from "cpa-agents/adapters/openclaw";
configureOpenClawBridge({
runTool: async (tool, args, signal) => gateway.callTool(tool, args, { signal }),
readMemory: async (key, signal) => gateway.readMemory(key, { signal }),
writeMemory: async (input, signal) => gateway.writeMemory(input, { signal }),
});
Without configureOpenClawBridge() (or a per-factory bridge option), openclawTool and
workspaceAgent throw "OpenClaw bridge not connected".
Call skill.handleCommand(command, args, ctx) with these command names:
| Command | Purpose |
|---|---|
parallel | Run independent tasks concurrently |
branch-fix | Run task, fix on errors, continue |
fan-out | Same task across multiple models |
retry | Exponential backoff + per-attempt timeout |
fallback | Primary task with fallback on failure |
saga | Multi-step workflow with rollback |
status | Current session process tree |
Global default: timeout = 300000 ms (5 min) on any command that accepts it.
parallel{
"tasks": ["analyze failing tests", "draft fix proposal", "write migration notes"],
"timeout": 300000
}
Returns merged parallel results via SchedulerResult.
branch-fixRun one task; if agent.run() returns errors, branch into a fix subprocess, then resume.
Do this only after the user explicitly asks to change this workspace. Describe the branch and files before writing them.
{
"task": "implement auth middleware and resolve lint issues",
"timeout": 300000
}
Fix prompt sent to agent: Fix the following issues: {errors joined by "; "}.
fan-outRun the same task across models the user named, then merge outputs. models is required. Do not rely on the library default, which would send the task to two providers.
{
"task": "propose API surface for agent orchestration",
"models": ["claude-sonnet-4-20250514", "gpt-4o"],
"timeout": 300000
}
Do not omit models. Omitting it sends the task to claude-sonnet-4-20250514 and gpt-4o.
Merge shape: { results: string[], consensus: number }.
retryRetry a task with exponential backoff and a per-attempt timeout.
{
"task": "fix flaky integration test",
"model": "gpt-4o",
"maxAttempts": 3,
"initialDelayMs": 250,
"stepTimeout": 60000,
"timeout": 300000
}
Defaults: maxAttempts=3, initialDelayMs=250, stepTimeout=60000.
fallbackRun fallback task if primary fails.
{
"primary": "run strict static analyzer",
"fallback": "run lightweight linter",
"model": "gpt-4o",
"timeout": 300000
}
sagaRun steps sequentially; on failure, undo completed steps in reverse order.
Do this only after the user explicitly asks for the forward steps and accepts rollback. Rollback can delete a branch or revert files in the current workspace.
{
"steps": ["create branch", "apply patch", "run validation"],
"model": "gpt-4o",
"timeout": 300000
}
Each undo step prompts: Rollback/undo the effects of this step: {step}.
statusReturn the CPA session tree for the current session.
{}
Response includes sessionTree and value.tree. Use sessionTreeToMarkdown for display:
import { sessionTreeToMarkdown } from "cpa-agents/adapters/openclaw";
const md = sessionTreeToMarkdown(result.sessionTree);
Every SchedulerResult includes trace and sessionTree. For standalone workflows or
post-run persistence:
import { Scheduler, loadJsonlTree } from "cpa-agents";
const scheduler = new Scheduler();
const sink = scheduler.attachJsonl("./session.jsonl");
const result = await scheduler.run("workflow", myProcess);
await sink.close();
const tree = await loadJsonlTree("./session.jsonl");
In OpenClaw, prefer streaming via session.appendEvent during handleCommand runs.
Use these in custom TypeScript workflows via cpa-agents core exports.
mapPar)Fan out over an array with a concurrency cap (unlike fixed-arity par):
import { mapPar, Scheduler } from "cpa-agents";
const workflow = mapPar(
tasks,
(task) => async (ctx) => agent.run(task, { signal: ctx.signal }),
{ concurrency: 3, failFast: true }
);
const result = await new Scheduler().run("batch", workflow);
mapPar[i] spawn/done traces per itemctx.signalinvertible + saga)invertible(forward, undo) — step plus compensating actionsaga([...steps]) — forward order; undo in reverse on failureimport { invertible, saga } from "cpa-agents";
const workflow = saga([
invertible(createBranch, deleteBranch),
invertible(writeCode, revertCode),
invertible(runValidation, cleanupValidation),
]);
The OpenClaw saga command wraps this pattern around agent.run().
converse)Relational provenance, not operational undo. Answers: which input(s) could produce this output?
import { rel, converse } from "cpa-agents";
const generate = rel("generate", async (prompt: string) => [prompt + "-out"]);
const provenance = converse(generate, async (output: string) => [
output.replace("-out", ""),
]);
guard, guardValue, ifThenElse)guard(...) — block unsafe executionguardValue(...) — require a value to existifThenElse(...) — conditional routingretryWithBackoff, timeout, or)retryWithBackoff — transient failure recoverytimeout(ms, process) — bound execution timeor(primary, fallback) — fallback routing (used by fallback command)| Mechanism | Use when |
|---|---|
invertible + saga | You must reverse side effects |
converse | Audit, lineage, explainability |
| Symptom | Fix |
|---|---|
OpenClaw bridge not connected | Call configureOpenClawBridge() or pass bridge to factory helpers |
| Agent not invoked | Ensure openclawCtx.agent.run is wired in the skill host |
| Unknown command | Use: parallel, branch-fix, fan-out, retry, fallback, saga, status |
| Timeout | Increase timeout in command args (default 300000 ms) |
| Missing session events | Enable session.appendEvent in host context |
| Rollback did not occur | Wrap steps with invertible(...); use saga command or operator |
| Empty status tree | Run a command in the same session first; status reflects the last active scheduler |
| Provenance unclear | Provide an explicit inverseFn when defining converse(...) |
Pi extension commands (cpa:par, cpa:fix, cpa:tree, cpa:retry, cpa:fallback, cpa:saga, cpa:fan-out)
use the same algebra via createPiCpaExtension() from cpa-agents/adapters/pi.
Requires piCtx.agent.run() — see package README.