Skip to content

[Bug]: disableFilesystemTools() leaves injected prompt guidance referencing the disabled tools #3614

Open

Description

@Peng-io

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 with read_file / grep / glob
  • ## Memory Persistence — persist via memory_save, and do not use write_file / edit_file on MEMORY.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:

  1. skip or adjust the tool-related guidance when the corresponding tools are disabled, or
  2. 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.onSystemPrompt receives only the user's sysPrompt — 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's order() does not change this.
  • MiddlewareBase.onReasoning (and onModelCall) does receive the fully assembled system message inside ReasoningInput.messages(), and that list is a mutable ArrayList. 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 disableFilesystemTools in HarnessAgent.Builder.build(), so the switch is all-or-nothing.
  • The guidance text lives in WorkspaceContextMiddleware as 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions