Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,16 @@ private Mono<ToolResultBlock> applyTimeout(
Duration timeout = config.getTimeout();
logger.debug("Applied timeout: {} for tool: {}", timeout, toolCall.getName());

return execution.timeout(
timeout,
Mono.error(new RuntimeException("Tool execution timeout after " + timeout)));
return execution.timeout(timeout, Mono.error(toolExecutionTimeoutError(timeout, toolCall)));
}

private static RuntimeException toolExecutionTimeoutError(
Duration timeout, ToolUseBlock toolCall) {
String toolName = toolCall.getName() != null ? toolCall.getName() : "unknown";
String toolId = toolCall.getId() != null ? toolCall.getId() : "unknown";
return new RuntimeException(
String.format(
"Tool '%s' (id=%s) execution timeout after %s", toolName, toolId, timeout));
}

private Mono<ToolResultBlock> applyRetry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@
import io.agentscope.harness.agent.tool.MemorySearchTool;
import io.agentscope.harness.agent.tool.SessionSearchTool;
import io.agentscope.harness.agent.tool.ShellExecuteTool;
import io.agentscope.harness.agent.tool.TaskTool;
import io.agentscope.harness.agent.workspace.WorkspaceManager;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -146,6 +148,9 @@ public class HarnessAgent implements Agent, StateModule {

private static final Logger log = LoggerFactory.getLogger(HarnessAgent.class);

private static final Duration SUBAGENT_TOOL_EXECUTION_TIMEOUT =
TaskTool.MAX_BLOCK_WAIT.plusMinutes(1);

private final ReActAgent delegate;
private final WorkspaceManager workspaceManager;
private final CompactionHook compactionHook;
Expand Down Expand Up @@ -1380,7 +1385,11 @@ public HarnessAgent build() {
allHooks.add(new SessionPersistenceHook());
}

if (!leafSubagent && !disableSubagents && model != null) {
boolean subagentsEnabled = !leafSubagent && !disableSubagents && model != null;
ExecutionConfig effectiveToolExecutionConfig = toolExecutionConfig;
if (subagentsEnabled) {
effectiveToolExecutionConfig =
withSubagentToolExecutionTimeout(toolExecutionConfig);
SubagentsHook subagentsHook =
buildSubagentsHook(
wsManager, resolvedWorkspace, capturedSandboxFs, userIdRef);
Expand Down Expand Up @@ -1425,8 +1434,8 @@ public HarnessAgent build() {
if (modelExecutionConfig != null) {
reactBuilder.modelExecutionConfig(modelExecutionConfig);
}
if (toolExecutionConfig != null) {
reactBuilder.toolExecutionConfig(toolExecutionConfig);
if (effectiveToolExecutionConfig != null) {
reactBuilder.toolExecutionConfig(effectiveToolExecutionConfig);
}
if (generateOptions != null) {
reactBuilder.generateOptions(generateOptions);
Expand Down Expand Up @@ -1470,7 +1479,7 @@ public HarnessAgent build() {
name,
resolvedWorkspace,
filesystem.getClass().getSimpleName(),
!leafSubagent && !disableSubagents && model != null);
subagentsEnabled);

return new HarnessAgent(
delegate,
Expand Down Expand Up @@ -1596,6 +1605,20 @@ private static NamespaceFactory buildDynamicNamespaceFactory(
};
}

private static ExecutionConfig withSubagentToolExecutionTimeout(
ExecutionConfig configured) {
ExecutionConfig timeoutOverride =
ExecutionConfig.builder().timeout(SUBAGENT_TOOL_EXECUTION_TIMEOUT).build();
if (configured == null) {
return timeoutOverride;
}
Duration timeout = configured.getTimeout();
if (timeout == null || timeout.compareTo(TaskTool.MAX_BLOCK_WAIT) <= 0) {
return ExecutionConfig.mergeConfigs(timeoutOverride, configured);
}
return configured;
}

// -----------------------------------------------------------------
// Subagents
// -----------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.agentscope.harness.agent.subagent.task.BackgroundTask;
import io.agentscope.harness.agent.subagent.task.TaskRepository;
import io.agentscope.harness.agent.subagent.task.TaskStatus;
import java.time.Duration;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
Expand All @@ -41,6 +42,9 @@
*/
public class TaskTool {

public static final long MAX_BLOCK_WAIT_MILLIS = 600_000L;
public static final Duration MAX_BLOCK_WAIT = Duration.ofMillis(MAX_BLOCK_WAIT_MILLIS);

private static final DateTimeFormatter ISO_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(ZoneOffset.UTC);

Expand Down Expand Up @@ -96,7 +100,7 @@ public String taskOutput(
bgTask.updateLastCheckedAt();

boolean shouldBlock = block == null || block;
long timeoutMs = timeout != null ? Math.min(timeout, 600_000) : 30_000;
long timeoutMs = timeout != null ? Math.min(timeout, MAX_BLOCK_WAIT_MILLIS) : 30_000;

if (shouldBlock && !bgTask.isCompleted()) {
// If the task has no local future (cross-node or post-restart), degrade gracefully
Expand Down
Loading