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

[Feature]: Add framework-level guardrails for `wait_async_results` to prevent repeated long blocking waits

Open HuJiShuang opened this issue 4 months ago • 0 comments

Title

[Harness] Add framework-level guardrails for wait_async_results to prevent repeated long blocking waits

Environment

  • AgentScope Java version: 2.0.0-RC4
  • Module: Harness / Subagents / Background task coordination
  • Tools involved: agent_spawn, wait_async_results, task_list, task_output

Problem

In Harness subagent workflows, the main agent can call wait_async_results(timeout_seconds=600) repeatedly after spawning a background subagent. The current tool appears to trust the model-provided timeout_seconds value, so a single reasoning mistake can block the parent agent for a long time.

In one production run, wait_async_results dominated the whole request latency:

Category Time
wait_async_results fixed waits 3 * 600s = 1800s
Share of visible total duration 77.3%
Evidence 16:04:15-16:14:15, 16:14:34-16:24:34, 16:25:34-16:35:34 all waited full 600s

ODPS queries themselves were not the bottleneck:

Category Time
ODPS queries 12 calls / 118.4s total
Average 9.9s
Max 24.7s

So the main problem is orchestration-level blocking wait, not the actual data query runtime.

Current Behavior

wait_async_results can block for the full model-supplied timeout.

After a timeout, the tool response says the agent may continue or wait again, so the model may call wait_async_results repeatedly for the same pending work.

This can lead to long parent-agent stalls even though the subagent task is already running in the background and could be checked via task_list or task_output(block=false).

Expected Behavior

Harness should provide framework-level guardrails so applications do not need to override built-in tools.

Suggested behavior:

  1. Cap wait_async_results.timeout_seconds at the framework/tool layer.

    • Example default: maxTimeoutSeconds = 120
    • If the model passes 600, the tool should clamp it and log/report the cap.
  2. Limit repeated empty waits.

    • Example default: allow only one empty wait_async_results per session or per pending task.
    • After the wait budget is exhausted, return a non-blocking response telling the model to use task_list, task_output(block=false), existing artifacts/status files, or cancel/take over.
  3. Separate parent-agent blocking wait from long-running task duration.

    • A cap on wait_async_results should not imply a cap on the underlying ODPS / remote / background task.
    • Long-running tasks should continue in the background and expose status/query ids/results through task APIs.
  4. Optionally expose similar policy for agent_spawn / agent_send sync timeout.

    • Current prompt advertises max=600.
    • Applications may want a lower sync wait cap while still allowing timeout promotion to background task.

Proposed API

One possible API shape:

HarnessAgent agent = HarnessAgent.builder()
    .subagentPolicy(SubagentPolicy.builder()
        .waitAsyncResultsMaxTimeoutSeconds(120)
        .waitAsyncResultsMaxEmptyWaits(1)
        .agentSpawnMaxSyncTimeoutSeconds(120)
        .agentSendMaxSyncTimeoutSeconds(120)
        .build())
    .build();

HuJiShuang avatar Jul 09 '26 09:07 HuJiShuang