Skip to content

[Feature]: Configurable Harness workspace-memory recall guidance to avoid unnecessary tool round trips #4160

Open

Description

@suntianxian

Is your feature request related to a problem? Please describe.

With AgentScope Java 2.0.4, we observed a Harness agent answering a self-contained, first-turn question by first issuing memory_search, receiving no matches, and then requesting the model again to answer. This repeats the system/context material and tool schemas in another model request, increasing cumulative input tokens even though the search contributes no information.

We understand that tool execution followed by another model request is normal ReAct behavior. This report is about the retrieval policy and its configuration, not a claim that all tool use should fit in one model request, or that the framework duplicates the prompt within a request.

The built-in WorkspaceContextMiddleware currently injects:

## Memory Recall
Before answering questions about prior work, decisions, dates, people, or preferences:
run memory_search on MEMORY.md + memory/*.md, then memory_get for needed lines.
Include Source: <path#line> citations when helpful.

The broad categories, especially dates/people/preferences, can encourage a lookup for a new planning question whose necessary constraints are already supplied. We would like to retain workspace memory and its tools while narrowing or replacing this recall instruction through a supported API.

Environment and application-level reproduction

  • AgentScope Java / Harness: 2.0.4; JDK 21.
  • Answering model: qwen3.8-omni-flash.
  • Fresh application sessions, same agent/model and the same Chinese user question below.
  • File tools, Shell, Web, and our application tool-search middleware were disabled. For the first two measurements, context compaction and tool-result eviction were also disabled.
  • Two visible tool schemas with workspace memory disabled; eight with memory enabled. The additional six are memory_search, memory_get, memory_save, session_search, session_list, and session_history.
  • The application also supplies skill-selection instructions. It asks the model to use a matching skill when one exists and to copy actual IDs from the catalog. This is relevant to the separate invalid-skill observation below.

User question:

最近大家都挺忙的,我想下周五下午在公司搞个小聚会,吃点东西聊聊天。大概八个人,预算三百块,你觉得怎么安排比较舒服?

English meaning: "Everyone has been busy lately. I would like to arrange a small gathering at the office next Friday afternoon, with food and casual conversation. About eight people, budget RMB 300. How would you organize it comfortably?"

Steps to reproduce the application observation:

  1. Enable Harness workspace-memory tools/hooks in a fresh session.
  2. Ask the question above, without asking the agent to recall any prior conversation.
  3. Inspect each model request and its tool calls, rather than only the final answer or aggregate usage.
  4. Compare against a new session with both .disableMemoryTools() and .disableMemoryHooks().

Measured calls

These are real application observations cross-checked between provider-usage records and Langfuse model spans, not a standalone SDK-only reproduction. Model decisions and response lengths vary between runs.

Configuration / call Model action Input tokens Output tokens Total
Memory disabled Answer directly 2,282 1,705 3,987
Memory enabled, call 1 Request memory_search 3,197 35 3,232
Memory enabled, call 2 Answer after no matches 3,267 654 3,921
Memory-enabled run, cumulative Two model calls, one empty search 6,464 689 7,153

The first memory-enabled request is 915 input tokens larger. We have not separately attributed those 915 tokens to individual prompt sections versus schemas. Input counts include cached input; the two-call run had 1,792 cache-read tokens already included in its input total. Output lengths differ, so the total-token difference is not a controlled estimate of memory-policy savings.

In another application run, the sequence was:

Call Model action / backend result Input Output Total
1 memory_search; no matches 3,197 44 3,241
2 load_skill_through_path; nonexistent skill ID 3,276 73 3,349
3 Final answer 3,411 523 3,934
Cumulative Three model calls 9,884 640 10,524

This additional run had compaction enabled, but no compaction was observed; its configured threshold was 375 messages / approximately 168,776 estimated conversation tokens. Tool-result eviction was configured on but inactive because file tools were disabled. The invalid skill ID and application skill-priority prompt are confounders: we are not attributing that failure to a confirmed SDK defect. It illustrates why controlling unnecessary initial retrieval and tool guidance matters for cumulative cost. This was not a repeated invocation of the same tool/arguments or a transport retry.

Background memory extraction/consolidation costs are not included in the comparison above; it only covers the verified answering-model calls. No provider-wide cost reduction is claimed.

Describe the solution you would like

Please consider a supported, opt-in way to configure Harness workspace-memory recall policy independently of tool availability and background maintenance. For example:

  1. Override or disable only the Memory Recall guidance, while retaining memory tools, MEMORY.md injection, and configured flush/consolidation behavior.
  2. Allow a narrower policy: use injected memory when sufficient; invoke search when the task actually depends on information from past interactions, rather than merely mentioning a date or preference.
  3. If appropriate, offer an application-controlled pre-retrieval/injection mode for workspace memory, so the answering model need not first generate a search tool call. The retrieval backend may have its own model/embedding costs; this is about avoiding an answering-model round trip, not making retrieval free.

Preserving current behavior by default would avoid changing existing agents. We are asking for a supported configuration/extension point, not automatic rewriting of the user's system prompt or a hard guarantee of one model call per turn.

Describe alternatives you have considered

  • .disableMemoryTools() removes the recall guidance and six tools, but also removes on-demand access to memory and session history.
  • .disableMemoryHooks() controls automatic extraction/consolidation; it does not remove the active-tool recall instruction.
  • .disableWorkspaceContext() removes much more than this recall policy, including other useful workspace context.
  • MemoryConfig.flushPrompt(...) customizes extraction, not the answering-model recall guidance.
  • Context compaction handles growing history. It does not prevent an unnecessary search in a short first-turn request. The development branch's ContextPolicy can control optional input material, but does not by itself decide whether a search is useful.
  • Repetition protection is useful for loops, but the three-call example above uses different tools and is not an identical-call loop.

Existing APIs and Python comparison

Java core already has ReActAgent.Builder.longTermMemoryMode(...) with STATIC_CONTROL, AGENT_CONTROL, and BOTH for the LongTermMemory integration. This request is specifically about the separate Harness MEMORY.md / workspace-memory tools and guidance, which are not controlled by that mode. Guidance on reusing an existing supported API for this path would also resolve the request.

In the Python v2.0.11 source:

  • Mem0MemoryMiddleware supports static_control, agent_control, and both, plus configurable tool_instructions. Static control pre-fetches memories and exposes no memory tools; agent control still has normal model/tool/model round trips. Its default is both, so this is not a claim that Python always avoids extra calls.
  • AgenticMemoryMiddleware.Parameters exposes memory_instructions, retrieval_instructions, retrieval_async, and retrieval limits for filesystem memory.

These are source-level comparisons, not a live Python benchmark. The Python backends and memory semantics are different; we are asking whether comparable configurability belongs in the Java Harness workspace-memory path.

Related work:

Activity

  1. CryoThrust commented on Nov 17, 2026

    @CryoThrust
    Contributor

    I'd like to take a narrow first implementation of this request. I checked current main at 5525ac1aa and searched existing PRs; I found no implementation of configurable workspace-memory recall guidance. #3287 addresses knowledge context and #2565 gates guidance on disabled capabilities, which are different scopes.

    The current WorkspaceContextMiddleware contributes the fixed recall text to the working_principles context item whenever memory tools are enabled. MemoryConfig is already carried through the Harness builder, but currently configures extraction/consolidation rather than that answering-model instruction.

    I propose an optional MemoryConfig.Builder.recallInstructions(String) setting:

    • null keeps the existing recall guidance; defaults remain unchanged.
    • Blank text omits only the Memory Recall section.
    • Nonblank text replaces its body under the existing heading, without appending the old policy or formatting/interpolating application text.
    • Disabled memory tools still suppress recall guidance, including an override. This setting does not enable tools, inject extra memory, change namespace/permissions, disable memory persistence/maintenance, or guarantee a number of model calls.

    I will cover the default/custom/blank/null behavior at the actual rendered-request boundary, tool/hook flag combinations, builder reuse and isolation, and matching EN/ZH documentation. The original application token comparison is useful motivation, but I would not claim token savings from deterministic prompt tests or add automatic pre-retrieval in this first change.

    Implementation: #4219 adds this focused setting, the rendered-request/flag-combination and subagent-inheritance coverage, and matching EN/ZH docs. The full 114-module mvn -B -T1C clean verify passes on JDK 17 (13,157 tests reported, 0 failures/errors, 221 skips); documentation tests, strict build and broken-link checks also pass. On GitHub, Linux is still running; Windows failed in a Durable Worker lease test before dependent Harness modules ran. Details and the maintainer rerun request are in #4219 (comment) . CI is not yet green.

    Is MemoryConfig the right public home for this policy, or would you prefer it on the workspace-context builder? API-placement feedback is welcome on the PR; automatic pre-retrieval remains outside this change.

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