Repository navigation
Description
Describe the bug
HarnessAgent.Builder.disableFilesystemTools() removes all six filesystem tools registered by FilesystemTool (list_files, read_file, write_file, edit_file, grep_files, glob_files), but the prompt sections injected by WorkspaceContextMiddleware are not adjusted — they still instruct the model to use exactly those tools.
Concretely, the working_principles (harness:workspace-guidance) block still contains guidance such as:
## Domain Knowledge— read knowledge files withread_file/grep/glob## Memory Persistence— persist viamemory_save, and do not usewrite_file/edit_fileonMEMORY.md
The model therefore receives instructions pointing at tools that are not registered for this agent.
To Reproduce
HarnessAgent agent = HarnessAgent.builder()
.name("my-agent")
.sysPrompt("You are a helpful assistant.")
.model(model)
.workspace(Paths.get(".agentscope/workspace"))
.disableFilesystemTools()
.build();Then run a call and inspect the compiled system prompt (or watch the model's behavior) — the workspace guidance still mentions the removed tools.
Expected behavior
Either:
- skip or adjust the tool-related guidance when the corresponding tools are disabled, or
- expose a supported way to override/replace the injected prompt sections.
Actual behavior
The prompt and the registered tool set are inconsistent, which can lead the model to reference tools that do not exist for this agent.
Measured behavior on 2.0.4 (follow-up investigation)
To check whether an application can rewrite the injected sections without patching the framework, I probed the middleware hooks on 2.0.4:
MiddlewareBase.onSystemPromptreceives only the user'ssysPrompt— 12 characters in my setup, while the final system message reaching the model is 4793 characters. The framework-injected sections (working_principles, AGENTS.md, environment) never pass through this hook, so its return value cannot rewrite them. Raising the middleware'sorder()does not change this.MiddlewareBase.onReasoning(andonModelCall) does receive the fully assembled system message insideReasoningInput.messages(), and that list is a mutableArrayList. Replacing the system message there does take effect — after appending an instruction to the system message, the model followed it verbatim.
So a workaround exists today, but it rests on undocumented behavior: nothing in the API states that the messages() list may be mutated, and its effect depends on the pipeline not rebuilding the system message afterwards. On main, the v2 context pipeline (HarnessContextBuilder) appears to drop and re-render synthetic system fragments (workspace_materials / harness_instructions), which would silently discard exactly this kind of edit — so the workaround would not be portable across versions.
This makes the need for option 2 above stronger rather than weaker: the hook that cannot rewrite the injected prompt is the documented one, while the one that works is an undocumented implementation detail. Happy to share the minimal probe middleware if useful.
Error messages
N/A — this is a behavioral inconsistency, not a runtime error.
Environment
- AgentScope-Java Version: 2.0.4
- Java Version: 21
- OS: Windows
Additional context
- The six tools come from a single registration guarded by
disableFilesystemToolsinHarnessAgent.Builder.build(), so the switch is all-or-nothing. - The guidance text lives in
WorkspaceContextMiddlewareas inline constants. - The same mismatch potentially applies to the other
disable*switches (disableShellTool,disableWebTools,disableMemoryTools), which also remove tools whose usage is described in the injected prompt.
Activity