Repository navigation
fix(tools): report tool success/failure via ToolResultBlock state - #2751
Conversation
|
我更倾向于重构一下:让 FilesystemTool 等工具成功/失败时返回结构化 ToolResultBlock.withState(); |
Built-in @tool methods signalled failure by returning a string prefixed with "Error: ", leaving ReActAgent#determineToolResultState to infer the state from the result text. Per review feedback on agentscope-ai#2751, that inference is replaced by having the tools state their outcome structurally. Text-based inference cannot be made correct: several tools return external content on success — read_file hands back raw file content, web_fetch an HTTP body, shell execute the command output — so content that merely looks like an error message is indistinguishable from a real failure. Broadening the prefix match would have turned a missed failure into a false one. - ToolResultBlock.success(String): new, symmetric with the existing error(String). Needed because an unset state is coerced to RUNNING by the constructor, which determineToolResultState treats as "unknown" and resolves via the text fallback; only an explicit SUCCESS opts out. - 17 @tool methods across FilesystemTool, WebTools, SessionSearchTool, TaskTool, MemoryGetTool, MemorySaveTool and ShellExecuteTool now return ToolResultBlock: failures via error(msg), successes via success(text). - ReActAgent is untouched (byte-identical to main). The [ERROR] text fallback is left in place for third-party tools that build blocks without a state; structured results no longer reach it. Error text is unchanged: error(msg) already renders "Error: " + msg. Successful output loses the JSON quotes that DefaultToolResultConverter added around String returns, since ToolResultBlock passes through unserialised — the model now sees the bare content. ReActAgentToolResultErrorPrefixTest covered the removed heuristic and is replaced by ReActAgentToolResultStateTest, which asserts both directions of the new contract end-to-end, including a successful read whose content begins with "Error: ". Tool-level tests assert state alongside text. Closes agentscope-ai#2745
e36f264 to
bdd4602
Compare
|
@jujn Thanks — you were right, and the point turned out to be sharper than a style preference. Reworked as requested. Your concern reproduces. Five tools are exposed this way — What changed
Two findings worth your attention
One behaviour change to flag: successful output loses the JSON quotes that Scope question for you. This PR covers the tool named in #2745 plus every content-returning tool. Still returning strings: Verification: |
|
👍 Please continue in the current PR. |
Return ToolResultBlock from team, memory search, and todo tools, and Mono<ToolResultBlock> from subagent spawn, send, and generation. Preserve existing payloads while reporting explicit success, failure, and remote interruption states. Keep asynchronous acceptance and timeout promotion successful, and leave ReActAgent's fallback unchanged. Add state regression coverage, adapt direct test callers, and document the return-type migration and subagent outcome semantics in English and Chinese. Validation: Linux core/harness clean test passed (2284 + 894 tests, 0 failures, 0 errors, 9 existing skips); Windows harness and affected core tests passed. Spotless and git diff --check passed.
Preserve bounded filesystem listings and upstream task status messages while returning structured tool results. Retain web interruption handling and cover task lookup errors, successful payloads, and interrupted waits.
4b7508f to
6eaa5a1
Compare
|
This PR currently conflicts with git fetch origin
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved. Automated notification by github-manager-bot |
98f5e60 to
a5d8e88
Compare
Brings main (incl. agentscope-ai#2697, agentscope-ai#3324, agentscope-ai#2751, agentscope-ai#3129) into the branch. Only conflict: ReActAgentStructuredOutputTest.java — this branch's added test (testToolBasedExtractionPreservesMessageIdentity) sat exactly where agentscope-ai#2697 later appended its new tests; kept both sides (our test plus the incoming suite) and both import sets. ReActAgent.java auto-merged. Verified: ReActAgentStructuredOutputTest 16 tests green including both this branch's identity test and the merged-in tests.
- Builder.copy() now carries capabilityResolver (main's copy()-based build dropped it, silently disabling the grant layer) - reset_equipped_tools keeps the RuntimeContext param while adopting ToolResultBlock.success from agentscope-ai#2751 - externalToolSchema and rewriteResetToolSchema carry the new deferLoading schema field - grant tests observe the call-scoped rc (main isolates the caller rc) and assert the suspended external result
The takeover test can exceed its 3s sent.await budget on loaded CI runners: a >leaseMs (1500ms) stall expires the lease mid-takeover, the consumer backs off and re-acquires, and the reply lands after the budget. Widen the takeover assertion to 10s and the class-level @timeout to 60s, consistent with agentscope-ai#2751/agentscope-ai#3505. Closes agentscope-ai#3547
…uncation (agentscope-ai#3266) Rebase onto main (f4dd724) resolving the String -> ToolResultBlock return-type change from agentscope-ai#2751 and the session_search clamp from agentscope-ai#3382: - Clamp model-supplied maxResults to a 100 hard ceiling (Math.min), default 30 - Truncate matched lines at 500 chars (surrogate-pair-safe) with a memory_get hint - Test-before-cap scan so a match exactly at the cap is flagged, never dropped - Keep ToolResultBlock.success/error contract and the matchMode overloads
…uncation (agentscope-ai#3266) Rebase onto main (f4dd724) resolving the String -> ToolResultBlock return-type change from agentscope-ai#2751 and the session_search clamp from agentscope-ai#3382: - Clamp model-supplied maxResults to a 100 hard ceiling (Math.min), default 30 - Truncate matched lines at 500 chars (surrogate-pair-safe) with a memory_get hint - Test-before-cap scan so a match exactly at the cap is flagged, never dropped - Keep ToolResultBlock.success/error contract and the matchMode overloads
…uncation (agentscope-ai#3266) Rebase onto main (f4dd724) resolving the String -> ToolResultBlock return-type change from agentscope-ai#2751 and the session_search clamp from agentscope-ai#3382: - Clamp model-supplied maxResults to a 100 hard ceiling (Math.min), default 30 - Truncate matched lines at 500 chars (surrogate-pair-safe) with a memory_get hint - Test-before-cap scan so a match exactly at the cap is flagged, never dropped - Keep ToolResultBlock.success/error contract and the matchMode overloads
Problem
Closes #2745
Built-in tool calls could report failed operations as
SUCCESS(#2745). Inferring failure from output text also misclassified successful content that merely starts withError:or[ERROR].Changes
ToolResultBlock.success(String)so successful tool calls can carry an explicit terminal state.ToolResultBlock/Mono<ToolResultBlock>:ERRORINTERRUPTEDSUCCESStask_outputandwait_async_resultspropagateFAILED/CANCELLEDtask stateFAILED.ReActAgentand reflectiveToolkitregistration unchanged. Structured text no longer receives the JSON string quoting applied to plainStringreturns.8eb911).Compatibility
ToolResultBlockorMono<ToolResultBlock>; inspectgetState()and the text blocks ingetOutput().