Skip to content

fix(workspace): inject subagents and skills summary into workspace co…#1665

Open
hangweizhang wants to merge 1 commit into
agentscope-ai:mainfrom
hangweizhang:fix/issue-1650-workspace-file-not-used
Open

fix(workspace): inject subagents and skills summary into workspace co…#1665
hangweizhang wants to merge 1 commit into
agentscope-ai:mainfrom
hangweizhang:fix/issue-1650-workspace-file-not-used

Conversation

@hangweizhang

Copy link
Copy Markdown
Contributor

…ntext

The WorkspaceContextMiddleware previously only injected AGENTS.md, MEMORY.md, and knowledge/ content into the system prompt. Subagent declarations and skill directories were not included in the injected workspace context, causing the LLM to be unaware of available subagents and skills defined in the workspace.

This change adds:

  • SUBAGENTS_DIR constant to WorkspaceConstants
  • getSubagentsDir(), listSubagentFiles(), listSkillDirs() methods to WorkspaceManager
  • buildSubagentsBlock() and buildSkillsBlock() in WorkspaceContextMiddleware to inject subagent and skill summaries (name + description from YAML frontmatter) into <loaded_context>
  • extractDescriptionFromFrontmatter() utility for parsing YAML frontmatter description fields
  • Unit tests for extractDescriptionFromFrontmatter()

Closes #1650

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.12, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

…ntext

The WorkspaceContextMiddleware previously only injected AGENTS.md,
MEMORY.md, and knowledge/ content into the system prompt. Subagent
declarations and skill directories were not included in the injected
workspace context, causing the LLM to be unaware of available
subagents and skills defined in the workspace.

This change adds:
- SUBAGENTS_DIR constant to WorkspaceConstants
- getSubagentsDir(), listSubagentFiles(), listSkillDirs() methods to
  WorkspaceManager
- buildSubagentsBlock() and buildSkillsBlock() in
  WorkspaceContextMiddleware to inject subagent and skill summaries
  (name + description from YAML frontmatter) into <loaded_context>
- extractDescriptionFromFrontmatter() utility for parsing YAML
  frontmatter description fields
- Unit tests for extractDescriptionFromFrontmatter()

Closes agentscope-ai#1650
@hangweizhang hangweizhang requested a review from a team June 7, 2026 02:45
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.25806% with 53 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...cope/harness/agent/workspace/WorkspaceManager.java 49.15% 22 Missing and 8 partials ⚠️
...s/agent/middleware/WorkspaceContextMiddleware.java 64.61% 18 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Jun 7, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR adds subagent and skill directory summaries to the workspace context injected into the system prompt, closing issue #1650. The implementation follows existing patterns in WorkspaceContextMiddleware (mirroring buildKnowledgeBlock) and adds new listing methods to WorkspaceManager. The overall approach is sound and the token budget accounting is correctly updated. However, there are two notable issues: (1) YAML-quoted description values (e.g. description: "foo") are not unquoted, leaking literal " characters into the LLM prompt, and (2) the new XML blocks use a different indentation strategy from the existing buildXmlContext helper, producing inconsistent output.

if (trimmed.startsWith("description:")) {
return trimmed.substring("description:".length()).strip();
}
if (trimmed.startsWith("description :")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Quoted YAML description values are not unquoted. If frontmatter contains description: "Code review specialist", this line returns the literal string "Code review specialist" (with quote characters), which leaks into the LLM prompt. The test extractDescriptionFromFrontmatter_quotedDescription even asserts this incorrect behavior.

Suggested fix — strip matching surrounding quotes:

String value = trimmed.substring("description:".length()).strip();
if (value.length() >= 2
        && ((value.startsWith("\"") && value.endsWith("\""))
                || (value.startsWith("'") && value.endsWith("'")))) {
    value = value.substring(1, value.length() - 1);
}
return value;

Also update the test expectation to assertEquals("A long description with special chars: @#$", desc);.

sb.append(buildXmlContext("agents_context", agentsContent));
sb.append(buildXmlContext("memory_context", memoryContent));
sb.append(buildXmlContext("domain_knowledge_context", knowledgeBlock));
if (!subagentsBlock.isBlank()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] Indentation inconsistency: buildSubagentsBlock / buildSkillsBlock produce XML blocks whose inner content is not indented, yet buildLoadedContextSection prepends only " " (2 spaces) to the whole block. This yields output like:

  <subagents_context>
Available subagents:
- foo
</subagents_context>

While buildXmlContext (used for agents/memory/knowledge) correctly indents every inner line by 2 spaces.

Suggested fix: apply indentByTwo inside buildSubagentsBlock / buildSkillsBlock (similar to how buildAdditionalContextBlock works), or wrap them via buildXmlContext for consistency.

+ "\n"
+ "Body text.";
String desc = WorkspaceContextMiddleware.extractDescriptionFromFrontmatter(content);
assertNotNull(desc);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] This assertion codifies the buggy behavior: the expected value still includes the literal quote characters (\"A long description...\"). After fixing extractDescriptionFromFrontmatter to strip YAML quotes, update this to:

assertEquals("A long description with special chars: @#$", desc);

return trimmed.substring("description:".length()).strip();
}
if (trimmed.startsWith("description :")) {
return trimmed.substring("description :".length()).strip();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The second branch description : (with a space before the colon) is non-standard YAML and unlikely to appear in real frontmatter. While harmless, consider removing it to keep the parser minimal, or document that it's intentional leniency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:Never use workspace file

2 participants