clanka 0.22.6 → 0.23.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.
- package/dist/Acp.js +1 -1
- package/dist/Acp.test.js +7 -7
- package/dist/Agent.js +6 -6
- package/dist/Agent.test.js +1 -1
- package/dist/AgentCallerConfig.test.js +11 -10
- package/dist/AgentCallerConfig.test.js.map +1 -1
- package/dist/AgentEnvironment.test.js +2 -2
- package/dist/AgentExecutor.d.ts +25 -25
- package/dist/AgentExecutor.js +9 -9
- package/dist/AgentExecutor.test.js +13 -13
- package/dist/AgentImage.test.js +4 -4
- package/dist/AgentSubagents.test.js +11 -11
- package/dist/AgentTools.d.ts +78 -78
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +8 -8
- package/dist/McpServers.test.js +1 -1
- package/dist/bin/cli.mjs +19 -19
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +7 -7
- package/src/Acp.ts +1 -1
- package/src/Agent.test.ts +1 -1
- package/src/Agent.ts +6 -6
- package/src/AgentCallerConfig.test.ts +14 -10
- package/src/AgentEnvironment.test.ts +2 -2
- package/src/AgentExecutor.test.ts +13 -13
- package/src/AgentExecutor.ts +16 -16
- package/src/AgentImage.test.ts +4 -4
- package/src/AgentSubagents.test.ts +12 -12
- package/src/AgentTools.ts +11 -11
- package/src/McpServers.test.ts +1 -1
package/package.json
CHANGED
package/src/Acp.test.ts
CHANGED
|
@@ -646,7 +646,7 @@ describe("Acp", () => {
|
|
|
646
646
|
),
|
|
647
647
|
)
|
|
648
648
|
|
|
649
|
-
it.effect("reports subagents with a
|
|
649
|
+
it.effect("reports subagents with a subagent prompt preview", () =>
|
|
650
650
|
withStore(
|
|
651
651
|
Effect.scoped(
|
|
652
652
|
Effect.gen(function* () {
|
|
@@ -661,14 +661,14 @@ describe("Acp", () => {
|
|
|
661
661
|
type: "tool-call",
|
|
662
662
|
id: "call-1",
|
|
663
663
|
name: "execute",
|
|
664
|
-
params: { script: "await
|
|
664
|
+
params: { script: "await subagent()" },
|
|
665
665
|
})
|
|
666
666
|
: assistantSays(summary),
|
|
667
667
|
{
|
|
668
668
|
...executor,
|
|
669
669
|
execute: ({ agentTasks, environment }) =>
|
|
670
670
|
Stream.fromEffect(
|
|
671
|
-
agentTasks.
|
|
671
|
+
agentTasks.subagent({
|
|
672
672
|
id: "1",
|
|
673
673
|
prompt,
|
|
674
674
|
background: false,
|
|
@@ -706,13 +706,13 @@ describe("Acp", () => {
|
|
|
706
706
|
assert.strictEqual(tools[1].sessionUpdate, "tool_call_update")
|
|
707
707
|
assert.strictEqual(tools[1].toolCallId, tools[0].toolCallId)
|
|
708
708
|
assert.strictEqual(tools[1].status, "completed")
|
|
709
|
-
assert.match(tools[0].title, /^
|
|
709
|
+
assert.match(tools[0].title, /^subagent: Inspect the repository/)
|
|
710
710
|
assert.notMatch(tools[0].title, /[\r\n]/)
|
|
711
711
|
assert.strictEqual(
|
|
712
712
|
tools[0].title,
|
|
713
|
-
"
|
|
713
|
+
"subagent: " + prompt.replace(/\s+/g, " ").slice(0, 120),
|
|
714
714
|
)
|
|
715
|
-
assert.strictEqual(tools[0].title.length, "
|
|
715
|
+
assert.strictEqual(tools[0].title.length, "subagent: ".length + 120)
|
|
716
716
|
assert.deepStrictEqual(tools[1].content, [
|
|
717
717
|
{ type: "content", content: { type: "text", text: summary } },
|
|
718
718
|
])
|
|
@@ -763,7 +763,7 @@ describe("Acp", () => {
|
|
|
763
763
|
Stream.fromEffect(
|
|
764
764
|
executions++ === 0
|
|
765
765
|
? agentTasks
|
|
766
|
-
.
|
|
766
|
+
.subagent({
|
|
767
767
|
id: "1",
|
|
768
768
|
prompt: "TASK-CHILD",
|
|
769
769
|
background: true,
|
package/src/Acp.ts
CHANGED
|
@@ -934,7 +934,7 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
|
|
|
934
934
|
return update(session.id, {
|
|
935
935
|
sessionUpdate: announced ? "tool_call_update" : "tool_call",
|
|
936
936
|
toolCallId: `subagent-${part.id}`,
|
|
937
|
-
title: `
|
|
937
|
+
title: `subagent: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
|
|
938
938
|
kind: "think",
|
|
939
939
|
status: "in_progress",
|
|
940
940
|
rawInput: { prompt: part.prompt },
|
package/src/Agent.test.ts
CHANGED
package/src/Agent.ts
CHANGED
|
@@ -620,7 +620,7 @@ export const makeWith = Effect.fnUntraced(function* <
|
|
|
620
620
|
})
|
|
621
621
|
|
|
622
622
|
const agentTasks: AgentExecutor.ExecuteAgentTasks = {
|
|
623
|
-
|
|
623
|
+
subagent: Effect.fnUntraced(function* ({
|
|
624
624
|
id,
|
|
625
625
|
prompt,
|
|
626
626
|
background,
|
|
@@ -640,7 +640,7 @@ export const makeWith = Effect.fnUntraced(function* <
|
|
|
640
640
|
yield* startTurn({
|
|
641
641
|
child,
|
|
642
642
|
label: prompt,
|
|
643
|
-
prompt: `You have been asked using the "
|
|
643
|
+
prompt: `You have been asked using the "subagent" function to complete the following task. Try to avoid using the "subagent" function yourself unless strictly necessary:
|
|
644
644
|
|
|
645
645
|
${prompt}`,
|
|
646
646
|
// The update goes into the child's first prompt.
|
|
@@ -1745,8 +1745,8 @@ const when = (condition: boolean, text: string) => (condition ? text : "")
|
|
|
1745
1745
|
// model. Only offered functions are named.
|
|
1746
1746
|
const taskInstructions = (tools: PromptTools): string => {
|
|
1747
1747
|
const bash = tools.offers("bash")
|
|
1748
|
-
const
|
|
1749
|
-
if (!bash && !
|
|
1748
|
+
const subagent = tools.offers("subagent")
|
|
1749
|
+
if (!bash && !subagent) return ""
|
|
1750
1750
|
const functions = (
|
|
1751
1751
|
[
|
|
1752
1752
|
["taskOutput", `"taskOutput" reads one`],
|
|
@@ -1761,7 +1761,7 @@ const taskInstructions = (tools: PromptTools): string => {
|
|
|
1761
1761
|
.filter(([name]) => tools.offers(name))
|
|
1762
1762
|
.map(([, text]) => text)
|
|
1763
1763
|
const kinds =
|
|
1764
|
-
bash &&
|
|
1764
|
+
bash && subagent
|
|
1765
1765
|
? "Background commands and sub-agents are"
|
|
1766
1766
|
: bash
|
|
1767
1767
|
? "Background commands are"
|
|
@@ -1805,7 +1805,7 @@ const generateSystemTools = (
|
|
|
1805
1805
|
|
|
1806
1806
|
When you have fully completed your task, call the "taskComplete" function with the final output.
|
|
1807
1807
|
Make sure every detail of the task is done before calling "taskComplete".${when(
|
|
1808
|
-
tools.offers("
|
|
1808
|
+
tools.offers("subagent"),
|
|
1809
1809
|
`
|
|
1810
1810
|
Any sub-agents you started must finish first: "taskComplete" fails while they are running.`,
|
|
1811
1811
|
)}`,
|
|
@@ -260,9 +260,9 @@ await taskComplete(result)`,
|
|
|
260
260
|
const { system, summary } = yield* runAgent({
|
|
261
261
|
mode,
|
|
262
262
|
executor: {
|
|
263
|
-
excludeTools: ["gh", "webSearch", "fetchMarkdown", "
|
|
263
|
+
excludeTools: ["gh", "webSearch", "fetchMarkdown", "subagent"],
|
|
264
264
|
},
|
|
265
|
-
script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof
|
|
265
|
+
script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof subagent, typeof messageAgent].join(",")
|
|
266
266
|
let call
|
|
267
267
|
try {
|
|
268
268
|
await gh(["pr", "view"])
|
|
@@ -278,7 +278,7 @@ await taskComplete(missing + " " + call)`,
|
|
|
278
278
|
)
|
|
279
279
|
assert.notMatch(
|
|
280
280
|
system,
|
|
281
|
-
/\b(gh|webSearch|fetchMarkdown|
|
|
281
|
+
/\b(gh|webSearch|fetchMarkdown|subagent|messageAgent)\b/,
|
|
282
282
|
)
|
|
283
283
|
assert.include(system, "declare function readFile(")
|
|
284
284
|
}),
|
|
@@ -286,13 +286,13 @@ await taskComplete(missing + " " + call)`,
|
|
|
286
286
|
|
|
287
287
|
// The shared task functions address bash and agent tasks, so they stay
|
|
288
288
|
// while either kind can still be started.
|
|
289
|
-
it.live("the task functions go only when bash and
|
|
289
|
+
it.live("the task functions go only when bash and subagent both go", () =>
|
|
290
290
|
Effect.gen(function* () {
|
|
291
291
|
const tasks =
|
|
292
292
|
"[typeof taskOutput, typeof waitTasks, typeof stopTask, typeof listTasks].join()"
|
|
293
293
|
const withBash = yield* runAgent({
|
|
294
294
|
mode,
|
|
295
|
-
executor: { excludeTools: ["
|
|
295
|
+
executor: { excludeTools: ["subagent"] },
|
|
296
296
|
script: `await taskComplete(${tasks})`,
|
|
297
297
|
})
|
|
298
298
|
assert.strictEqual(
|
|
@@ -301,7 +301,7 @@ await taskComplete(missing + " " + call)`,
|
|
|
301
301
|
)
|
|
302
302
|
const withNeither = yield* runAgent({
|
|
303
303
|
mode,
|
|
304
|
-
executor: { excludeTools: ["bash", "
|
|
304
|
+
executor: { excludeTools: ["bash", "subagent"] },
|
|
305
305
|
script: `await taskComplete(${tasks})`,
|
|
306
306
|
})
|
|
307
307
|
assert.strictEqual(
|
|
@@ -458,17 +458,21 @@ describe("rpc executor", () => {
|
|
|
458
458
|
describe("agent", () => {
|
|
459
459
|
it.live("a left-out tool is not mentioned anywhere in the prompt", () =>
|
|
460
460
|
Effect.gen(function* () {
|
|
461
|
-
// Each is named outside its own declaration: the
|
|
461
|
+
// Each is named outside its own declaration: the subagent bullet, the
|
|
462
462
|
// applyPatch hint and the executor's skills catalog.
|
|
463
463
|
const { system, summary } = yield* runAgent({
|
|
464
464
|
mode: "local",
|
|
465
465
|
executor: { excludeTools: ["waitTasks", "applyPatch", "readFile"] },
|
|
466
466
|
script:
|
|
467
|
-
"await taskComplete([typeof waitTasks, typeof applyPatch, typeof readFile].join())",
|
|
467
|
+
"await taskComplete([typeof waitTasks, typeof applyPatch, typeof readFile, typeof subagent, typeof delegate].join())",
|
|
468
468
|
})
|
|
469
|
-
assert.strictEqual(
|
|
469
|
+
assert.strictEqual(
|
|
470
|
+
summary,
|
|
471
|
+
"undefined,undefined,undefined,function,undefined",
|
|
472
|
+
)
|
|
470
473
|
assert.notMatch(system, /\b(waitTasks|applyPatch|readFile)\b/)
|
|
471
|
-
assert.include(system, "declare function
|
|
474
|
+
assert.include(system, "declare function subagent(")
|
|
475
|
+
assert.notInclude(system, "declare function delegate(")
|
|
472
476
|
}),
|
|
473
477
|
)
|
|
474
478
|
|
|
@@ -277,7 +277,7 @@ for (const [mode, executorLayer] of Object.entries(executors)) {
|
|
|
277
277
|
return Stream.make(toolCall(`await changeDirectory("pkg")`))
|
|
278
278
|
case 3:
|
|
279
279
|
return Stream.make(
|
|
280
|
-
toolCall(`await
|
|
280
|
+
toolCall(`await subagent({ prompt: "TASK-CHILD" })`),
|
|
281
281
|
)
|
|
282
282
|
default:
|
|
283
283
|
return Stream.fromIterable(text("done"))
|
|
@@ -326,7 +326,7 @@ for (const [mode, executorLayer] of Object.entries(executors)) {
|
|
|
326
326
|
assert.include(
|
|
327
327
|
JSON.stringify(encodePrompt(child!.prompt)),
|
|
328
328
|
"PKG-RULES",
|
|
329
|
-
"a
|
|
329
|
+
"a subagent started after the cd sees pkg's instructions",
|
|
330
330
|
)
|
|
331
331
|
const childUpdates = outputs.flatMap((output) =>
|
|
332
332
|
output._tag === "SubagentPart" &&
|
|
@@ -23,7 +23,7 @@ import * as NodePath from "node:path"
|
|
|
23
23
|
import * as AgentExecutor from "./AgentExecutor.ts"
|
|
24
24
|
import { agentTasksUnavailable, type Task } from "./AgentTools.ts"
|
|
25
25
|
|
|
26
|
-
// The task a stub `
|
|
26
|
+
// The task a stub `subagent` resolves with once its agent has finished.
|
|
27
27
|
const completedAgent = (id: string, prompt: string, output: string): Task => ({
|
|
28
28
|
id,
|
|
29
29
|
kind: "agent",
|
|
@@ -74,7 +74,7 @@ const withRpc = <A, E, R>(
|
|
|
74
74
|
)
|
|
75
75
|
|
|
76
76
|
describe("RPC subagent executor", () => {
|
|
77
|
-
it.live("routes concurrent
|
|
77
|
+
it.live("routes concurrent subagents to their originating scripts", () =>
|
|
78
78
|
withRpc((executor) =>
|
|
79
79
|
Effect.gen(function* () {
|
|
80
80
|
const { environment } = yield* executor.capabilities
|
|
@@ -87,12 +87,12 @@ describe("RPC subagent executor", () => {
|
|
|
87
87
|
environment,
|
|
88
88
|
onEnvironment: () => Effect.void,
|
|
89
89
|
script:
|
|
90
|
-
'console.log("first:" + (await
|
|
90
|
+
'console.log("first:" + (await subagent({ prompt: "first" })).output)',
|
|
91
91
|
onTaskComplete: () => Effect.void,
|
|
92
92
|
onImage: () => Effect.void,
|
|
93
93
|
agentTasks: {
|
|
94
94
|
...agentTasksUnavailable,
|
|
95
|
-
|
|
95
|
+
subagent: ({ id, prompt }) =>
|
|
96
96
|
Effect.gen(function* () {
|
|
97
97
|
assert.strictEqual(prompt, "first")
|
|
98
98
|
yield* Deferred.succeed(firstStarted, undefined)
|
|
@@ -107,12 +107,12 @@ describe("RPC subagent executor", () => {
|
|
|
107
107
|
environment,
|
|
108
108
|
onEnvironment: () => Effect.void,
|
|
109
109
|
script:
|
|
110
|
-
'console.log("second:" + (await
|
|
110
|
+
'console.log("second:" + (await subagent({ prompt: "second" })).output)',
|
|
111
111
|
onTaskComplete: () => Effect.void,
|
|
112
112
|
onImage: () => Effect.void,
|
|
113
113
|
agentTasks: {
|
|
114
114
|
...agentTasksUnavailable,
|
|
115
|
-
|
|
115
|
+
subagent: ({ id, prompt }) =>
|
|
116
116
|
Effect.gen(function* () {
|
|
117
117
|
assert.strictEqual(prompt, "second")
|
|
118
118
|
yield* Deferred.succeed(secondStarted, undefined)
|
|
@@ -142,12 +142,12 @@ describe("RPC subagent executor", () => {
|
|
|
142
142
|
environment,
|
|
143
143
|
onEnvironment: () => Effect.void,
|
|
144
144
|
script:
|
|
145
|
-
'console.log("parent:" + (await
|
|
145
|
+
'console.log("parent:" + (await subagent({ prompt: "outer" })).output)',
|
|
146
146
|
onTaskComplete: () => Effect.void,
|
|
147
147
|
onImage: () => Effect.void,
|
|
148
148
|
agentTasks: {
|
|
149
149
|
...agentTasksUnavailable,
|
|
150
|
-
|
|
150
|
+
subagent: ({ id, prompt }) =>
|
|
151
151
|
Effect.gen(function* () {
|
|
152
152
|
assert.strictEqual(prompt, "outer")
|
|
153
153
|
const childOutput = yield* executor
|
|
@@ -155,12 +155,12 @@ describe("RPC subagent executor", () => {
|
|
|
155
155
|
environment,
|
|
156
156
|
onEnvironment: () => Effect.void,
|
|
157
157
|
script:
|
|
158
|
-
'console.log("child:" + (await
|
|
158
|
+
'console.log("child:" + (await subagent({ prompt: "inner" })).output)',
|
|
159
159
|
onTaskComplete: () => Effect.void,
|
|
160
160
|
onImage: () => Effect.void,
|
|
161
161
|
agentTasks: {
|
|
162
162
|
...agentTasksUnavailable,
|
|
163
|
-
|
|
163
|
+
subagent: ({ id: innerId, prompt: innerPrompt }) =>
|
|
164
164
|
Effect.sync(() => {
|
|
165
165
|
assert.strictEqual(innerPrompt, "inner")
|
|
166
166
|
return completedAgent(
|
|
@@ -994,15 +994,15 @@ console.log("MAIN" + "_DONE")`)
|
|
|
994
994
|
.execute({
|
|
995
995
|
environment,
|
|
996
996
|
onEnvironment: () => Effect.void,
|
|
997
|
-
// `
|
|
997
|
+
// `subagent` never finishes. The worker then exits through
|
|
998
998
|
// the host's `process`, the way a crashed worker would.
|
|
999
999
|
script: `
|
|
1000
|
-
|
|
1000
|
+
subagent({ prompt: "never finishes" })
|
|
1001
1001
|
sleep(100).then(() => console.constructor.constructor("return process")().exit(7))`,
|
|
1002
1002
|
onTaskComplete: () => Effect.void,
|
|
1003
1003
|
agentTasks: {
|
|
1004
1004
|
...agentTasksUnavailable,
|
|
1005
|
-
|
|
1005
|
+
subagent: () => Effect.never,
|
|
1006
1006
|
},
|
|
1007
1007
|
onImage: () => Effect.void,
|
|
1008
1008
|
})
|
package/src/AgentExecutor.ts
CHANGED
|
@@ -158,16 +158,16 @@ export interface ExecuteOptions {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
* The sub-agents of the agent running a script. `
|
|
161
|
+
* The sub-agents of the agent running a script. `subagent` also receives the
|
|
162
162
|
* environment the new agent starts in: the script's directory at the moment
|
|
163
|
-
* `
|
|
163
|
+
* `subagent` was called, with an update holding everything that applies to
|
|
164
164
|
* it beyond the system prompt.
|
|
165
165
|
*
|
|
166
166
|
* @since 1.0.0
|
|
167
167
|
* @category Models
|
|
168
168
|
*/
|
|
169
|
-
export interface ExecuteAgentTasks extends Omit<AgentTasks, "
|
|
170
|
-
readonly
|
|
169
|
+
export interface ExecuteAgentTasks extends Omit<AgentTasks, "subagent"> {
|
|
170
|
+
readonly subagent: (options: {
|
|
171
171
|
readonly id: string
|
|
172
172
|
readonly prompt: string
|
|
173
173
|
readonly background: boolean
|
|
@@ -313,8 +313,8 @@ export interface LocalOptions<Toolkit extends Toolkit.Any = never> {
|
|
|
313
313
|
readonly limits?: Limits | undefined
|
|
314
314
|
/**
|
|
315
315
|
* Built-in tools to leave out of the sandbox and the type declarations.
|
|
316
|
-
* Leaving out `
|
|
317
|
-
* both `
|
|
316
|
+
* Leaving out `subagent` also leaves out `messageAgent`, and leaving out
|
|
317
|
+
* both `subagent` and `bash` leaves out the task functions.
|
|
318
318
|
* Leaving out `fetch` removes the global Fetch API.
|
|
319
319
|
*/
|
|
320
320
|
readonly excludeTools?: ReadonlyArray<ExcludableTool> | undefined
|
|
@@ -526,10 +526,10 @@ const makeLocalWith = Effect.fnUntraced(function* <
|
|
|
526
526
|
...opts.agentTasks,
|
|
527
527
|
// A new agent has only the system prompt, so it gets everything that
|
|
528
528
|
// applies to the directory.
|
|
529
|
-
|
|
529
|
+
subagent: (options) =>
|
|
530
530
|
renderEnvironment(currentEnvironment(), { reset: true }).pipe(
|
|
531
531
|
Effect.flatMap((environment) =>
|
|
532
|
-
opts.agentTasks.
|
|
532
|
+
opts.agentTasks.subagent({ ...options, environment }),
|
|
533
533
|
),
|
|
534
534
|
),
|
|
535
535
|
}),
|
|
@@ -992,10 +992,10 @@ export const layerRpcServer = <Toolkit extends Toolkit.Any = never>(
|
|
|
992
992
|
request<void>({ _tag: "TaskComplete", summary }),
|
|
993
993
|
agentId,
|
|
994
994
|
agentTasks: {
|
|
995
|
-
|
|
995
|
+
subagent: (options) =>
|
|
996
996
|
Effect.orDie(
|
|
997
997
|
request<Task>({
|
|
998
|
-
_tag: "
|
|
998
|
+
_tag: "Subagent",
|
|
999
999
|
...options,
|
|
1000
1000
|
}),
|
|
1001
1001
|
),
|
|
@@ -1108,7 +1108,7 @@ export const layerRpcServer = <Toolkit extends Toolkit.Any = never>(
|
|
|
1108
1108
|
*/
|
|
1109
1109
|
export const AgentRequest = Schema.TaggedUnion({
|
|
1110
1110
|
TaskComplete: { summary: Schema.String },
|
|
1111
|
-
|
|
1111
|
+
Subagent: {
|
|
1112
1112
|
id: Schema.String,
|
|
1113
1113
|
prompt: Schema.String,
|
|
1114
1114
|
background: Schema.Boolean,
|
|
@@ -1129,7 +1129,7 @@ export const AgentRequest = Schema.TaggedUnion({
|
|
|
1129
1129
|
|
|
1130
1130
|
/**
|
|
1131
1131
|
* The client's answer to a `Request`. `Failure` carries a message for the
|
|
1132
|
-
* script; a failed foreground `
|
|
1132
|
+
* script; a failed foreground `subagent` is raised there as a defect.
|
|
1133
1133
|
*
|
|
1134
1134
|
* @since 1.0.0
|
|
1135
1135
|
* @category Rpcs
|
|
@@ -1305,8 +1305,8 @@ const handleRequest = (
|
|
|
1305
1305
|
switch (request._tag) {
|
|
1306
1306
|
case "TaskComplete":
|
|
1307
1307
|
return opts.onTaskComplete(request.summary)
|
|
1308
|
-
case "
|
|
1309
|
-
return opts.agentTasks.
|
|
1308
|
+
case "Subagent":
|
|
1309
|
+
return opts.agentTasks.subagent(request)
|
|
1310
1310
|
case "TaskOutput":
|
|
1311
1311
|
return opts.agentTasks.taskOutput(request.id)
|
|
1312
1312
|
case "WaitTasks":
|
|
@@ -1380,13 +1380,13 @@ const errorMessage = (error: unknown): string =>
|
|
|
1380
1380
|
? error.message
|
|
1381
1381
|
: String(error)
|
|
1382
1382
|
|
|
1383
|
-
// Leaving out `
|
|
1383
|
+
// Leaving out `subagent` leaves out `messageAgent`. The task functions
|
|
1384
1384
|
// address both kinds, so they go once neither can be started.
|
|
1385
1385
|
const excludedToolNames = (
|
|
1386
1386
|
excludeTools: ReadonlyArray<ExcludableTool> | undefined,
|
|
1387
1387
|
): ReadonlySet<string> => {
|
|
1388
1388
|
const names = new Set<string>(excludeTools)
|
|
1389
|
-
if (names.has("
|
|
1389
|
+
if (names.has("subagent")) {
|
|
1390
1390
|
names.add("messageAgent")
|
|
1391
1391
|
if (names.has("bash")) {
|
|
1392
1392
|
for (const name of ["taskOutput", "waitTasks", "stopTask", "listTasks"]) {
|
package/src/AgentImage.test.ts
CHANGED
|
@@ -268,11 +268,11 @@ describe("Agent images", () => {
|
|
|
268
268
|
}),
|
|
269
269
|
)
|
|
270
270
|
|
|
271
|
-
it.effect("does not copy image bytes into a
|
|
271
|
+
it.effect("does not copy image bytes into a subagent prompt", () =>
|
|
272
272
|
Effect.gen(function* () {
|
|
273
273
|
const executor = makeExecutor(({ agentTasks, environment }) =>
|
|
274
274
|
Stream.fromEffect(
|
|
275
|
-
agentTasks.
|
|
275
|
+
agentTasks.subagent({
|
|
276
276
|
id: "1",
|
|
277
277
|
prompt: "child task: describe the layout",
|
|
278
278
|
background: false,
|
|
@@ -292,7 +292,7 @@ describe("Agent images", () => {
|
|
|
292
292
|
respond: (call, index) => {
|
|
293
293
|
if (index === 0) {
|
|
294
294
|
return Stream.make(
|
|
295
|
-
toolCall("call-1", 'await
|
|
295
|
+
toolCall("call-1", 'await subagent("describe the layout")'),
|
|
296
296
|
)
|
|
297
297
|
}
|
|
298
298
|
const isChild = userText(call.prompt).includes("child task")
|
|
@@ -305,7 +305,7 @@ describe("Agent images", () => {
|
|
|
305
305
|
const child = calls.find((call) =>
|
|
306
306
|
userText(call.prompt).includes("child task"),
|
|
307
307
|
)
|
|
308
|
-
assert.isDefined(child, "the
|
|
308
|
+
assert.isDefined(child, "the subagent call reached the model")
|
|
309
309
|
assert.strictEqual(fileParts(child!.prompt).length, 0)
|
|
310
310
|
// The parent still has its image.
|
|
311
311
|
assert.strictEqual(fileParts(calls[0]!.prompt).length, 1)
|
|
@@ -29,7 +29,7 @@ import * as Compaction from "./Compaction.ts"
|
|
|
29
29
|
// Agent tasks: lifetime and completion delivery.
|
|
30
30
|
//
|
|
31
31
|
// These drive the real Agent loop and a real executor, so the model only
|
|
32
|
-
// talks to the script API: `
|
|
32
|
+
// talks to the script API: `subagent({ prompt, background })`, `waitTasks`,
|
|
33
33
|
// `messageAgent`, `stopTask`, `listTasks` and `taskOutput`. One scripted
|
|
34
34
|
// LanguageModel serves every agent; calls are routed by the task marker in
|
|
35
35
|
// each agent's first user message. Task IDs come from the executor's counter,
|
|
@@ -159,7 +159,7 @@ const complete = (output: string) =>
|
|
|
159
159
|
const spawnBackground = (task: string) =>
|
|
160
160
|
toolCall(
|
|
161
161
|
`spawn-${task}`,
|
|
162
|
-
`const result = await
|
|
162
|
+
`const result = await subagent({ prompt: "${task}", background: true })
|
|
163
163
|
console.log(JSON.stringify(result))`,
|
|
164
164
|
)
|
|
165
165
|
|
|
@@ -459,7 +459,7 @@ for (const [executorName, executorLayer] of executors) {
|
|
|
459
459
|
return Stream.make(
|
|
460
460
|
toolCall(
|
|
461
461
|
"too-early",
|
|
462
|
-
`await
|
|
462
|
+
`await subagent({ prompt: "TASK-CHILD", background: true })
|
|
463
463
|
try {
|
|
464
464
|
await taskComplete("too early")
|
|
465
465
|
console.log("ACCEPTED")
|
|
@@ -768,7 +768,7 @@ console.log("MESSAGE-VOID:", result === undefined)`,
|
|
|
768
768
|
return Stream.make(
|
|
769
769
|
toolCall(
|
|
770
770
|
"foreground",
|
|
771
|
-
`const result = await
|
|
771
|
+
`const result = await subagent({ prompt: "TASK-CHILD" })
|
|
772
772
|
console.log(JSON.stringify(result))`,
|
|
773
773
|
),
|
|
774
774
|
)
|
|
@@ -834,8 +834,8 @@ await taskComplete("${name.toUpperCase()}:" + pwd.output.trim())`,
|
|
|
834
834
|
"spawn",
|
|
835
835
|
`await bash({ command: "mkdir -p a/one a/two" })
|
|
836
836
|
await changeDirectory("a")
|
|
837
|
-
const one = await
|
|
838
|
-
const two = await
|
|
837
|
+
const one = await subagent({ prompt: "TASK-CHILD-ONE", background: true })
|
|
838
|
+
const two = await subagent({ prompt: "TASK-CHILD-TWO", background: true })
|
|
839
839
|
console.log(JSON.stringify(await waitTasks({ ids: [one.id, two.id] })))
|
|
840
840
|
console.log("ROOT:" + (await bash({ command: "pwd" })).output.trim())`,
|
|
841
841
|
),
|
|
@@ -868,7 +868,7 @@ console.log("ROOT:" + (await bash({ command: "pwd" })).output.trim())`,
|
|
|
868
868
|
toolCall(
|
|
869
869
|
"mixed",
|
|
870
870
|
`const bashTask = await bash({ command: "echo BASH-OUT", background: true })
|
|
871
|
-
const agentTask = await
|
|
871
|
+
const agentTask = await subagent({ prompt: "TASK-CHILD", background: true })
|
|
872
872
|
const ended = await waitTasks({ ids: [bashTask.id, agentTask.id] })
|
|
873
873
|
console.log(JSON.stringify(ended.map(({ kind, status, output }) => ({ kind, status, output: output.trim() }))))`,
|
|
874
874
|
),
|
|
@@ -931,7 +931,7 @@ await taskComplete(JSON.stringify({ seen, attempts }))`,
|
|
|
931
931
|
toolCall(
|
|
932
932
|
"spawn",
|
|
933
933
|
`const server = await bash({ command: "sleep 30", background: true })
|
|
934
|
-
const child = await
|
|
934
|
+
const child = await subagent({ prompt: "TASK-CHILD BASH-ID:" + server.id })
|
|
935
935
|
console.log("CHILD:" + child.output)
|
|
936
936
|
const mine = await listTasks()
|
|
937
937
|
console.log("ROOT:" + JSON.stringify(mine.map((task) => task.kind + ":" + task.status).sort()))`,
|
|
@@ -988,7 +988,7 @@ console.log("ROOT:" + JSON.stringify(mine.map((task) => task.kind + ":" + task.s
|
|
|
988
988
|
return Stream.make(
|
|
989
989
|
toolCall(
|
|
990
990
|
"wait",
|
|
991
|
-
`const child = await
|
|
991
|
+
`const child = await subagent({ prompt: "TASK-CHILD", background: true })
|
|
992
992
|
const [task] = await waitTasks({ ids: [child.id], timeoutMs: 200 })
|
|
993
993
|
console.log("WAITED:" + task.status)`,
|
|
994
994
|
),
|
|
@@ -1035,7 +1035,7 @@ console.log("WAITED:" + task.status)`,
|
|
|
1035
1035
|
toolCall(
|
|
1036
1036
|
"wait",
|
|
1037
1037
|
`const quick = await bash({ command: "echo BASH-OUT", background: true })
|
|
1038
|
-
const child = await
|
|
1038
|
+
const child = await subagent({ prompt: "TASK-CHILD", background: true })
|
|
1039
1039
|
const slow = await bash({ command: "sleep 30", background: true })
|
|
1040
1040
|
await waitTasks({ ids: [quick.id, child.id, slow.id] })
|
|
1041
1041
|
console.log("RETURNED")`,
|
|
@@ -1118,8 +1118,8 @@ describe("agent tasks (rpc executor, slow callbacks)", () => {
|
|
|
1118
1118
|
return Stream.make(
|
|
1119
1119
|
toolCall(
|
|
1120
1120
|
"wait",
|
|
1121
|
-
`const a = await
|
|
1122
|
-
const b = await
|
|
1121
|
+
`const a = await subagent({ prompt: "TASK-CHILD-A", background: true })
|
|
1122
|
+
const b = await subagent({ prompt: "TASK-CHILD-B", background: true })
|
|
1123
1123
|
const ended = await waitTasks({ ids: [a.id, b.id] })
|
|
1124
1124
|
console.log(ended.map((task) => task.output).join(" "))`,
|
|
1125
1125
|
),
|
package/src/AgentTools.ts
CHANGED
|
@@ -59,7 +59,7 @@ export class TaskCompleter extends Context.Service<
|
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* What a task is: a background `bash` command or a sub-agent started with
|
|
62
|
-
* `
|
|
62
|
+
* `subagent`.
|
|
63
63
|
*
|
|
64
64
|
* @since 1.0.0
|
|
65
65
|
* @category Models
|
|
@@ -130,7 +130,7 @@ export interface AgentTasks {
|
|
|
130
130
|
* it resolves once the agent has finished, and dies if the agent failed.
|
|
131
131
|
* In the background it resolves straight away with `status: "running"`.
|
|
132
132
|
*/
|
|
133
|
-
readonly
|
|
133
|
+
readonly subagent: (options: {
|
|
134
134
|
readonly id: string
|
|
135
135
|
readonly prompt: string
|
|
136
136
|
readonly background: boolean
|
|
@@ -184,7 +184,7 @@ export class AgentTaskExecutor extends Context.Service<
|
|
|
184
184
|
* @category Context
|
|
185
185
|
*/
|
|
186
186
|
export const agentTasksUnavailable: AgentTasks = {
|
|
187
|
-
|
|
187
|
+
subagent: () => Effect.die(new Error("Sub-agents are not available here")),
|
|
188
188
|
taskOutput: () => Effect.fail("Sub-agents are not available here"),
|
|
189
189
|
waitTasks: () => Effect.fail("Sub-agents are not available here"),
|
|
190
190
|
messageAgent: () => Effect.fail("Sub-agents are not available here"),
|
|
@@ -387,7 +387,7 @@ export const AgentTools = Toolkit.make(
|
|
|
387
387
|
success: Schema.String,
|
|
388
388
|
dependencies: [CurrentDirectory],
|
|
389
389
|
}),
|
|
390
|
-
Tool.make("
|
|
390
|
+
Tool.make("subagent", {
|
|
391
391
|
description:
|
|
392
392
|
"Delegate a task to another software engineer / sub-agent. With `background: true` the sub-agent works in the background, and its result is sent to you when it finishes.",
|
|
393
393
|
parameters: Schema.Struct({
|
|
@@ -1174,14 +1174,14 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
1174
1174
|
|
|
1175
1175
|
return `Success. Updated the following files:\n${out.join("\n")}`
|
|
1176
1176
|
}, Effect.orDie),
|
|
1177
|
-
|
|
1178
|
-
const { prompt, background = false } = yield*
|
|
1179
|
-
yield* Effect.logInfo(`Calling "
|
|
1177
|
+
subagent: Effect.fn("AgentTools.subagent")(function* (options: unknown) {
|
|
1178
|
+
const { prompt, background = false } = yield* decodeSubagent(options)
|
|
1179
|
+
yield* Effect.logInfo(`Calling "subagent"`).pipe(
|
|
1180
1180
|
Effect.annotateLogs({ background }),
|
|
1181
1181
|
)
|
|
1182
1182
|
const id = yield* registerAgentTask()
|
|
1183
1183
|
const agentTasks = yield* AgentTaskExecutor
|
|
1184
|
-
return yield* agentTasks.
|
|
1184
|
+
return yield* agentTasks.subagent({ id, prompt, background })
|
|
1185
1185
|
}),
|
|
1186
1186
|
messageAgent: Effect.fn("AgentTools.messageAgent")(function* (
|
|
1187
1187
|
input: unknown,
|
|
@@ -1250,9 +1250,9 @@ const decodeParams = <S extends Schema.Decoder<unknown>>(
|
|
|
1250
1250
|
return (input: unknown) => Effect.mapError(decode(input), () => usage)
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
1253
|
-
const
|
|
1254
|
-
AgentTools.tools.
|
|
1255
|
-
'
|
|
1253
|
+
const decodeSubagent = decodeParams(
|
|
1254
|
+
AgentTools.tools.subagent.parametersSchema,
|
|
1255
|
+
'subagent requires an options object, for example: subagent({ prompt: "..." }) or subagent({ prompt: "...", background: true }).',
|
|
1256
1256
|
)
|
|
1257
1257
|
const decodeMessageAgent = decodeParams(
|
|
1258
1258
|
AgentTools.tools.messageAgent.parametersSchema,
|
package/src/McpServers.test.ts
CHANGED
|
@@ -853,7 +853,7 @@ await taskComplete(JSON.stringify({ crashed, after: await attempt(mcp.fake.echo(
|
|
|
853
853
|
return "await taskComplete(await mcp.fake.ping({}))"
|
|
854
854
|
}
|
|
855
855
|
return call.index === 0
|
|
856
|
-
? `const child = await
|
|
856
|
+
? `const child = await subagent({ prompt: "TASK-CHILD" })
|
|
857
857
|
console.log(JSON.stringify(child))
|
|
858
858
|
console.log(await mcp.fake.screenshot({}))`
|
|
859
859
|
: 'await taskComplete("done")'
|