Class SubagentSpecGenerator
java.lang.Object
io.agentscope.harness.agent.subagent.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(java.lang.String, java.lang.String, java.nio.file.Path).
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 AgentGenerateTool during a live session.
Reuses the same model.stream(messages, null, null).reduce(...) pattern used by
ConversationCompactor for one-shot LLM
calls, so behaviour stays consistent with other internal LLM users in the harness.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordPair of the raw markdown and the parsedSubagentDeclaration. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<SubagentSpecGenerator.GeneratedSpec> generateAndValidate(String description, String agentName, Collection<String> existingIds, Path mainWorkspace) Generates a markdown spec and validates it by round-tripping throughAgentSpecLoader.parse(java.lang.String, java.lang.String, java.nio.file.Path).reactor.core.publisher.Mono<String> generateMarkdown(String description, Collection<String> existingIds) Generates a markdown spec for a new subagent without validation.
-
Constructor Details
-
SubagentSpecGenerator
public SubagentSpecGenerator(io.agentscope.core.model.Model model)
-
-
Method Details
-
generateMarkdown
public reactor.core.publisher.Mono<String> generateMarkdown(String description, Collection<String> existingIds) Generates a markdown spec for a new subagent without validation. PrefergenerateAndValidate(java.lang.String, java.lang.String, java.util.Collection<java.lang.String>, java.nio.file.Path)unless you need to inspect or massage the markdown before it goes throughAgentSpecLoader.- Parameters:
description- free-form description of what the agent should doexistingIds- names already registered; the model is told to avoid these- Returns:
- raw markdown returned by the model (trimmed; otherwise unprocessed)
-
generateAndValidate
public reactor.core.publisher.Mono<SubagentSpecGenerator.GeneratedSpec> generateAndValidate(String description, String agentName, Collection<String> existingIds, Path mainWorkspace) Generates a markdown spec and validates it by round-tripping throughAgentSpecLoader.parse(java.lang.String, java.lang.String, java.nio.file.Path). Emits anIllegalStateExceptionif the LLM output is malformed (missing frontmatter terminator, missing requireddescription, etc.).- Parameters:
description- free-form descriptionagentName- name to assign the parsed declaration (also reserved againstexistingIds)existingIds- existing agent idsmainWorkspace- workspace root for resolving any relativeworkspace.path; may benull- Returns:
- tuple of the raw markdown and the parsed
SubagentDeclaration
-