SubagentSpecGenerator
public final class SubagentSpecGenerator
io/agentscope/harness/agent/subagent/SubagentSpecGenerator.java:44–159子智能体规格 Generator,支持智能体之间的发现、委派与协作。位于 io.agentscope.harness.agent.subagent 包。核心成员包括 generateMarkdown、generateAndValidate、SubagentSpecGenerator。
LLM-driven generator for SubagentDeclaration markdown specs.
Given a free-form description of an agent's purpose, prompts the supplied Model to
emit a markdown document with YAML frontmatter conforming to AgentSpecLoader's schema.
The output is parseable round-trip via AgentSpecLoader#parse.
This is the Java analogue of opencode's Agent.generate flow (opencode/packages/opencode/src/agent/agent.ts). Intended to be called from a CLI scaffolder or
from io.agentscope.harness.agent.tool.AgentGenerateTool during a live session.
Reuses the same model.stream(messages, null, null).reduce(...) pattern used by
io.agentscope.harness.agent.memory.compaction.ConversationCompactor for one-shot LLM
calls, so behaviour stays consistent with other internal LLM users in the harness.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
GeneratedSpec | 记录record | 承载 Generated 规格数据的记录类型。 Pair of the raw markdown and the parsed `SubagentDeclaration`. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public SubagentSpecGenerator(Model model) | 初始化 `SubagentSpecGenerator` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<String> generateMarkdown(String description, Collection<String> existingIds) | 执行 `generateMarkdown` 方法。 Generates a markdown spec for a new subagent without validation. |
public Mono<GeneratedSpec> generateAndValidate(String description, String agentName, Collection<String> existingIds, Path mainWorkspace) | 执行 `generateAndValidate` 方法。 Generates a markdown spec and validates it by round-tripping through
`AgentSpecLoader#parse`. |
构造器详情Constructor Detail
SubagentSpecGenerator
public SubagentSpecGenerator(Model model)
初始化 SubagentSpecGenerator 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | Model | 模型实例(类型 `Model`)。The model. |
io/agentscope/harness/agent/subagent/SubagentSpecGenerator.java:82–84方法详情Method Detail
generateMarkdown
public Mono<String> generateMarkdown(String description, Collection<String> existingIds)
执行 generateMarkdown 方法。
Generates a markdown spec for a new subagent without validation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
description | String | 描述(类型 `String`)。free-form description of what the agent should do |
existingIds | Collection<String> | existing Ids(类型 `Collection`)。names already registered; the model is told to avoid these |
Mono<String>io/agentscope/harness/agent/subagent/SubagentSpecGenerator.java:95–122generateAndValidate
public Mono<GeneratedSpec> generateAndValidate(String description, String agentName, Collection<String> existingIds, Path mainWorkspace)
执行 generateAndValidate 方法。
Generates a markdown spec and validates it by round-tripping through AgentSpecLoader#parse.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
description | String | 描述(类型 `String`)。free-form description |
agentName | String | 智能体名称(类型 `String`)。name to assign the parsed declaration (also reserved against `existingIds`) |
existingIds | Collection<String> | existing Ids(类型 `Collection`)。existing agent ids |
mainWorkspace | Path | 主工作区(类型 `Path`)。workspace root for resolving any relative `workspace.path`; may be `null` |
Mono<GeneratedSpec>io/agentscope/harness/agent/subagent/SubagentSpecGenerator.java:137–155嵌套类详情Nested Class Detail
GeneratedSpec
public record GeneratedSpec(String markdown, SubagentDeclaration declaration)承载 Generated 规格数据的记录类型。位于 io.agentscope.harness.agent.subagent 包。核心成员包括 markdown、declaration。
Pair of the raw markdown and the parsed SubagentDeclaration.