feat(subagent): catalog one-shot child sessions

This commit is contained in:
Dudu-0223
2026-07-27 16:58:37 +08:00
committed by Tianyi Cui
parent de6e572e51
commit 774ee34b9a
85 changed files with 1034 additions and 539 deletions

View File

@@ -322,6 +322,7 @@ export class WorkerRun implements WorkflowRun {
let run: SubagentRun
try {
run = await this.subagents.start(this.provider, {
label: request.label,
prompt: [{ type: 'text', text: request.prompt }],
parent: this.parent,
signal: this.controller.signal,

View File

@@ -275,6 +275,7 @@ export class WorkflowExecution {
let run: ChildHandle
try {
run = await this.children.startAgent({
label,
prompt: rawPrompt,
...opts.schema !== undefined ? { schema: opts.schema } : {},
...opts.provider !== undefined ? { provider: opts.provider } : {},

View File

@@ -38,6 +38,8 @@ export interface WorkerInit {
/** What the worker asks the host to start for one `agent()` call (options already validated worker-side). */
export interface ChildStartRequest {
/** Short display label resolved by the worker runtime. */
label: string
/** The child's prompt text. */
prompt: string
/** The structured-output schema, if the call passed one (already subset-checked). */

View File

@@ -420,10 +420,13 @@ describe('runWorkerSession over an in-process MessageChannel', () => {
`))
await host.result()
const starts = host.ofType(WorkerToHostType.AgentStart).map(m => m.info)
const requests = host.ofType(WorkerToHostType.ChildStart).map(m => m.request)
expect(starts[0]).toMatchObject({ seq: 1, phase: 'Find' })
expect(starts[0]!.label.length).toBeLessThanOrEqual(48)
expect(starts[0]!.label).not.toContain('second line')
expect(starts[1]).toMatchObject({ seq: 2, label: 'named', phase: 'Custom' })
expect(requests[0]!.label).toBe(starts[0]!.label)
expect(requests[1]!.label).toBe('named')
host.close()
})

View File

@@ -211,7 +211,7 @@ describe('dsh-workflow-workerthread', () => {
reply: () => ({ output: [], structured: { files: ['x.ts', 'y.ts'] }, stopReason: 'completed' }),
})
const result = await run(ctx, parent, scripted(`
const found = await agent('list files', { model: 'deepseek-v4-pro', schema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' } } }, required: ['files'] } })
const found = await agent('list files', { label: 'inventory', model: 'deepseek-v4-pro', schema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' } } }, required: ['files'] } })
return { first: found.files[0], count: found.files.length }
`))
expect(result.value).toEqual({ first: 'x.ts', count: 2 })
@@ -221,6 +221,7 @@ describe('dsh-workflow-workerthread', () => {
required: ['files'],
})
expect(provider.runs[0]!.request.agentOptions).toEqual({ model: 'deepseek-v4-pro' })
expect(provider.runs[0]!.request.label).toBe('inventory')
expect(provider.runs[0]!.request.parent).toBeDefined()
})