feat(service): expose background tasks via REST endpoints#1865
Open
XiuShenAl wants to merge 1 commit into
Open
feat(service): expose background tasks via REST endpoints#1865XiuShenAl wants to merge 1 commit into
XiuShenAl wants to merge 1 commit into
Conversation
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.
AgentScope Version
2.0.1
Description
Background
ToolOffloadMiddlewareoffloads tool calls that exceed the timeout to backgroundasynciotasks. However, there was no REST endpoint for the frontend to observe the status of these background tasks, leaving users unaware of ongoing or recently-completed executions (issue #1720).Changes
BackgroundTaskdataclass — added five fields:summary(≤128-char human-readable invocation summary),started_at(Unix epoch),completed_at,status(TaskStatusenum:running/completed/failed/cancelled), anderror_summary.TaskStatusenum — newstrenum tracking the full task lifecycle._on_donecallback — rewritten from "remove on completion" to "update status + capacity-based eviction". Terminal-state tasks are retained (up to_MAX_RETAINED_TASKS = 50) so frontends can observe outcomes via polling.BackgroundTaskManager— addedlist_tasks(user_id, session_id?)andget_task(task_id, user_id)query methods;register_taskgains asummarykeyword argument (backward-compatible default"").ToolOffloadMiddleware— added_make_summaryhelper that generates a concise summary from the tool name and JSON input, passed toregister_taskat offload time._router/_background_task.py— two read-only endpoints, both user-isolated viaDepends(get_current_user_id):GET /background-tasks— list all tasks for the current user (optional?session_id=filter)GET /background-tasks/{task_id}— single task detail; returns 404 for missing or cross-user access_router/_schema/_background_task.py—BackgroundTaskInfoandListBackgroundTasksResponsePydantic models;to_infoconversion helper.DELETEendpoint is provided — task cancellation remains exclusively via theToolStopagent tool, consistent with the architectural decision in PR feat(agent_team): refactor the agent service to support agent team #1776.ToolStop,CancelDispatcher,MessageBus, and Redis metadata schema are unchanged.How to test
timeout_secs(e.g. aBashtool runningsleep 30).GET /background-taskswith theX-User-IDheader — the task should appear withstatus: "running".statustransitions to"completed"andcompleted_atis populated.X-User-IDto access the sametask_id— should return404.pytest tests/background_task_endpoint_test.py tests/tool_offload_middleware_test.py -vChecklist