fix(core): limit subagent nesting depth (#37124)
Co-authored-by: Dax <mail@thdxr.com>
This commit is contained in:
committed by
GitHub
parent
656f299017
commit
285d315b4e
@@ -388,6 +388,86 @@ describe("tool.task", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("prevents subagents from launching subagents by default", () =>
|
||||
Effect.gen(function* () {
|
||||
const sessions = yield* Session.Service
|
||||
const { chat, assistant } = yield* seed()
|
||||
const child = yield* sessions.create({ parentID: chat.id, title: "child" })
|
||||
const nestedAssistant = yield* sessions.updateMessage({
|
||||
...assistant,
|
||||
id: MessageID.ascending(),
|
||||
parentID: MessageID.ascending(),
|
||||
sessionID: child.id,
|
||||
})
|
||||
const tool = yield* TaskTool
|
||||
const def = yield* tool.init()
|
||||
let asked = false
|
||||
|
||||
const exit = yield* def
|
||||
.execute(
|
||||
{
|
||||
description: "inspect bug",
|
||||
prompt: "look into the cache key path",
|
||||
subagent_type: "general",
|
||||
},
|
||||
{
|
||||
sessionID: child.id,
|
||||
messageID: nestedAssistant.id,
|
||||
agent: "general",
|
||||
abort: new AbortController().signal,
|
||||
extra: { promptOps: stubOps() },
|
||||
messages: [],
|
||||
metadata: () => Effect.void,
|
||||
ask: () => Effect.sync(() => (asked = true)),
|
||||
},
|
||||
)
|
||||
.pipe(Effect.exit)
|
||||
|
||||
expect(Exit.isFailure(exit)).toBe(true)
|
||||
expect(asked).toBe(false)
|
||||
expect(yield* sessions.children(child.id)).toHaveLength(0)
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance(
|
||||
"allows nested subagents up to the configured depth",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const sessions = yield* Session.Service
|
||||
const { chat, assistant } = yield* seed()
|
||||
const child = yield* sessions.create({ parentID: chat.id, title: "child" })
|
||||
const nestedAssistant = yield* sessions.updateMessage({
|
||||
...assistant,
|
||||
id: MessageID.ascending(),
|
||||
parentID: MessageID.ascending(),
|
||||
sessionID: child.id,
|
||||
})
|
||||
const tool = yield* TaskTool
|
||||
const def = yield* tool.init()
|
||||
|
||||
const result = yield* def.execute(
|
||||
{
|
||||
description: "inspect bug",
|
||||
prompt: "look into the cache key path",
|
||||
subagent_type: "general",
|
||||
},
|
||||
{
|
||||
sessionID: child.id,
|
||||
messageID: nestedAssistant.id,
|
||||
agent: "general",
|
||||
abort: new AbortController().signal,
|
||||
extra: { promptOps: stubOps() },
|
||||
messages: [],
|
||||
metadata: () => Effect.void,
|
||||
ask: () => Effect.void,
|
||||
},
|
||||
)
|
||||
|
||||
expect((yield* sessions.get(result.metadata.sessionId)).parentID).toBe(child.id)
|
||||
}),
|
||||
{ config: { subagent_depth: 2 } },
|
||||
)
|
||||
|
||||
it.instance(
|
||||
"execute shapes child permissions for task, todowrite, and primary tools",
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user