Class WaitAsyncResultsTool

java.lang.Object
io.agentscope.harness.agent.tool.WaitAsyncResultsTool

public class WaitAsyncResultsTool extends Object
Tool that blocks until async results arrive, either for a specific task barrier or (legacy) until any message appears in the session inbox.

Prefer barrier mode (task_ids or wait_all=true): when the wait set reaches terminal state, this tool embeds each task's status and result in the tool return so the model can continue reasoning immediately without waiting for push-back delivery.

Without task_ids / wait_all, this keeps the legacy inbox-any behavior: the tool returns as soon as any inbox message is present — it is not a wait-all barrier.

Guardrails prevent unbounded blocking:

  • Timeout is clamped to 120s regardless of the LLM-supplied value.
  • After 2 consecutive timeouts with no results, the tool refuses further blocking waits and directs the LLM to use non-blocking alternatives.
  • Constructor Details

    • WaitAsyncResultsTool

      public WaitAsyncResultsTool(MessageBus messageBus)
    • WaitAsyncResultsTool

      public WaitAsyncResultsTool(MessageBus messageBus, TaskRepository taskRepository)
  • Method Details

    • setExternalWorkProbe

      public WaitAsyncResultsTool setExternalWorkProbe(BooleanSupplier probe)
      Registers a probe for outstanding work owned outside the subagent task repository (currently AgentTeams teammates). Without it a lead with no subagent tasks would be told to stop waiting while its teammates are still running.
    • waitForResults

      @Tool(name="wait_async_results", description="Wait for background async tool, subagent, or teammate results. Prefer barrier mode: task_ids waits until those specific tasks are all terminal and returns their results in this tool output; wait_all=true waits for the snapshot of currently running tasks (tasks created while waiting are not added) and also returns their results. Without task_ids and without wait_all, this is legacy inbox-any mode: returns when ANY inbox message arrives \u2014 not wait-all. For must-collect-all groups use task_ids or wait_all=true. Also covers AgentTeams teammate work via the external-work probe. Max timeout is 120 seconds. If you have already waited without results, use task_list or task_output(block=false) to check status instead of waiting again.", readOnly=true) public String waitForResults(@ToolParam(name="timeout_seconds",description="Maximum seconds to wait. Default 60, max 120. Values above 120 are clamped.") Integer timeoutSeconds, @ToolParam(name="task_ids",description="Optional comma-separated task IDs to wait for. When set, the tool returns only after all listed tasks are terminal (or timeout), and embeds each task\'s result in the response.",required=false) String taskIds, @ToolParam(name="wait_all",description="Optional barrier mode. When true and task_ids is empty, wait for the snapshot of currently non-terminal tasks in this session and embed their results. Tasks created later are not added to the wait set. Not the same as legacy no-arg inbox-any wait.",required=false) Boolean waitAll, io.agentscope.core.agent.RuntimeContext runtimeContext) throws InterruptedException
      Throws:
      InterruptedException
    • waitForResults

      public String waitForResults(Integer timeoutSeconds, io.agentscope.core.agent.RuntimeContext runtimeContext) throws InterruptedException
      Throws:
      InterruptedException