workflow-under-test.js
1.06 KB
export const meta = {
name: 'graphlemon-a1-spike',
description: 'A-1 spike: minimal fan-out/fan-in workflow used to verify headless invocation and structured output.',
}
// args is injected by the runtime when invoked as:
// claude -p 'Run /graphlemon-a1-spike with args {"numbers":[2,3,4]}'
const numbers = (typeof args !== 'undefined' && args && args.numbers) || [2, 3, 4]
// Fan-out: one agent per number, each computes a square in isolation.
// This is the exact shape graphlemon's Work Graph "diamond" fan-out would use.
const squares = await pipeline(numbers, n =>
agent(`Compute ${n} squared (${n} * ${n}). Reply with only the integer result, nothing else.`, {
label: `square-${n}`,
schema: {
type: 'object',
required: ['value'],
properties: { value: { type: 'number' } },
},
}),
)
// Fan-in: reduce step, pure script code, zero extra tokens.
const sum = squares.reduce((acc, s) => acc + (s && typeof s.value === 'number' ? s.value : 0), 0)
return {
input_numbers: numbers,
squares: squares.map(s => (s ? s.value : null)),
sum,
}