clanka 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/Acp.test.js +20 -8
  2. package/dist/Acp.test.js.map +1 -1
  3. package/dist/Agent.d.ts +4 -4
  4. package/dist/Agent.d.ts.map +1 -1
  5. package/dist/Agent.js +140 -99
  6. package/dist/Agent.js.map +1 -1
  7. package/dist/Agent.test.js +5 -4
  8. package/dist/Agent.test.js.map +1 -1
  9. package/dist/AgentBashJobs.test.js +51 -32
  10. package/dist/AgentBashJobs.test.js.map +1 -1
  11. package/dist/AgentCallerConfig.test.js +26 -7
  12. package/dist/AgentCallerConfig.test.js.map +1 -1
  13. package/dist/AgentExecutor.d.ts +71 -41
  14. package/dist/AgentExecutor.d.ts.map +1 -1
  15. package/dist/AgentExecutor.js +86 -78
  16. package/dist/AgentExecutor.js.map +1 -1
  17. package/dist/AgentExecutor.test.js +173 -72
  18. package/dist/AgentExecutor.test.js.map +1 -1
  19. package/dist/AgentExecutorImage.test.js +2 -2
  20. package/dist/AgentExecutorImage.test.js.map +1 -1
  21. package/dist/AgentImage.test.js +3 -2
  22. package/dist/AgentImage.test.js.map +1 -1
  23. package/dist/AgentSubagents.test.js +220 -31
  24. package/dist/AgentSubagents.test.js.map +1 -1
  25. package/dist/AgentTools.d.ts +369 -257
  26. package/dist/AgentTools.d.ts.map +1 -1
  27. package/dist/AgentTools.js +247 -190
  28. package/dist/AgentTools.js.map +1 -1
  29. package/dist/AgentTools.test.js +2 -2
  30. package/dist/AgentTools.test.js.map +1 -1
  31. package/dist/bin/cli.mjs +330 -281
  32. package/dist/bin/cli.mjs.map +1 -1
  33. package/package.json +1 -1
  34. package/src/Acp.test.ts +32 -11
  35. package/src/Agent.test.ts +5 -4
  36. package/src/Agent.ts +175 -137
  37. package/src/AgentBashJobs.test.ts +74 -38
  38. package/src/AgentCallerConfig.test.ts +39 -7
  39. package/src/AgentExecutor.test.ts +229 -72
  40. package/src/AgentExecutor.ts +120 -104
  41. package/src/AgentExecutorImage.test.ts +2 -2
  42. package/src/AgentImage.test.ts +4 -3
  43. package/src/AgentSubagents.test.ts +825 -562
  44. package/src/AgentTools.test.ts +2 -2
  45. package/src/AgentTools.ts +370 -278
package/dist/Agent.js CHANGED
@@ -51,7 +51,7 @@ export const Agent = Context.Service("clanka/Agent");
51
51
  */
52
52
  export const makeWith = Effect.fnUntraced(function* (options) {
53
53
  const executor = yield* AgentExecutor.AgentExecutor;
54
- // Background bash jobs are followed here rather than in a run, since they
54
+ // Background bash tasks are followed here rather than in a run, since they
55
55
  // can outlive the run that started them.
56
56
  const agentScope = yield* Effect.scope;
57
57
  const singleTool = yield* SingleTools.pipe(Effect.provide(SingleToolHandlers));
@@ -68,7 +68,7 @@ export const makeWith = Effect.fnUntraced(function* (options) {
68
68
  .filter((dts) => dts !== "")
69
69
  .join("\n\n"),
70
70
  offers: (name) => capabilities.tools.includes(name),
71
- jobPushes: capabilities.jobPushes,
71
+ taskPushes: capabilities.taskPushes,
72
72
  skillsCatalog: options.skills === undefined
73
73
  ? AgentSkills.renderCatalog(capabilities.skills)
74
74
  : AgentSkills.renderProvidedCatalog(options.skills),
@@ -79,7 +79,9 @@ export const makeWith = Effect.fnUntraced(function* (options) {
79
79
  const agentsMd = options.instructions === undefined
80
80
  ? capabilities.instructions
81
81
  : Option.map(options.instructions, renderInstructions);
82
- let agentCounter = 0;
82
+ // Tasks belong to the agent that started them. Each agent has its own
83
+ // owner id, so no agent sees another's tasks on a shared executor.
84
+ const rootTaskOwner = crypto.randomUUID();
83
85
  const outputBuffer = new Map();
84
86
  let currentOutputAgent = null;
85
87
  const history = MutableRef.make(Prompt.empty);
@@ -121,14 +123,14 @@ export const makeWith = Effect.fnUntraced(function* (options) {
121
123
  let cacheWrite = 0;
122
124
  const prompt = opts.history;
123
125
  const mailbox = opts.mailbox;
124
- // A job that ends is queued for the model and shown straight away, or at
125
- // the start of the next run when none is running. It neither wakes a
126
- // waiting run nor keeps one alive.
127
- const onJob = (job) => job.await.pipe(Effect.flatMap((final) => Effect.sync(() => {
128
- // `await` only returns once the job has ended.
126
+ // A bash task that ends is queued for the model and shown straight
127
+ // away, or at the start of the next run when none is running. It
128
+ // neither wakes a waiting run nor keeps one alive.
129
+ const onTask = (task) => task.await.pipe(Effect.flatMap((final) => Effect.sync(() => {
130
+ // `await` only returns once the task has ended.
129
131
  if (final.status === "running")
130
132
  return;
131
- mailbox.jobs.push({ job: final, claim: job.claim });
133
+ mailbox.tasks.push({ task: final, claim: task.claim });
132
134
  const event = new JobComplete({
133
135
  id: final.id,
134
136
  status: final.status,
@@ -178,6 +180,7 @@ export const makeWith = Effect.fnUntraced(function* (options) {
178
180
  if (typeof opts.system === "string") {
179
181
  system += `\n${opts.system}\n`;
180
182
  }
183
+ console.log("system:", system);
181
184
  function maybeSend(options) {
182
185
  if (!opts.display) {
183
186
  Queue.offerUnsafe(output, options.part);
@@ -230,26 +233,27 @@ export const makeWith = Effect.fnUntraced(function* (options) {
230
233
  };
231
234
  mailbox.notify = notify;
232
235
  const runningChildren = () => Array.Array.from(children.values()).filter((child) => child.turn.status === "running");
233
- const hasUndelivered = () => completions.some((turn) => !turn.delivered);
234
- const finishTurn = (turn, exit) => Effect.sync(() => {
236
+ const hasUndelivered = () => completions.some(({ turn }) => !turn.reported);
237
+ const finishTurn = (child, turn, exit) => Effect.sync(() => {
235
238
  if (Exit.isSuccess(exit)) {
236
239
  turn.status = "completed";
237
240
  turn.output = exit.value;
238
241
  }
239
242
  else if (Cause.hasInterruptsOnly(exit.cause)) {
240
- turn.status = "cancelled";
243
+ turn.status = "stopped";
241
244
  }
242
245
  else {
243
246
  turn.status = "failed";
244
247
  turn.output = causeMessage(exit.cause);
245
248
  }
246
249
  Queue.offerUnsafe(output, new SubagentComplete({
247
- id: turn.agentId,
250
+ id: child.id,
248
251
  summary: turn.output ?? "",
249
- status: turn.status,
252
+ // The output event keeps its own name for a stopped agent.
253
+ status: turn.status === "stopped" ? "cancelled" : turn.status,
250
254
  }));
251
- if (!turn.delivered) {
252
- completions.push(turn);
255
+ if (!turn.reported) {
256
+ completions.push({ child, turn });
253
257
  }
254
258
  Deferred.doneUnsafe(turn.done, Effect.void);
255
259
  notify();
@@ -262,6 +266,7 @@ export const makeWith = Effect.fnUntraced(function* (options) {
262
266
  const display = opts.display && !options.background;
263
267
  const stream = spawn({
264
268
  agentId: child.id,
269
+ taskOwner: child.taskOwner,
265
270
  prompt: Prompt.make(options.prompt),
266
271
  environmentUpdate: options.environmentUpdate,
267
272
  system: opts.system,
@@ -305,30 +310,38 @@ export const makeWith = Effect.fnUntraced(function* (options) {
305
310
  }
306
311
  return Effect.void;
307
312
  }), Effect.as(""), Effect.catchTag("AgentFinished", (finished) => Effect.succeed(finished.summary)));
308
- }).pipe(Effect.onExit((exit) => finishTurn(turn, exit)), provideSubagentModel, Effect.provideContext(runContext), Effect.forkIn(runScope, { startImmediately: true }));
313
+ }).pipe(Effect.onExit((exit) => finishTurn(child, turn, exit)), provideSubagentModel, Effect.provideContext(runContext), Effect.forkIn(runScope, { startImmediately: true }));
309
314
  });
310
- // Leaves `output` out when unset, so the result stays JSON for RPC.
311
- const childResult = ({ id, turn }) => turn.output === undefined
312
- ? { id: String(id), status: turn.status }
313
- : { id: String(id), status: turn.status, output: turn.output };
315
+ const childTask = ({ id, prompt, turn }) => ({
316
+ id: String(id),
317
+ kind: "agent",
318
+ status: turn.status,
319
+ description: prompt,
320
+ output: turn.output ?? "",
321
+ });
322
+ // A final status returned to the script is not pushed as well.
323
+ const reportChild = (child) => {
324
+ if (child.turn.status !== "running")
325
+ child.turn.reported = true;
326
+ return childTask(child);
327
+ };
314
328
  const lookupChild = (id) => Effect.suspend(() => {
315
329
  const child = children.get(id);
316
330
  return child
317
331
  ? Effect.succeed(child)
318
- : Effect.fail(`Unknown agent id ${JSON.stringify(id)}. You can only address agents you started; call listAgents() to see them.`);
332
+ : Effect.fail(`No task with id ${JSON.stringify(id)}. You can only address tasks you started; call listTasks() to see them.`);
319
333
  });
320
- const subagents = {
321
- delegate: Effect.fnUntraced(function* ({ prompt, background, environment, }) {
322
- const agentId = agentCounter++;
334
+ const agentTasks = {
335
+ delegate: Effect.fnUntraced(function* ({ id, prompt, background, environment, }) {
323
336
  const child = {
324
- id: agentId,
337
+ id: Number(id),
338
+ taskOwner: crypto.randomUUID(),
325
339
  prompt,
326
340
  history: MutableRef.make(Prompt.empty),
327
341
  environment: MutableRef.make(environment.environment),
328
342
  mailbox: makeMailbox(),
329
- turn: makeTurn(agentId, background),
343
+ turn: makeTurn(background),
330
344
  };
331
- const id = String(child.id);
332
345
  children.set(id, child);
333
346
  const turn = child.turn;
334
347
  yield* startTurn({
@@ -342,7 +355,7 @@ ${prompt}`,
342
355
  background,
343
356
  });
344
357
  if (background) {
345
- return { id, status: "running" };
358
+ return childTask(child);
346
359
  }
347
360
  // Foreground: a failure crashes the script, as before. Interrupting
348
361
  // the script stops the agent.
@@ -350,60 +363,57 @@ ${prompt}`,
350
363
  if (turn.status !== "completed") {
351
364
  return yield* Effect.die(new Error(`Sub-agent ${child.id} ${turn.status}${turn.output ? `: ${turn.output}` : ""}`));
352
365
  }
353
- return { id, status: "completed", output: turn.output ?? "" };
366
+ return childTask(child);
354
367
  }),
355
- waitAgents: Effect.fnUntraced(function* (ids) {
356
- const targets = ids === undefined
357
- ? Array.Array.from(children.values())
358
- : yield* Effect.forEach(ids, lookupChild);
368
+ taskOutput: (id) => Effect.map(lookupChild(id), reportChild),
369
+ waitTasks: Effect.fnUntraced(function* (ids, { timeoutMs }) {
370
+ const targets = yield* Effect.forEach(ids, lookupChild);
359
371
  // A turn started by messageAgent while waiting is waited for too.
360
- while (true) {
361
- const running = targets.find((child) => child.turn.status === "running");
362
- if (!running)
363
- break;
364
- yield* Deferred.await(running.turn.done);
365
- }
366
- return targets.map((child) => {
367
- child.turn.delivered = true;
368
- return childResult(child);
369
- });
372
+ // Agents still running at the deadline keep going.
373
+ yield* Effect.gen(function* () {
374
+ while (true) {
375
+ const running = targets.find((child) => child.turn.status === "running");
376
+ if (!running)
377
+ break;
378
+ yield* Deferred.await(running.turn.done);
379
+ }
380
+ }).pipe(Effect.timeoutOption(timeoutMs));
381
+ // Reported together: only the agents that ended count as reported.
382
+ return targets.map(reportChild);
370
383
  }),
371
384
  messageAgent: Effect.fnUntraced(function* ({ id, message }) {
372
385
  const child = yield* lookupChild(id);
373
386
  if (child.turn.status === "running") {
374
387
  child.mailbox.messages.add({ message, resume: () => { } });
375
388
  child.mailbox.notify();
376
- return childResult(child);
389
+ return childTask(child);
377
390
  }
378
- child.turn = makeTurn(child.id, true);
391
+ child.turn = makeTurn(true);
379
392
  yield* startTurn({
380
393
  child,
381
394
  prompt: message,
382
395
  label: message,
383
396
  background: true,
384
397
  });
385
- return childResult(child);
398
+ return childTask(child);
386
399
  }),
387
- stopAgent: Effect.fnUntraced(function* (id) {
400
+ stopTask: Effect.fnUntraced(function* (id) {
388
401
  const child = yield* lookupChild(id);
389
402
  const turn = child.turn;
390
- turn.delivered = true;
403
+ turn.reported = true;
391
404
  if (turn.status === "running") {
392
405
  yield* Fiber.interrupt(turn.fiber);
393
406
  }
394
- return childResult(child);
407
+ return childTask(child);
395
408
  }),
396
- listAgents: Effect.sync(() => Array.Array.from(children.values(), (child) => ({
397
- id: String(child.id),
398
- status: child.turn.status,
399
- prompt: child.prompt,
400
- }))),
409
+ listTasks: Effect.sync(() => Array.Array.from(children.values(), childTask)),
401
410
  };
402
411
  const onTaskComplete = (summary) => Effect.suspend(() => {
403
412
  const running = runningChildren();
404
413
  if (running.length > 0) {
405
- const ids = running.map((child) => JSON.stringify(String(child.id)));
406
- return Effect.fail(`taskComplete was rejected: sub-agents ${ids.join(", ")} are still running. Call waitAgents() to wait for them, or stopAgent(id) to stop them, before calling taskComplete.`);
414
+ const ids = running.map((child) => String(child.id));
415
+ const quoted = ids.map((id) => JSON.stringify(id)).join(", ");
416
+ return Effect.fail(`taskComplete was rejected: sub-agents ${quoted} are still running. Call waitTasks({ ids: ${JSON.stringify(ids)} }) to wait for them, or stopTask(id) to stop them, before calling taskComplete.`);
407
417
  }
408
418
  finalSummary = Option.some(summary);
409
419
  return Effect.void;
@@ -521,10 +531,11 @@ ${prompt}`,
521
531
  onEnvironment: (environment) => Effect.sync(() => {
522
532
  MutableRef.set(opts.environment, environment);
523
533
  }),
524
- subagents,
534
+ agentId: opts.taskOwner,
535
+ agentTasks,
525
536
  onTaskComplete,
526
537
  onImage,
527
- onJob,
538
+ onTask,
528
539
  loopTools: scriptLoopTools,
529
540
  }), Stream.mkString);
530
541
  // Always-on cap on what enters the Prompt. The ScriptOutput event keeps
@@ -590,35 +601,29 @@ ${prompt}`,
590
601
  })));
591
602
  mailbox.messages.clear();
592
603
  }
593
- // Completion pushes from background sub-agents. These have their own
594
- // queue: the steering path above cuts the model stream short.
595
- if (completions.length > 0) {
596
- const pushes = completions.splice(0).filter((turn) => {
597
- if (turn.delivered)
598
- return false;
599
- turn.delivered = true;
600
- return true;
601
- });
602
- if (pushes.length > 0) {
603
- appendHistory(Prompt.make(pushes.map((turn) => ({
604
- role: "user",
605
- content: `<subagent id="${turn.agentId}" status="${turn.status}">
606
- ${Compaction.capOutput(turn.output ?? "").output}
607
- </subagent>`,
608
- }))));
609
- }
610
- }
611
- // Background bash jobs that ended and were not reported otherwise.
612
- if (mailbox.jobs.length > 0) {
604
+ // Ended tasks not reported otherwise: background sub-agents of this
605
+ // run and bash tasks of this agent. These have their own queue: the
606
+ // steering path above cuts the model stream short.
607
+ if (completions.length > 0 || mailbox.tasks.length > 0) {
613
608
  const pushes = [];
614
- for (const { job, claim } of mailbox.jobs.splice(0)) {
609
+ for (const { child, turn } of completions.splice(0)) {
610
+ if (turn.reported)
611
+ continue;
612
+ turn.reported = true;
613
+ pushes.push({
614
+ ...childTask(child),
615
+ status: turn.status,
616
+ output: turn.output ?? "",
617
+ });
618
+ }
619
+ for (const { task, claim } of mailbox.tasks.splice(0)) {
615
620
  if (yield* claim)
616
- pushes.push(job);
621
+ pushes.push(task);
617
622
  }
618
623
  if (pushes.length > 0) {
619
- appendHistory(Prompt.make(pushes.map((job) => ({
624
+ appendHistory(Prompt.make(pushes.map((task) => ({
620
625
  role: "user",
621
- content: jobMessage(job),
626
+ content: taskMessage(task),
622
627
  }))));
623
628
  }
624
629
  }
@@ -870,7 +875,8 @@ ${Compaction.capOutput(turn.output ?? "").output}
870
875
  history,
871
876
  environment,
872
877
  send: (options) => spawn({
873
- agentId: agentCounter++,
878
+ agentId: 0,
879
+ taskOwner: rootTaskOwner,
874
880
  prompt: Prompt.make(options.prompt),
875
881
  system: options.system,
876
882
  history,
@@ -898,22 +904,21 @@ export const make = makeWith({});
898
904
  const makeMailbox = () => ({
899
905
  messages: new Set(),
900
906
  notify: () => { },
901
- jobs: [],
907
+ tasks: [],
902
908
  emit: undefined,
903
909
  events: [],
904
910
  });
905
- const jobMessage = (job) => {
906
- const exitCode = job.exitCode === undefined ? "" : ` exitCode="${job.exitCode}"`;
907
- return `<job id="${job.id}" status="${job.status}"${exitCode}>
908
- ${Compaction.capOutput(job.output).output}
909
- </job>`;
911
+ const taskMessage = (task) => {
912
+ const exitCode = task.exitCode === undefined ? "" : ` exitCode="${task.exitCode}"`;
913
+ return `<task id="${task.id}" kind="${task.kind}" status="${task.status}"${exitCode}>
914
+ ${Compaction.capOutput(task.output).output}
915
+ </task>`;
910
916
  };
911
- const makeTurn = (agentId, background) => ({
912
- agentId,
917
+ const makeTurn = (background) => ({
913
918
  status: "running",
914
919
  output: undefined,
915
920
  // Foreground results go straight back to the script.
916
- delivered: !background,
921
+ reported: !background,
917
922
  done: Deferred.makeUnsafe(),
918
923
  fiber: undefined,
919
924
  });
@@ -949,13 +954,16 @@ const startsWith = (message, prefix) => message.role === "user" &&
949
954
  const isEnvironmentUpdate = (message) => startsWith(message, environmentUpdateOpen);
950
955
  /**
951
956
  * Whether a user message was added by the agent rather than typed: an
952
- * `<environment-update>` or a `<subagent>` result. Surfaces that replay
953
- * history (ACP) skip them.
957
+ * `<environment-update>` or a `<task>` result, or the `<subagent>` and `<job>`
958
+ * results of earlier versions. Surfaces that replay history (ACP) skip them.
954
959
  *
955
960
  * @since 1.0.0
956
961
  * @category Models
957
962
  */
958
- export const isInjectedMessage = (message) => isEnvironmentUpdate(message) || startsWith(message, "<subagent ");
963
+ export const isInjectedMessage = (message) => isEnvironmentUpdate(message) ||
964
+ startsWith(message, "<task ") ||
965
+ startsWith(message, "<subagent ") ||
966
+ startsWith(message, "<job ");
959
967
  const renderInstructions = (content) => `# Project instructions
960
968
 
961
969
  **ALWAYS follow these instructions when completing tasks**:
@@ -970,6 +978,40 @@ ${options.toolInstructions}
970
978
  ${options.agentsMd}
971
979
  `;
972
980
  const when = (condition, text) => (condition ? text : "");
981
+ // The task functions the executor offers, and how ended tasks reach the
982
+ // model. Only offered functions are named.
983
+ const taskInstructions = (tools) => {
984
+ const bash = tools.offers("bash");
985
+ const delegate = tools.offers("delegate");
986
+ if (!bash && !delegate)
987
+ return "";
988
+ const functions = [
989
+ ["taskOutput", `"taskOutput" reads one`],
990
+ [
991
+ "waitTasks",
992
+ `"waitTasks" waits for a list of them and returns any still running at its timeout as "running"`,
993
+ ],
994
+ ["stopTask", `"stopTask" stops one`],
995
+ ["listTasks", `"listTasks" lists yours`],
996
+ ]
997
+ .filter(([name]) => tools.offers(name))
998
+ .map(([, text]) => text);
999
+ const kinds = bash && delegate
1000
+ ? "Background commands and sub-agents are"
1001
+ : bash
1002
+ ? "Background commands are"
1003
+ : "Sub-agents are";
1004
+ const uses = functions.length === 0
1005
+ ? ""
1006
+ : ` ${functions.length === 1 ? functions[0] : `${functions.slice(0, -1).join(", ")} and ${functions.at(-1)}`}.`;
1007
+ const pushes = tools.taskPushes
1008
+ ? ` When a task ends, its status and output are sent to you as a \`<task id="..." kind="..." status="...">\` message, unless a task function already gave you its final status, so you do not need to poll.`
1009
+ : bash && tools.offers("taskOutput")
1010
+ ? ` Background commands are not sent to you when they end: check them with "taskOutput".`
1011
+ : "";
1012
+ return `
1013
+ - ${kinds} tasks with ids.${uses}${pushes}`;
1014
+ };
973
1015
  const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL AVAILABLE: "execute", to run javascript code to do your work.
974
1016
 
975
1017
  - Use \`console.log\` to print any output you need.
@@ -977,11 +1019,10 @@ const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL
977
1019
  - Use top level await.${when(tools.offers("search") && tools.offers("rg"), `
978
1020
  - Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`)}${when(tools.offers("applyPatch"), `
979
1021
  - You can add / update / remove multiple files in one go with "applyPatch".${when(tools.offers("writeFile"), ` Prefer it over "writeFile" to update existing files.`)}`)}${when(tools.offers("bash"), `
980
- - Avoid passing scripts into the "bash" function, and instead write javascript.
981
- - Pass \`background: true\` to "bash" for commands that keep running, such as dev servers or watchers. A command still running at its timeout is moved to the background instead of being stopped. Use "jobOutput" and "stopJob" with the returned job id.${when(tools.jobPushes, ` When a job ends, its status and output are sent to you as a \`<job id="..." status="..." exitCode="...">\` message, unless "jobOutput" or "stopJob" already gave you its final status. You do not need to poll jobs with "jobOutput" to find out when they end.`)}`)}
1022
+ - Avoid passing scripts into the "bash" function, and instead write javascript.`)}
982
1023
  - Variables are not shared between executions.
983
1024
  - Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${when(tools.offers("delegate"), `
984
- - "delegate" runs a sub-agent and waits for it. Pass \`background: true\` to keep working while it runs: its result is sent to you later as a \`<subagent id="..." status="...">\` message.${when(tools.offers("waitAgents"), ` Use "waitAgents" to wait for the returned id.`)}${when(tools.offers("messageAgent"), ` Use "messageAgent" to send a message to the returned id.`)}${when(tools.offers("stopAgent"), ` Use "stopAgent" to stop the returned id.`)}${when(tools.offers("listAgents"), ` "listAgents" shows the agents you started.`)}`)}${when(!conversationMode, `
1025
+ - "delegate" runs a sub-agent and waits for it. Pass \`background: true\` to keep working while it runs: it returns an agent task straight away, and the agent's result is sent to you when it ends.${when(tools.offers("messageAgent"), ` Use "messageAgent" to send a message to a sub-agent.`)}`)}${taskInstructions(tools)}${when(!conversationMode, `
985
1026
 
986
1027
  When you have fully completed your task, call the "taskComplete" function with the final output.
987
1028
  Make sure every detail of the task is done before calling "taskComplete".${when(tools.offers("delegate"), `