Repository navigation
Description
Problem
Currently, the only way to disable knowledge-related system prompt injection is disableWorkspaceContext(), which is a nuclear option — it disables everything: AGENTS.md, MEMORY.md, knowledge/KNOWLEDGE.md, knowledge file catalog, guidance text, and session context.
There is no independent switch to disable only the knowledge context while keeping AGENTS.md, MEMORY.md, and memory tools intact.
Use Case
We build an enterprise Q&A agent with a custom searchKnowledge tool (backed by Solr full-text search + Milvus vector search + Rerank, indexing 120K enterprise documents). The LLM is expected to call searchKnowledge when it needs domain knowledge.
However, the framework's WorkspaceContextMiddleware injects into every system prompt:
DOMAIN_KNOWLEDGE_GUIDANCEtext ("The knowledge/ directory is the source of truth...")knowledge/KNOWLEDGE.mdfull content- All file paths under
knowledge/directory - Workspace Files notice mentioning
knowledge/KNOWLEDGE.md
This causes the LLM to prefer list_files on the knowledge/ directory or memory_search over calling our searchKnowledge tool. For example, when asked about a contact person, the LLM tries to browse local files instead of querying the enterprise knowledge base.
We need a way to disable only the knowledge injection so the LLM relies on our custom tool, while keeping AGENTS.md, MEMORY.md, and memory tools working normally.
Proposed Solution
Add a disableKnowledgeContext() Builder method that precisely disables knowledge-related injection without affecting other workspace context:
HarnessAgent.builder()
.disableKnowledgeContext() // NEW: disable knowledge/ injection only
// AGENTS.md — still injected
// MEMORY.md — still injected
// memory tools (memory_search, memory_get, etc.) — still available
// session context (date, OS, workspace path) — still injectedWhen disableKnowledgeContext() is called:
- Skip
DOMAIN_KNOWLEDGE_GUIDANCEtext - Skip
knowledge/KNOWLEDGE.mdcontent injection (including file IO) - Skip knowledge file path catalog
- Use Workspace Files notice text without knowledge/ mention
Relationship to existing switches
| Method | What it disables |
|---|---|
disableWorkspaceContext() |
Everything (nuclear option) |
disableMemoryTools() |
memory_search / memory_get / memory_save tools |
disableMemoryHooks() |
memory flush + background maintenance + MEMORY.md injection |
disableKnowledgeContext() |
Only knowledge-related injection (guidance + KNOWLEDGE.md + file catalog + notice text) |
Affected Code
WorkspaceContextMiddleware.java:buildGuidance(),workspaceFilesNotice(),buildKnowledgeBlock(),buildWorkspaceSection()HarnessAgent.java: Builder method + flag + constructor pass-through
We have a working prototype and are happy to review a PR once implemented.
Activity
[-]Feature: Add independent switch to disable knowledge context injection[/-][+][Feature]: Add independent switch to disable knowledge context injection[/+]z43460018724 commentedon Sep 24, 2026
Here is a working prototype diff for reference. It touches 2 files, ~60 lines:
Key design points to avoid missing:
readKnowledgeMd()at all — skip the file read entirely, not just discard the result.DOMAIN_KNOWLEDGE_GUIDANCEsays "The knowledge/ directory is the source of truth" — if this text remains in the prompt, the LLM will still try to browse knowledge/ vialist_filesormemory_search. Must be skipped.knowledge/KNOWLEDGE.mdby name. Need two variants (with/without MEMORY.md) that omit the knowledge mention.buildKnowledgeBlock()lists all files underknowledge/. Return empty string immediately when disabled.disableKnowledgeContext=false.oss-maintainer commentedon Sep 24, 2026
Issue Evaluation
Category:
enhancement(area/harness) | Status: Evaluated — feasible, but blocked on an in-flight refactor | Severity: low-medium (ergonomics / prompt-budget control)Claim-by-claim check (verified against
main@fefc196f4, engine-assisted read ofagentscope-harness)disableWorkspaceContext()is the only switch today, and it is all-or-nothingHarnessAgent.java:1259(single boolean) → the wholeWorkspaceContextMiddlewareis skipped atHarnessAgent.java:2529-2541disable*flags atHarnessAgent.java:1232-1265(compaction, toolResultEviction, filesystemTools, shellTool, webTools, memoryTools, memoryHooks, transcript, sessionPersistence, workspaceContext, atPathExpansion, subagents, dynamicSkills, defaultWorkspaceSkills, dynamicSubagents, toolsConfig); none gates knowledge.disableMemoryTools()/disableMemoryHooks()leave knowledge injection intact —WorkspaceContextMiddlewareMemoryPromptTest:158-167asserts## Domain Knowledgeand<domain_knowledge_context>still appear when both are setDOMAIN_KNOWLEDGE_GUIDANCEappended unconditionally inbuildGuidance()—WorkspaceContextMiddleware.java:260; (b)readKnowledgeMd(rc)called unconditionally —:216; (c)listKnowledgeFiles(rc)catalog —:574; (d) bothWORKSPACE_FILES_NOTICE_*templates nameknowledge/KNOWLEDGE.md—:113,:120, selected at:525-529WorkspaceContextMiddleware+HarnessAgentHarnessAgent.java:2531There is also no alternative escape hatch today (no system property, env var, spec option or middleware flag). The only non-API workaround is to not ship a
knowledge/directory, which is not viable for the reporter's setup. So the gap is real and the motivation (a custom retrieval tool competing with framework-injected "knowledge/ is the source of truth" guidance) is legitimate.Why no automated PR this tick — the proposed patch would collide with #3275.
PR #3275 (OPEN,
+8148/-562, by a project collaborator, opened ~1h50m before this issue; currentlyREVIEW_REQUIRED) rewrites the context pipeline these very methods live in:buildWorkspaceSection()stops emitting<domain_knowledge_context>viabuildXmlContext(...)and instead emitsnew ContextItem("knowledge", "workspace:knowledge", knowledgeBlock)into a newHARNESS_CONTEXTmodel, withContextSelectionPolicy.defaults()rankingknowledgesecond in the budget-omission order (aftermemory).DOMAIN_KNOWLEDGE_GUIDANCEis reworded, and bothWORKSPACE_FILES_NOTICE_WITH_MEMORY/..._WITHOUT_MEMORYconstants (the exact strings the prototype patch edits) are deleted.HarnessAgent.java,HarnessAgentBuilderSupport.javaand all threeWorkspaceContextMiddleware*Testclasses are modified in the same PR.So the diff attached to this issue cannot be applied as-is after #3275 lands, and if written now against
mainit conflicts on every touched hunk.Recommended direction (maintainer call, since #3275 changes what "a switch" means):
workspace:knowledgesource non-required / excluded, or aContextSelectionPolicythat omits it unconditionally) rather than a new boolean threaded through the middleware constructor. This keeps one configuration model for the new pipeline instead of reintroducing the old flag pattern.HarnessAgent.Builder, but add aWorkspaceContextMiddlewareoverload instead of changing the 6-arg constructor —WorkspaceContextMiddlewareMemoryPromptTest:119,:139,:154call that constructor directly, so a signature change breaks the build.readKnowledgeMd/listKnowledgeFilescalls, not just discard their output) is worth keeping from the prototype — it is the part that avoids reading a 120K-document tree every turn.docs/v2/{en,zh}/docs/harness/*.mdhas a switch table listingdisableWorkspaceContext(); a new switch needs a row in both languages.Testability: yes, no external services needed — a
WorkspaceContextMiddlewareKnowledgePromptTestmirroring the existing memory-prompt test, asserting## Domain Knowledgeguidance, theKNOWLEDGE.mdbody, theKnowledge files:catalog and the notice text are all absent when disabled whileAGENTS.md/MEMORY.md/<memory_context>remain present.@z43460018724 the requirement itself checks out — this is a genuine gap, not a misreading of the existing switches. The blocker is purely sequencing against #3275. If a harness owner confirms which of (1) or (2) they want, reply
/approveor/revise <direction>and a patch will be generated against the agreed shape.Automated evaluation by github-manager-bot
z43460018724 commentedon Sep 24, 2026
Update: PR #3275 (the in-flight context pipeline refactor that was blocking this issue) has been closed without merging on Sep 24 due to merge conflicts with main. The blocker no longer applies.
We have submitted PR #3287 implementing the
disableKnowledgeContext()approach (direction 2 — overload instead of changing the 6-arg constructor, per the evaluation's note aboutWorkspaceContextMiddlewareMemoryPromptTest).PR #3287 is ready for review.
oss-maintainer commentedon Sep 27, 2026
Proposal window closed — no competing PR will be filed from this proposal window
The 72 h feedback window opened by the evaluation above (2026-09-24T10:14:40Z) reached its bound with
no approve / revise / reject directive from a harness owner.
The thread answered the question in another way: @z43460018724 reported on 2026-09-24T21:59:10Z that
the sequencing blocker (PR #3275) had been closed without merging, and opened PR #3287 —
Fixes #3278, direction 2 from the evaluation (aWorkspaceContextMiddlewareoverload rather than asignature change on the 6-arg constructor). As of this read #3287 is OPEN, not a draft, review
decision APPROVED, 7/7 checks passing,
+398/-9across 7 files, headf87ba33cab.So the implementation path for this request is owned by a community PR that already exists and is
awaiting maintainer merge. Filing a second PR against the same issue is exactly the collision this
window policy exists to prevent, so the proposal is stood down and no automated PR will be generated
from it.
Nothing here disputes the evaluation: the gap is real and the recommended shape is the one #3287
implements. Merge, close, or request changes on #3287 — that is the productive thread now. If #3287 is
closed unmerged and this remains wanted, reopen the question on #3278 and it will be re-evaluated
against whatever
mainlooks like at that point.Automated feedback-window maintenance by github-manager-bot