()
| 27 | } |
| 28 | |
| 29 | async function main() { |
| 30 | const agent = await Agent.create(repoConfigPath()); |
| 31 | const session = agent.session('.', {}); |
| 32 | |
| 33 | // 1. parallel — independent steps; outcomes in input order. |
| 34 | const outcomes = await session.parallel([ |
| 35 | { taskId: 'langs', agent: 'general', description: 'list', prompt: 'Name three systems languages.', maxSteps: 2 }, |
| 36 | { taskId: 'safe', agent: 'general', description: 'classify', prompt: 'Is Rust memory-safe without a GC? yes/no.', maxSteps: 2 }, |
| 37 | ]); |
| 38 | for (const o of outcomes) console.log(`[parallel] ${o.taskId}: success=${o.success}`); |
| 39 | |
| 40 | // 2. pipeline — stage 2 builds on stage 1's output. Return null to stop a |
| 41 | // chain. A stage callback MUST NOT throw (return null on error). |
| 42 | const results = await session.pipeline( |
| 43 | ['the Rust programming language'], |
| 44 | [ |
| 45 | (ctx) => ({ taskId: 'sum', agent: 'general', description: 'summarize', prompt: `In one sentence, what is ${ctx.item}?`, maxSteps: 2 }), |
| 46 | (ctx) => ({ taskId: 'cls', agent: 'general', description: 'classify', |
| 47 | prompt: `Reply YES or NO: does this describe a programming language?\n\n${ctx.previous.output}`, maxSteps: 2 }), |
| 48 | ], |
| 49 | ); |
| 50 | for (const r of results) console.log(`[pipeline] final=${r === null ? null : JSON.stringify(r.output.slice(0, 60))}`); |
| 51 | } |
| 52 | |
| 53 | main().catch((err) => { |
| 54 | console.error(err); |
no test coverage detected