Repository navigation
feat(harness): let operators configure subagent timeout, overriding the LLM - #2749
haosong384 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds operator-controlled subagent timeout configuration so application code can bound the synchronous wait for subagent runs, overriding the LLM-provided timeout_seconds (and doing so without requiring force-sync mode).
Changes:
- Introduces
SubagentDeclaration.timeoutSecondsto configure a per-subagent synchronous wait timeout. - Adds
AgentSpawnTool.CTX_TIMEOUT_SECONDSand updates timeout resolution to apply per-call context and per-subagent declaration precedence over the LLM value. - Adds a focused test suite covering the new precedence and edge cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/AgentSpawnTool.java | Adds a new per-call context override key and updates effective timeout resolution to incorporate operator-configured precedence. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/subagent/SubagentDeclaration.java | Adds a new per-subagent timeout configuration field + builder setter/getter. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/tool/AgentSpawnToolDeclarationTimeoutTest.java | Adds unit tests validating precedence (context → declaration → LLM) and force-sync interaction. |
Suppressed comments (1)
agentscope-harness/src/main/java/io/agentscope/harness/agent/subagent/SubagentDeclaration.java:600
- This builder Javadoc says a non-null timeoutSeconds "forces synchronous execution"; in practice it forces a synchronous wait window (the run may continue in the background if the wait times out and force-sync is not enabled). Rewording avoids implying the subagent is stopped/interrupted at the timeout.
* <p>Use this when the subagent runs deep, long-running work whose duration the model
* cannot estimate reliably. A non-null value forces synchronous execution for up to this
* many seconds, even if the model requests background execution. {@code null} (default)
* defers to the {@code RuntimeContext} override and then the LLM's argument.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * <p>When set (non-null), this value takes precedence over the {@code timeout_seconds} argument | ||
| * the LLM supplies on {@code agent_spawn} / {@code agent_send}, giving the application operator | ||
| * control over how long a deep, long-running subagent is allowed to run before it is | ||
| * interrupted. This is useful when the model cannot reliably estimate the wait and keeps | ||
| * timing out. | ||
| * | ||
| * <p>Semantics when set: | ||
| * | ||
| * <ul> | ||
| * <li>The subagent runs synchronously for up to this many seconds, overriding an LLM request | ||
| * for background execution ({@code timeout_seconds=0}). | ||
| * <li>Values are clamped to the tool's maximum; {@code <= 0} is treated as unset. |
…he LLM Subagent timeouts could only be set by the model through the agent_spawn / agent_send timeout_seconds argument. For deep, long-running work the model cannot estimate the duration reliably, so calls kept timing out even after the model retried with a larger value. The only existing override, CTX_FORCE_SYNC_TIMEOUT_SECONDS, applies solely when CTX_FORCE_SYNC is enabled, which also strips the model of the ability to choose background execution. This adds an operator-controlled timeout that does not depend on force-sync: - SubagentDeclaration: new Integer timeoutSeconds (builder + getter), so a timeout can be configured per subagent type alongside steps/model/etc. - AgentSpawnTool: new CTX_TIMEOUT_SECONDS RuntimeContext key for a per-call override, plus resolveOperatorTimeoutSeconds() and a 3-arg resolveEffectiveTimeoutMs(Integer, RuntimeContext, Optional<SubagentDeclaration>). Resolution precedence: - force-sync: CTX_FORCE_SYNC_TIMEOUT_SECONDS > CTX_TIMEOUT_SECONDS > declaration > LLM timeout_seconds - otherwise: CTX_TIMEOUT_SECONDS > declaration > LLM timeout_seconds An operator timeout expresses explicit intent to wait synchronously, so a positive value overrides an LLM request for background execution (timeout_seconds=0). Non-positive operator values are treated as unset and fall through to the next source; all sources are clamped to MAX_TIMEOUT_SECONDS. All three call sites (agentSpawn, agentSend, execSpawnTask) now pass the declaration, so local and remote subagents share the same resolution. The 2-arg resolveEffectiveTimeoutMs overload is preserved and delegates with an empty declaration, keeping existing behaviour unchanged. Closes agentscope-ai#2103
7fcc874 to
9682918
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds operator-configurable subagent timeouts via a new CTX_TIMEOUT_SECONDS runtime context key and a timeoutSeconds field on SubagentDeclaration. The implementation is well-structured with clear precedence rules and backwards compatibility. The resolution logic is properly tested with comprehensive unit tests.
|
This PR currently conflicts with git fetch upstream
git checkout feat/subagent-declaration-timeout
git rebase upstream/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Once the conflicts are resolved, comment Automated notification by github-manager-bot |
#3879) ## AgentScope-Java Version 2.1.0-SNAPSHOT; based on upstream `main` at `e190a8d1b`. ## Description A synchronous `agent_spawn` or `agent_send` can be cancelled by the ordinary-tool timeout before its own wait finishes. Raising the application override alone also leaves it silently capped at 600 seconds. Fixes #3878. ### Summary ```diff - Ordinary-tool timeout wraps the entire subagent invocation + Delegation uses AgentSpawnTool's existing wait timer + Positive application force-sync overrides can exceed 600 seconds ``` Add an opt-in `timeoutManaged` tool flag, defaulting to false, and enable it on `agent_spawn` / `agent_send`. Ordinary tools, including tools called inside the child, retain their configured timeout. The LLM-facing 600-second cap and parent-cancellation propagation are preserved. Update the existing English and Chinese subagent guides. Related: #3166 and #1451. This PR focuses on spawn/send and does not change `task_output` or add a separate application-ceiling policy. It overlaps #2749 in `AgentSpawnTool` and the subagent guides; it does not depend on that PR. ### Evidence - **Before:** `Tool execution failed: Tool execution timeout after PT10M` interrupts the whole delegation; an application override of 1800 is also clamped to 600. - **After:** regression coverage uses a 50 ms ordinary-tool timeout and a 200 ms child invocation. Both spawn and send finish successfully through direct and batch Toolkit calls. Ordinary-tool timeout, parent cancellation, and the child's own force-sync timeout remain covered. Validation completed on Windows with Java 21: ```text mvn -B -T1C clean verify PASS mvn -B -T1C -pl agentscope-harness -am \ -Dtest=AgentSpawnTool*Test,ToolExecutorTest,ReflectiveFunctionToolTest test 66 tests passed npm test 13 tests passed npm run validate PASS ``` `npm run broken-links` reports 2,222 broken links across 328 files. This patch changes no links or anchors; the repository's documentation source check and strict build validation pass. ### Merge Danger **Door:** Two-way; revert the commit to restore the previous timeout behavior. **Blast Radius:** Tools. The new flag defaults to false; only the two delegation tools opt in. Applications own the positive force-sync wait budget. ## Checklist - [x] Code formatted with `mvn spotless:apply` - [x] All tests pass in the full `clean verify` - [x] Javadoc comments updated - [x] Related English and Chinese documentation updated - [x] Code ready for review
AgentScope-Java Version
2.1.0-SNAPSHOT, synchronized with
mainat48f7257a.Description
Long-running subagent work can exceed the wait chosen by the model. Applications can now configure that wait on
SubagentDeclaration.timeoutSeconds(...)or, for an individual call,AgentSpawnTool.CTX_TIMEOUT_SECONDSinRuntimeContext. For example, a declaration timeout of 300 seconds overrides an LLM request for immediate background execution (timeout_seconds=0), so the parent waits for a result for up to 300 seconds.The configuration bounds the parent's synchronous wait. In ordinary mode, an unfinished local execution is promoted to a background task and continues running; remote execution remains on its task server and returns its task ID. Force-sync keeps the existing cancellation/no-promotion behavior when the wait expires.
Resolution precedence
CTX_TIMEOUT_SECONDS→ positive declaration timeout → LLMtimeout_secondsCTX_FORCE_SYNC_TIMEOUT_SECONDS→ positiveCTX_TIMEOUT_SECONDS→ positive declaration timeout → LLMtimeout_secondsGeneral context/declaration values of zero or less are ignored. Positive values are capped at 600 seconds. The existing force-sync override retains its behavior: non-positive values use the 30-second default, and values above 600 are capped. Without an application override, the existing LLM sync/background behavior is preserved; force-sync still coerces an LLM value of zero to the default wait.
All three dispatch paths use the same resolution: fresh
agent_spawn, persisted-instance reuse, andagent_send. The two-argument resolver remains available and delegates with an empty declaration.Conflict and review fixes
main, resolving declaration conflicts while retainingenablePendingToolRecoveryand current call-scoped manager/permission handling.Validation
e0ead076: all six CI checks passed (Linux, Windows, license, module sync, documentation validation and patch coverage). CLA status passed too.clean verifyin Linux CI and Windows CI: 10,495 tests per platform, 0 failures, 0 errors. Linux reports 187 skips; Windows reports 218 skips.mvn -B -T1 clean verifyran 2,590 Core tests (0 failures, 2 errors, 8 skips) and stopped on two untouchedDangerousPathBypassTestcases because this Windows host lacks symbolic-link creation privileges. No test assertions or unrelated Core code were changed.npm run validatepassed (430 pages / 584 redirects and strict build validation).npm run broken-linksreports the existing 2,206 broken links across 326 files; this change adds no links or anchors, and the repository's navigation/local-link source check passes.Run the new timeout scenarios or the complete Java check from the repository root:
mvn -B -T1 -pl agentscope-harness -am \ -Dtest=AgentSpawnToolDeclarationTimeoutTest \ -Dsurefire.failIfNoSpecifiedTests=false test mvn -B -T1 clean verifyChecklist
mvn spotless:apply; reactor Spotless checks passedCloses #2103