eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
23 lines (20 loc) • 1.83 kB
JavaScript
function workflowToolDescription(e){let t=e.length>0?e:[`agent`],n=t.map(e=>`\`${e}\``).join(`, `),r=t.filter(e=>e!==`agent`);return`Orchestrate this agent's subagents by writing a JavaScript program the runtime executes deterministically — fan out independent subtasks, run staged pipelines, and combine results in code, in a single step.
The only callable operations are these agents — no filesystem, network, shell, or other tools: ${n}. Call each as \`await tools.<name>(input)\`; it resolves to the child's result, or a typed object when you pass an \`outputSchema\`. Sequence with \`await\`, run agents concurrently with \`Promise.all([...])\`, and use \`map\`/\`filter\`/\`flatMap\` to build calls and combine results. The program's return value becomes the tool result.
Reach for this when work decomposes into independent or staged subtasks — map-reduce over a list, a plan-then-verify pipeline, or fan-out-and-gather. For a single delegation, call the agent directly.
Example — fan out across areas with \`agent\`, then pipe the results into a synthesis step:
\`\`\`js
const areas = ["correctness", "security", "performance"];
const reviews = await Promise.all(
areas.map((area) =>
tools.agent({
message: \`Review the change for \${area}.\`,
outputSchema: { type: "object", properties: { findings: { type: "array", items: { type: "string" } } } },
}),
),
);
const verdict = await tools.agent({
message: \`Summarize these findings into a verdict: \${JSON.stringify(reviews)}\`,
outputSchema: { type: "object", properties: { verdict: { type: "string" }, blocking: { type: "boolean" } } },
});
return verdict;
\`\`\`${r.length>0?`\n\nDeclared subagents are called the same way — e.g. \`const note = await tools.${r[0]}({ message: "..." });\`.`:``}`}export{workflowToolDescription};