This commit is contained in:
@@ -227,6 +227,7 @@ export function pickAgents(userText, maxAgents = 3) {
|
||||
* tools: { run: (name: string, args?: object) => Promise<any> },
|
||||
* query: string,
|
||||
* maxAgents?: number,
|
||||
* isAborted?: () => boolean,
|
||||
* onAgent?: (ev: {
|
||||
* id: string,
|
||||
* label: string,
|
||||
@@ -239,15 +240,36 @@ export function pickAgents(userText, maxAgents = 3) {
|
||||
export async function runSubAgents(opts) {
|
||||
const specs = pickAgents(opts.query, opts.maxAgents ?? 3)
|
||||
const tools = opts.tools
|
||||
const aborted = () => Boolean(opts.isAborted?.())
|
||||
|
||||
/** @type {Array<{ id: string, label: string, status: string, summary: string, result?: any, error?: string }>} */
|
||||
const agents = []
|
||||
|
||||
await Promise.all(
|
||||
specs.map(async (spec) => {
|
||||
if (aborted()) {
|
||||
agents.push({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
status: 'error',
|
||||
summary: 'stopped',
|
||||
error: 'stopped',
|
||||
})
|
||||
return
|
||||
}
|
||||
opts.onAgent?.({ id: spec.id, label: spec.label, status: 'start' })
|
||||
try {
|
||||
const result = await spec.run(tools)
|
||||
if (aborted()) {
|
||||
agents.push({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
status: 'error',
|
||||
summary: 'stopped',
|
||||
error: 'stopped',
|
||||
})
|
||||
return
|
||||
}
|
||||
const summary = spec.summarize(result)
|
||||
const row = {
|
||||
id: spec.id,
|
||||
|
||||
Reference in New Issue
Block a user