AS AgentScopeAPI 手册 / API Reference

SubagentSpecGenerator

public final class SubagentSpecGenerator
源码Source 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.

参数Parameters
名称Name类型Type说明Description
modelModel模型实例(类型 `Model`)。The model.
源码Source 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.

参数Parameters
名称Name类型Type说明Description
descriptionString描述(类型 `String`)。free-form description of what the agent should do
existingIdsCollection<String>existing Ids(类型 `Collection`)。names already registered; the model is told to avoid these
返回Returns Mono<String>
返回Mono。raw markdown returned by the model (trimmed; otherwise unprocessed)
源码Source io/agentscope/harness/agent/subagent/SubagentSpecGenerator.java:95–122

generateAndValidate

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.

参数Parameters
名称Name类型Type说明Description
descriptionString描述(类型 `String`)。free-form description
agentNameString智能体名称(类型 `String`)。name to assign the parsed declaration (also reserved against `existingIds`)
existingIdsCollection<String>existing Ids(类型 `Collection`)。existing agent ids
mainWorkspacePath主工作区(类型 `Path`)。workspace root for resolving any relative `workspace.path`; may be `null`
返回Returns Mono<GeneratedSpec>
返回Mono。tuple of the raw markdown and the parsed `SubagentDeclaration`
源码Source 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.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.