MCPcopy Create free account
hub / github.com/AI45Lab/Code / main

Function main

sdk/node/examples/orchestration/parallel-pipeline.mjs:29–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29async 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
53main().catch((err) => {
54 console.error(err);

Callers 1

Calls 6

repoConfigPathFunction · 0.85
createMethod · 0.45
sessionMethod · 0.45
parallelMethod · 0.45
logMethod · 0.45
pipelineMethod · 0.45

Tested by

no test coverage detected