Repository navigation
feat(harness): add disableKnowledgeContext() builder method - #3287
z43460018724 wants to merge 21 commits into
Conversation
3ea275e to
7bda987
Compare
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Adds a granular disableKnowledgeContext() switch on HarnessAgent.Builder that suppresses the ## Domain Knowledge guidance, knowledge/KNOWLEDGE.md and the knowledge file catalog, while leaving AGENTS.md, MEMORY.md and the memory tools intact. The approach is sound and the backward compatibility is handled properly — the 6-arg constructor delegates with false, and the IO short-circuit in buildWorkspaceSection avoids the readKnowledgeMd() read entirely rather than reading and discarding. mergeable is clean and Check License / Check Module Sync are green (build still running at review time).
Three things keep this from an approve:
- Subagents don't inherit the switch.
HarnessAgentBuilderSupportpropagates every siblingdisable*flag to both subagent factories; this one is missing from both, so a subagent of an agent that disabled knowledge context still gets the full knowledge injection. - No tests. The diff is production-only; the PR body lists the test as "suggested".
WorkspaceContextMiddlewareMemoryPromptTestis a ready-made template for exactly these assertions. - No docs.
docs/v2/{en,zh}/docs/harness/workspace.mdtabulate every otherdisable*switch and currently state thatknowledge/can only be switched off viadisableWorkspaceContext().
Minor prompt-shape notes (empty <domain_knowledge_context> element, possibly-empty guidance block, constructor arity) are inline.
Findings
- [Warning]
HarnessAgent.java:1253—disableKnowledgeContextis not captured/propagated in either subagent factory inHarnessAgentBuilderSupport - [Warning]
HarnessAgent.java:2257— no test coverage added for the new switch or the two new notice variants - [Warning]
HarnessAgent.java:2249-2261—docs/v2/en+docs/v2/zhharness/workspace.mdswitch tables not updated - [Info]
WorkspaceContextMiddleware.java:194— seventh positional param / third adjacent boolean on a public constructor; a setter would match the existingsetArtifactDeliveryEnabledpattern - [Info]
WorkspaceContextMiddleware.java:303—buildGuidance()can now return a lone"\n", leaving an empty guidance block in the assembled prompt - [Info]
WorkspaceContextMiddleware.java:624— an empty<domain_knowledge_context></domain_knowledge_context>element is still emitted; consider skipping it likeadditionalBlock
Not blocking: none of the above changes behaviour for callers who leave the flag off — default path is byte-identical.
Automated review by github-manager-bot
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
All 6 review comments addressed in commit
CI re-triggered on new commit. Tests: 17/17 pass (5 new + 12 existing). |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed at f432b189 after the feedback round. All four follow-up items from the previous review are resolved and I verified each against the new commit rather than the replies:
- Subagent propagation —
disableKnowledgeContextis now captured and re-applied in both sibling sites (HarnessAgentBuilderSupport.java:341/398and:465/570), matching howdisableMemoryTools/disableMemoryHooksare handled, so a parent's switch no longer leaks back into spawned children. - Tests —
WorkspaceContextMiddlewareKnowledgePromptTestadds 5 cases, all green in CI on this head (WorkspaceContextMiddlewareKnowledgePromptTest→Tests run: 5, Failures: 0), covering guidance + content + catalog suppression, bothWorkspace Files (Injected)notice variants and the default-enabled path. The existingWorkspaceContextMiddlewareMemoryPromptTestassertions on<domain_knowledge_context>still hold, so the two suites do not contradict each other. - Docs — both
docs/v2/enanddocs/v2/zhgained the switch row plus the trimmed guidance/<domain_knowledge_context>rows, in the same table asdisableWorkspaceContext(). - Empty-element and blank-guidance edges —
if (!knowledgeBlock.isBlank())drops the<domain_knowledge_context></domain_knowledge_context>pair, andbuildGuidance()now returns""instead of a lone"\n".
The one item you acknowledged and deliberately kept (the 7th positional boolean on the public constructor) is a fair call for this PR — the telescoping chain is pre-existing and converting it here would widen the blast radius.
Two non-blocking notes below: the wiring paths that actually regressed in the first revision are still only covered indirectly, and the empty-guidance branch adds one blank line to the prompt. Neither is a reason to hold this.
LGTM — approving. Thanks for the fast, complete turnaround on the feedback.
Automated review by github-manager-bot
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Adds disableKnowledgeContext() on HarnessAgent.Builder, threads it through WorkspaceContextMiddleware, and — in the commit pushed since my previous review — adds the subagent-propagation tests that were the remaining gap. Re-reviewed at 51c831da; the delta over the commit I approved is test-only (136 added lines, one new test file), and it covers exactly the right surface: both factory branches in HarnessAgentBuilderSupport (general-purpose and declared) plus a default-off control. CLA signed, MERGEABLE, license/validate/module-sync green.
Approved. Two non-blocking nits are inline.
Findings
- [Info]
DisableKnowledgeContextSubagentPropagationTest.java:121—createChildreturnsObject, forcing a cast at each call site - [Info]
DisableKnowledgeContextSubagentPropagationTest.java:65— assert the rendered child prompt, not just the propagated flag, for an end-to-end guarantee
Verification of the fix itself
HarnessAgentBuilderSupport.java:341,398 (general-purpose) and :465,570 (declared) now capture and re-apply disableKnowledgeContext() alongside the sibling disable* flags, which is what my earlier review asked for. The backward-compatible 6-arg constructor delegation and the IO short-circuit in buildWorkspaceSection are unchanged from the version I approved.
Automated review by github-manager-bot
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed at f87ba33c. The only change since the commit I approved (2d2166f1) is test-only: DisableKnowledgeContextSubagentPropagationTest now seeds knowledge/KNOWLEDGE.md and asserts on the rendered child system prompt (absence of ## Domain Knowledge when disabled, presence when enabled) instead of only the propagated boolean. That is exactly the end-to-end gap from my previous round, and it is the stronger assertion. No production code moved. Verdict: approve at the new head.
Previous round's findings
DisableKnowledgeContextSubagentPropagationTest.java:65— assert the rendered child prompt, not just the propagated flag — resolved (renderedChildPrompt(child)viaWorkspaceContextMiddleware.onSystemPrompt, asserted in all three cases).DisableKnowledgeContextSubagentPropagationTest.java:121—createChildreturnsObject, forcing a cast at each call site — still open, non-blocking.
Verification
- The new assertions exercise the real branch, not a stub:
buildGuidance()appendsDOMAIN_KNOWLEDGE_GUIDANCE(whose first line is## Domain Knowledge) only when!disableKnowledgeContext, andseedKnowledgeFile()makes the enabled case produce a non-empty knowledge block, so the positive assertion can genuinely fail. @TempDir workspace+ per-test seeding keeps the new file writes isolated; no shared-state risk across the three cases.- Diff confirms scope:
gh api comparefor2d2166f1...f87ba33creturns a single test file, +26/-0. - CI on the new head is green (ubuntu, windows, validate, license, module-sync); CLA signed;
MERGEABLE.
Ready to merge
Previously approved, still approved at f87ba33c, CI green, no conflicts. Merging is a maintainer action.
Automated review by github-manager-bot
320a57d to
6b570d1
Compare
(cherry picked from commit c4fb227)
- Propagate disableKnowledgeContext to both subagent factories in
HarnessAgentBuilderSupport (general-purpose and declared)
- buildGuidance(): return empty string when all sections are suppressed
instead of a lone newline
- assembleSection(): skip empty guidance block
- buildLoadedContextSection(): omit <domain_knowledge_context> element
when the knowledge block is blank
- Add WorkspaceContextMiddlewareKnowledgePromptTest (5 test cases)
- Update docs/v2/{en,zh}/docs/harness/workspace.md switch tables
(cherry picked from commit e61b256)
…text Covers both branches of the disableKnowledgeContext flag checks in (cherry picked from commit 709eb73)
Extract shared parentBuilder()/buildSubagentEntry() helpers, assert entry (cherry picked from commit 9f7a030)
Addresses review [info]: previously the subagent propagation tests only asserted the flag reached the child's WorkspaceContextMiddleware. Add end-to-end assertions that the child's rendered system prompt actually drops the "## Domain Knowledge" section when disabled and keeps it when enabled (mirrors WorkspaceContextMiddlewareKnowledgePromptTest). Seeds a knowledge/KNOWLEDGE.md in the shared temp workspace so the rendered prompt exercises the real section. (cherry picked from commit d5724c4)
…erials refactor (cherry picked from commit 2678491)
…ements + escaped HTML) (cherry picked from commit 0b06a8c)
(cherry picked from commit 59d2cfa)
…disableKnowledgeContext notes (cherry picked from commit 276d944)
… keep material table unchanged (cherry picked from commit 6b570d1)
…feedback (cherry picked from commit 6de7d10)
6de7d10 to
0008824
Compare
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
Adding another +1 for this capability. We also need an independent opt-out for agents whose domain knowledge is supplied through application-defined tools or skills rather than the harness's local Why this is valuable and necessary
The important contract for us is that This PR addresses that focused need while keeping the existing default behavior. Its regression coverage, subagent propagation, and EN/ZH documentation are particularly useful for making the switch dependable. The capability is still absent from the latest upstream |
# Conflicts: # agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java
|
Thanks for the review and the P2 label, @jujn. Status update — this PR is now fully ready to merge:
@xseruer — your Nov 13 follow-up is valid: the opt-out removes all harness-generated knowledge guidance/materials (the Given that multiple consumers are waiting on this and it's ready at any time, would it be possible to bump it to P1 or merge when convenient, @jujn? No blocking work remains on our end. Thanks! |
…cope-ai#4176 flaky-test fix + agentscope-ai#4180 a2a-sdk bump)
…7e8e5, re-trigger CI past rocketmq flaky)
…6ff9e, pull in agentscope-ai#4435 deflake + harness fixes)
…rkspace.md (en+zh) after docs v2->dev restructure
Fixes #3278
Description
Add a
disableKnowledgeContext()Builder method toHarnessAgentthat precisely disables knowledge-related system prompt injection without affecting AGENTS.md, MEMORY.md, or memory tools.Currently the only way to disable knowledge injection is
disableWorkspaceContext(), which is a nuclear option — it disables everything including AGENTS.md, MEMORY.md, and session context. This PR adds a granular switch for agents that use a custom enterprise knowledge tool (e.g. Solr + Milvus + Rerank) instead of the framework's localknowledge/directory.Changes
HarnessAgent.java
disableKnowledgeContextboolean flag to Builder (defaultfalse)disableKnowledgeContext()Builder method with JavadocWorkspaceContextMiddlewarevia new 7-arg constructorWorkspaceContextMiddleware.java
WORKSPACE_FILES_NOTICE_NO_KNOWLEDGE_*constants (omitknowledge/KNOWLEDGE.mdmention)disableKnowledgeContextfieldfalse(backward compatible)readKnowledgeMd()entirely when disabledbuildGuidance(): skipDOMAIN_KNOWLEDGE_GUIDANCEtext when disabledworkspaceFilesNotice(): select no-knowledge notice variant when disabledbuildKnowledgeBlock(): return empty string immediately when disabledWhat is NOT affected when
disableKnowledgeContext()is calledTesting
WorkspaceContextMiddleware*Testclasses pass unchanged (6-arg constructor retained)WorkspaceContextMiddlewareKnowledgePromptTestmirroring the existing memory-prompt test, asserting## Domain Knowledgeguidance,KNOWLEDGE.mdbody,Knowledge files:catalog, and notice text are all absent when disabled whileAGENTS.md/MEMORY.md/<memory_context>remain presentBackward compatibility