任务

常规多智能体路径只有一个模型可见的 task 工具。它的 tasks 数组既可提交一个 聚焦子任务,也可提交多个相互独立的子任务并发扇出。子运行上下文相互隔离,只向父 智能体返回紧凑结果,而不是完整对话记录。

同一个委派核心也驱动自动子智能体委派。需要运行时主动为高置信工作启动专用 子智能体时启用它;如果只想让自动委派串行执行,可以用 autoParallel: false 关闭自动并行扇出。

Web 界面可以把这些状态分别展示为计划列表和子智能体运行列表,并用任务标识关联两者。

内置子智能体

智能体适用场景
explore只读代码搜索、文件检查和结构发现。
plan只读实现计划和架构分析。
general / general-purpose多步骤实现工作,可读写并执行命令。
verification聚焦检查、复现、回归验证和对抗测试。
review以发现为先的代码审查,关注正确性、回归、安全与可维护性。

可以显式提及它们,例如 @review、@agent-plan、使用 verification 子智能体 或 委派给 general-purpose。

手动委派

让父智能体委派一个有边界的子任务:

Text
Use task to ask an explore agent to inspect the auth module.
Return files inspected, findings, risks, and confidence.

宿主已经知道任务边界时,可以直接调用 SDK 辅助方法:

TypeScript
const task = await session.task({
agent: 'explore',
description: 'Inspect auth module',
prompt: 'Return files inspected, findings, risks, and confidence.',
});
if (task.exitCode !== 0) throw new Error(task.output);
console.log(task.output);

子智能体应返回紧凑契约:

  • 摘要
  • 已检查或修改的文件
  • 证据引用
  • 风险和未知项
  • 置信度

父智能体不应吞入完整的子对话记录。

并行委派

当工作彼此独立时,在一次 task 调用中提交多个 tasks 项,或使用 session.tasks(...) 并发执行:

Text
Run one task call with three independent tasks:
1. inspect provider config parsing
2. inspect Node SDK declarations
3. inspect release scripts
Merge the results into one release-readiness report.
TypeScript
const batch = await session.tasks([
{
agent: 'explore',
description: 'Inspect config',
prompt: 'Check provider parsing.',
},
{
agent: 'verification',
description: 'Verify SDK',
prompt: 'Check SDK declarations.',
},
]);
if (batch.exitCode !== 0) throw new Error(batch.output);
console.log(batch.output);

统一 task 调用接受 1–32 个任务。只有单任务调用可以设置 background;多任务调用 会收集所有分支,因此拒绝 background: true。默认要求所有分支成功;仅在允许不完整 证据的场景使用 allow_partial_failure,且 min_success_count 只能在该模式下设置。

session.task(...) 和 session.tasks(...) 都返回来自 task 工具的 ToolResult。 读取 output 获取紧凑摘要,并在信任结果前检查 exitCode。会话选项中的 maxParallelTasks 与 ACL 中的 max_parallel_tasks 会限制同级任务扇出。

旧名称 parallel_task 仅作为隐藏的宿主兼容别名保留,用于持久化调用和显式 session.parallelTask(...) 集成;模型不会收到它。新的策略、提示词和 Flow 步骤应使用 task。

自动委派

自动委派默认需要显式启用。运行时会把当前请求与内置或自定义智能体描述进行评分, 并在置信度足够时启动最多 maxTasks 个子运行。

TypeScript
const session = agent.session('/repo', {
autoDelegation: { enabled: true, minConfidence: 0.72, maxTasks: 4 },
maxParallelTasks: 8,
autoParallel: false,
});
ACL
auto_delegation {
enabled = true
auto_parallel = false
min_confidence = 0.72
max_tasks = 4
}

autoParallel: false / auto_parallel = false 是自动并行子智能体扇出的全局开关。 手动 task 扇出和 session.tasks(...) 仍然可用。

智能体目录

通过 agentDirs、agent_dirs 或 A3S 内置目录加载自定义智能体定义:

TypeScript
const session = agent.session('/repo', { agentDirs: ['./.a3s/agents'] });
const loaded = session.registerAgentDir('./more-agents');

A3S 会扫描配置的 agent_dirs、项目/用户 .a3s/agents,以及 Claude 兼容的 .claude/agents 迁移路径。新项目优先使用 .a3s/agents。

Markdown agent 文件支持 frontmatter:

Markdown
---
name: docs-auditor
description: Use proactively after documentation changes
tools: Read, Grep, Glob
disallowedTools:
- Write
- Bash(rm:*)
---
Audit docs for drift, broken examples, and unclear migration notes.

tools 字段是 allowlist。disallowedTools 是 denylist,且优先级高于 allowlist。模型路由字段不属于这个兼容层。

工作智能体

通过 workerAgents 或 registerWorkerAgent() 注册一次性 worker agents:

TypeScript
const session = agent.session('/repo', {
workerAgents: [
{
name: 'frontend-worker',
description: 'Small verified frontend fixes',
kind: 'implementer',
model: 'provider/model-id',
maxSteps: 24,
confirmationInheritance: 'auto_approve',
},
],
});

确认继承

通过 confirmationInheritance 控制子运行如何处理 Ask 决策:

  • 'auto_approve'(默认):子运行自动批准所有 Ask 决策
  • 'deny_on_ask':子运行遇到 Ask 时立即失败
  • 'inherit_parent':子运行继承父级的确认策略

旧生命周期控制面 API 已移除;需要 UI 状态时,应用应消费 streaming events、run replay,以及 Node cancelRun(runId)。

可编程编排

本页的所有内容都是模型驱动的:task、session.task(...) / session.tasks(...) 以及自动委派让 LLM 决定何时以及如何扇出。当宿主已经知道工作的 形态并希望它确定可复现时,改用 session.parallel(...)、session.pipeline(...) 和 session.parallelResumable(...) 以编程方式表达。开发者定义的扇出、无屏障流水线以及 可恢复或可迁移工作流见编排。