agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:HarnessAgent does not forward per-session interrupt methods from ReActAgent

Open cluskiop01 opened this issue 5 months ago • 1 comments

Describe the bug

ReActAgent provides per-session interrupt methods that are essential for the stateless (singleton) agent pattern introduced in 2.0:

  • interrupt(RuntimeContext ctx)
  • interrupt(String userId, String sessionId)
  • interrupt(String userId, String sessionId, Msg msg)

However, HarnessAgent only overrides the deprecated no-arg interrupt() and interrupt(Msg), which fall back to defaultSessionId. In a multi-session singleton deployment, calling interrupt() on a shared HarnessAgent cannot target a specific session — it always hits the default session, leaving other concurrent sessions unaffected when they should be interrupted.

To Reproduce

  1. Build a singleton HarnessAgent (no defaultSessionId set):
HarnessAgent agent = HarnessAgent.builder()
    .name("my-agent")
    .model(model)
    .stateStore(new MysqlAgentStateStore(dataSource))
    .build();
  1. Start concurrent calls with different RuntimeContext:
agent.streamEvents(msgs, RuntimeContext.builder()
    .userId("user-1").sessionId("session-A").build());
agent.streamEvents(msgs, RuntimeContext.builder()
    .userId("user-2").sessionId("session-B").build());
  1. Try to interrupt only session-A:
agent.interrupt("user-1", "session-A");  // compile error: method not found
  1. Workaround via getDelegate():
agent.getDelegate().interrupt("user-1", "session-A");  // works but leaks internals

Expected behavior

HarnessAgent should forward the per-session interrupt methods to its ReActAgent delegate, consistent with how it already forwards interrupt() and interrupt(Msg):

public void interrupt(RuntimeContext ctx) {
    delegate.interrupt(ctx);
}

public void interrupt(String userId, String sessionId) {
    delegate.interrupt(userId, sessionId);
}

public void interrupt(String userId, String sessionId, Msg msg) {
    delegate.interrupt(userId, sessionId, msg);
}

Environment

  • AgentScope-Java Version: 2.0.0-RC2
  • Java Version: 21
  • OS: Windows 11

Additional context

The HarnessAgent.getDelegate() method exists as a workaround, but requiring users to reach through the wrapper defeats the purpose of the facade. Since 2.0 explicitly promotes the stateless singleton pattern, per-session interrupt is a core capability that HarnessAgent should expose.

cluskiop01 avatar Jun 10 '26 01:06 cluskiop01

We've encountered the same issue. Should we abstract these methods into an interface?

yulindong avatar Jun 29 '26 12:06 yulindong