Skip to content

feat(app): mark offloaded tool placeholders with structured metadata - #3853

Merged
qbc2016 merged 3 commits into
agentscope-ai:mainfrom
konlue:fix/tool-offload-placeholder-metadata
Nov 10, 2026
Merged

qbc2016 merged 3 commits into
agentscope-ai:mainfrom
konlue:fix/tool-offload-placeholder-metadata

Conversation

@konlue

@konlue konlue commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3845 (see "About the issue link" below)

AgentScope Version

main @ d8ebf89 (rebased; originally opened against 782bd43)

Description

Problem

After ToolOffloadMiddleware offloads a timed-out tool call, it yields a synthetic ToolChunk/ToolResponse with state=ToolResultState.SUCCESS and 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 as SOPStepSubmitMiddleware._submitted / TeamMemberMiddleware compare state == ToolResultState.SUCCESS, so a still-running offloaded submit is currently indistinguishable from a completed one.

Changes

src/agentscope/app/middleware/_tool_offload_middleware.py:

  • The placeholder ToolChunk/ToolResponse now carry structured metadata — background_task_id, tool_name, tool_state: "running", offloaded_at — which flows into the context ToolResultBlock like any tool metadata. Zero behavior change; the state stays SUCCESS because ToolResponse.state is 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).
  • With this marker, downstream consumers (UIs, gate middlewares, user code) can distinguish a pending offloaded call from a real success without text parsing.

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 source JSON does not carry the background task_id.

How to test

pytest tests/tool_offload_middleware_test.py — 7 passed (includes the upstream-added tests).

  • test_slow_tool_offloaded_to_background now asserts the placeholder metadata (background_task_id equals the registered background task id, tool_state == "running"); verified to fail against the unpatched middleware (metadata was {}).
  • black --line-length=79 and flake8 clean on both changed files.

Checklist

  • An issue has been created for this PR
  • I have read the CONTRIBUTING.md
  • Related documentation has been updated (e.g. links, examples, etc.) in documentation repository — no documentation change needed
  • Code is ready for review

/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.

@github-actions github-actions Bot added pr/awaiting-review Waiting for maintainers to review this PR pr/no-linked-issue This PR does not link to any issue labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for the pull request. One thing worth sorting out before it is reviewed:

  • This pull request does not close an issue. Please open one describing the problem first and link it with Fixes #<number>, so the change can be discussed against the problem it solves.

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
konlue force-pushed the fix/tool-offload-placeholder-metadata branch from cfc33c6 to 57aa569 Compare November 9, 2026 15:10
@konlue konlue changed the title fix(app): mark offloaded tool placeholders machine-readable and report stopped tools as interrupted feat(app): mark offloaded tool placeholders with structured metadata Nov 9, 2026
@konlue

konlue commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

The PR is linked to a confirmed issue — #3845, which is assigned to me. It intentionally uses Part of #3845 instead of Fixes: that issue also asks for a persistent result store, per-tool execution policies, and a task management API, and this PR only delivers the machine-readable placeholder metadata slice, so the issue should stay open for the rest (details in the PR description under "About the issue link"). Happy to switch to Fixes if maintainers would rather close the issue with this change.

@qbc2016 qbc2016 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qbc2016
qbc2016 merged commit 72911f8 into agentscope-ai:main Nov 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/awaiting-review Waiting for maintainers to review this PR pr/no-linked-issue This PR does not link to any issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants