Repository navigation
feat(app): mark offloaded tool placeholders with structured metadata - #3853
Merged
qbc2016 merged 3 commits intoNov 10, 2026
Merged
Conversation
Contributor
|
Thanks for the pull request. One thing worth sorting out before it is reviewed:
If you think it belongs here anyway, say so and a maintainer will take a look. |
The synthetic ToolChunk/ToolResponse that ToolOffloadMiddleware yields after the timeout carries state=SUCCESS exactly like a real result, so telling "still running in background" apart from "done" requires parsing the placeholder text (agentscope-ai#3845). The placeholder now carries metadata {background_task_id, tool_name, tool_state, offloaded_at}, which flows into the context ToolResultBlock like any tool metadata. Downstream consumers (UIs, gate middlewares, user code) can distinguish a pending offloaded call from a real success without text parsing. No behavior change.
konlue
force-pushed
the
fix/tool-offload-placeholder-metadata
branch
from
November 9, 2026 15:10
cfc33c6 to
57aa569
Compare
Contributor
Author
|
The PR is linked to a confirmed issue — #3845, which is assigned to me. It intentionally uses |
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #3845 (see "About the issue link" below)
AgentScope Version
main @
d8ebf89(rebased; originally opened against782bd43)Description
Problem
After
ToolOffloadMiddlewareoffloads a timed-out tool call, it yields a syntheticToolChunk/ToolResponsewithstate=ToolResultState.SUCCESSand instructions in plain text. The only way for downstream code to tell "still running in background" from "done" is to parse the placeholder text — exactly the text-based detection called out in #3845. Concretely, gate middlewares such asSOPStepSubmitMiddleware._submitted/TeamMemberMiddlewarecomparestate == ToolResultState.SUCCESS, so a still-running offloaded submit is currently indistinguishable from a completed one.Changes
src/agentscope/app/middleware/_tool_offload_middleware.py:ToolChunk/ToolResponsenow carry structured metadata —background_task_id,tool_name,tool_state: "running",offloaded_at— which flows into the contextToolResultBlocklike any tool metadata. Zero behavior change; the state staysSUCCESSbecauseToolResponse.stateis typed as a Literal of the four terminal states, so introducing a non-terminal state here would be a breaking design change left to the maintainers ([Bug]: ToolOffloadMiddleware reports a still-running tool as SUCCESS and may deliver the result after the agent has finalized #3845 asks for it, but it reaches far beyond this middleware).About the issue link
This PR intentionally does not use
Fixes #3845: that issue also asks for a persistent result store, per-tool execution policies, and a task management API — none of which belong in this change, and the issue should stay open for them. #3845 is confirmed and assigned to @konlue (this PR's author).Note on the original second commit
This PR originally also fixed stopped background tools being reported as "has completed" — while it was open, that misreport was independently fixed on main (interrupted responses now render as "has been cancelled"), so the commit was dropped in the rebase to avoid duplicating it. Two small gaps remain there if anyone wants to pick them up: a raw (non-absorbed) cancellation of the drain task is still silently skipped, and the completion notification's
sourceJSON does not carry the backgroundtask_id.How to test
pytest tests/tool_offload_middleware_test.py— 7 passed (includes the upstream-added tests).test_slow_tool_offloaded_to_backgroundnow asserts the placeholder metadata (background_task_idequals the registered background task id,tool_state == "running"); verified to fail against the unpatched middleware (metadatawas{}).black --line-length=79andflake8clean on both changed files.Checklist
/cc @lins — happy to hear whether this matches the direction you had in mind for #3845; the metadata marker is the slice that can land without design decisions, the remaining items there (persistent result store, per-tool execution policy) are untouched.