Skip to content

fix(subagent): let scoped sub-agents keep conversation-local tools like task_tracker - #5520

Merged
simonrosenberg merged 3 commits into
mainfrom
sub-agent-scope-exempt-tools
Oct 13, 2026
Merged

simonrosenberg merged 3 commits into
mainfrom
sub-agent-scope-exempt-tools

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Sub-agent scoping (#5358) refuses any sub-agent that uses a tool the delegating agent doesn't have. That's right for tools that reach the workspace, network or other capabilities. It's wrong for task_tracker, which only keeps a to-do list in the sub-agent's own conversation (TASKS.json in its persistence directory).


AGENT:

Why

Sub-agent scoping (#5358) refuses any sub-agent that uses a tool the delegating agent doesn't have. That's right for tools that reach the workspace, network or other capabilities. It's wrong for task_tracker, which only keeps a to-do list in the sub-agent's own conversation (TASKS.json in its persistence directory).

So a profile with terminal, file_editor and the task tool, but not task_tracker, can't use the built-in general-purpose sub-agent:

Failed to execute task: Agent 'general-purpose' uses task_tracker, which this agent does not have.

It also breaks the default delegation, because subagent_type defaults to general-purpose. This was found while QA'ing Agent Canvas's tool picker on agent-server 1.52.0.

Summary

  • New ToolDefinition.conversation_local class flag (default False). It marks tools that only read and write their own conversation's state.
  • SubAgentScope.missing_from ignores conversation-local tools. It's the single check behind the task tool's listing, the TaskManager start check and both workflow tools, so all of them change together.
  • TaskTrackerTool sets the flag. Every other tool is still checked as before.

Issue Number

Closes #5519

How to Test

uv run pytest tests/tools/task/test_sub_agent_scope.py tests/sdk/subagent

Two new tests, plus one updated expectation (general-purpose now lacks only file_editor, terminal on a read-only profile). All three fail with the scope.py change reverted and pass with it. The related suites (tests/sdk/subagent, tests/sdk/tool, tests/sdk/profiles, tests/tools/task, tests/tools/workflow): 741 passed after rebasing on main (e3a2682). Pre-commit (ruff, pyright, import rules) is clean.

Live check (.pr/conversation_local_e2e.py): it starts a real agent-server and Agent Canvas's scripted mock LLM. A profile with terminal, file_editor and task_tool_set delegates to general-purpose, whose scripted turn calls task_tracker plan.

.venv/bin/python .pr/conversation_local_e2e.py \
  --mock <agent-canvas>/tests/e2e/mock-llm/scripts/mock-llm-server.py \
  [--server-python <env with released openhands-agent-server>/bin/python]

This branch (rebased on main, agent-server 1.54.0):

parent tools: ['file_editor', 'finish', 'invoke_skill', 'task', 'terminal', 'think']
sub-agent tools: ['file_editor', 'finish', 'task_tracker', 'terminal', 'think']
  PASS  conversation finished
  PASS  parent has no task_tracker
  PASS  general-purpose is offered
  PASS  general-purpose ran with task_tracker
  PASS  delegation returned the sub-agent's answer
  PASS  no scope refusal
ALL PASSED

main at e3a2682 (1.54.0, with this branch's scope.py change reverted) still fails the same way:

sub-agent tools: None
  FAIL  general-purpose is offered
  FAIL  general-purpose ran with task_tracker
  FAIL  delegation returned the sub-agent's answer  [... Agent 'general-purpose' uses task_tracker, which this agent does not have.]
  FAIL  no scope refusal
4 FAILED

The sub-agent's TASKS.json is written to conversations/<parent>/subagents/<sub-agent>/, which is the sub-agent's own persistence directory. The live check now drops the host's OH_* variables, so the test server does not pick up the sandbox's webhooks or conversations path.

Released 1.53.0 (--server-python pointing at a venv with openhands-agent-server==1.53.0):

sub-agent tools: None
  FAIL  general-purpose is offered
  FAIL  general-purpose ran with task_tracker
  FAIL  delegation returned the sub-agent's answer  [... Agent 'general-purpose' uses task_tracker, which this agent does not have.]
  FAIL  no scope refusal
4 FAILED

Video/Screenshots

N/A (backend change; output above).

🤖 Generated with Claude Code. Rebase and live re-validation by an AI agent (OpenHands) on behalf of @simonrosenberg.


🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:d1123e6-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-d1123e6-python \
  ghcr.io/openhands/agent-server:d1123e6-python

All tags pushed for this build

ghcr.io/openhands/agent-server:d1123e6-golang-amd64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-golang-amd64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-golang-amd64
ghcr.io/openhands/agent-server:d1123e6-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:d1123e6-golang-arm64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-golang-arm64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-golang-arm64
ghcr.io/openhands/agent-server:d1123e6-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:d1123e6-java-amd64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-java-amd64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-java-amd64
ghcr.io/openhands/agent-server:d1123e6-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:d1123e6-java-arm64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-java-arm64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-java-arm64
ghcr.io/openhands/agent-server:d1123e6-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:d1123e6-python-amd64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-amd64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-amd64
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-amd64
ghcr.io/openhands/agent-server:d1123e6-python-arm64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-arm64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-arm64
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-arm64
ghcr.io/openhands/agent-server:d1123e6-python-minimal-amd64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-minimal-amd64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-minimal-amd64
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:d1123e6-python-minimal-arm64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-minimal-arm64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-minimal-arm64
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:d1123e6-python-slim-amd64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-slim-amd64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-slim-amd64
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:d1123e6-python-slim-arm64
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-slim-arm64
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-slim-arm64
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:d1123e6-golang
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-golang
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-golang
ghcr.io/openhands/agent-server:d1123e6-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:d1123e6-java
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-java
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-java
ghcr.io/openhands/agent-server:d1123e6-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:d1123e6-python-minimal
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-minimal
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-minimal
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-minimal
ghcr.io/openhands/agent-server:d1123e6-python-slim
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python-slim
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python-slim
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime-slim
ghcr.io/openhands/agent-server:d1123e6-python
ghcr.io/openhands/agent-server:d1123e689b13cd1b17dc23232bdc335f8a54621a-python
ghcr.io/openhands/agent-server:sub-agent-scope-exempt-tools-python
ghcr.io/openhands/agent-server:d1123e6-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., d1123e6-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., d1123e6-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
  ✅ **PR Artifacts Cleaned Up**

  The `.pr/` directory is no longer present.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/tool
   tool.py3562892%94–95, 97, 107, 161, 163, 187, 195–198, 327, 447, 494, 567–568, 590–591, 617, 642, 646, 673–674, 747, 868, 925, 937–938
openhands-tools/openhands/tools/task_tracker
   definition.py1358636%57, 60–62, 64–65, 68–69, 71, 87, 89–91, 93, 95–96, 99, 102–104, 106–107, 110–116, 118–120, 123, 125–128, 130, 133, 136–137, 139–140, 142–143, 145, 174, 176, 178–180, 187, 189–190, 195–196, 202, 214–215, 217–219, 223–224, 226–229, 231, 236, 242–246, 250, 254–255, 257–258, 260, 262–266
TOTAL479641359572% 

@simonrosenberg

Copy link
Copy Markdown
Member Author

@OpenHands rebase and do e2e validation make sure there are no bugs and fill in HUMAN section in description and make sure CI is green

@openhands-ai

openhands-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

I'm on it! simonrosenberg can track my progress at all-hands.dev

simonrosenberg and others added 2 commits October 12, 2026 15:47
A sub-agent scope now ignores tools that only touch their own conversation's
state. task_tracker is the first such tool, so a profile with terminal and
file_editor can delegate to general-purpose without also selecting it.

Closes #5519

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: openhands <openhands@all-hands.dev>
@simonrosenberg
simonrosenberg force-pushed the sub-agent-scope-exempt-tools branch from aef1050 to 32f5c6e Compare October 12, 2026 15:52

Copy link
Copy Markdown
Member Author

@simonrosenberg I rebased on main (e3a2682, 1.54.0), checked the change end to end, and CI is green: 48 checks passed. The 3 skipped checks are Validate PR description, which doesn't run on drafts, and the two .pr/ cleanup jobs.

Validation

  • Unit tests: 741 passed across tests/tools/task, tests/tools/workflow, tests/sdk/subagent, tests/sdk/tool and tests/sdk/profiles. With main's scope.py, the 3 new or changed scope tests fail, so they do catch the bug.
  • Live check (.pr/conversation_local_e2e.py, real agent-server and Agent Canvas mock LLM): all 6 checks pass on this branch. With main's scope.py it shows the original refusal, Agent 'general-purpose' uses task_tracker, which this agent does not have.
  • The sub-agent's TASKS.json is written to conversations/<parent>/subagents/<sub-agent>/. That confirms task_tracker only touches the sub-agent's own conversation state, so exempting it doesn't widen what the sub-agent can reach.
  • I found no bugs in the change. I did fix one problem in the live-check script (32f5c6e): it passed the host's OH_* environment to the test server, so in this sandbox the server picked up its webhooks and conversations path. That also made shutdown take 30 s or more.

HUMAN section: I left it as it was. The repo rules (AGENTS.md and the template comment) say AI agents must not write it, and the description check needs a note in a human's own words. Please add at least 20 characters there before you mark the PR ready. The linked issue #5519 already has ready-for-dev, so that's the only thing left for the description check.

This comment was created by an AI agent (OpenHands) on behalf of @simonrosenberg.

@openhands-ai

openhands-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

I rebased PR #5520 onto main and the end-to-end check passes, and CI is green. The one thing I didn't do is fill in the HUMAN section: the repo's rules say AI agents must not write it, so you'll need to add that note yourself.

Rebase: The branch is now on main at e3a2682 (1.54.0). It rebased with no conflicts, and I force-pushed it.

Testing

  • Unit tests: 741 passed across the task, workflow, sub-agent, tool and profile test suites. When I put back main's version of the scope check, the 3 new or changed scope tests fail, so they catch the bug.
  • Live check: The PR's script (.pr/conversation_local_e2e.py) runs a real agent-server with Agent Canvas's scripted mock LLM. On this branch, all 6 of its checks pass. With main's scope check put back, it fails with the original error: Agent 'general-purpose' uses task_tracker, which this agent does not have.
  • Where task_tracker writes: The sub-agent's TASKS.json is saved in its own folder, under conversations/<parent>/subagents/<sub-agent>/. So letting sub-agents keep task_tracker doesn't give them access to anything outside their own conversation.

Bugs: I found none in the fix itself. I did fix one problem in the live-check script (commit 32f5c6e). It passed this machine's OH_* environment settings to the test server. That meant the server tried to post events to app.all-hands.dev and could use the real conversations folder, and it took 30 seconds or more to shut down. The script now drops those settings.

CI: All 48 checks pass on the new head. Three were skipped: Validate PR description, which doesn't run while the PR is a draft, and two jobs that only clean up the .pr/ folder.

HUMAN section: The repo's AGENTS.md and the PR template both say AI agents must not edit it. The description check also requires a note of at least 20 characters in a person's own words. That check will run once you mark the PR ready for review, so please add the note before then. Issue #5519 already has the ready-for-dev label that check also looks for, so the note is all it still needs.

Description and reply: In the PR description I updated only the AGENT section, adding the results after the rebase and the failing run against main. I also posted a summary reply on the PR: #5520 (comment)

@simonrosenberg
simonrosenberg marked this pull request as ready for review October 12, 2026 16:10

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This review was posted by an AI agent (OpenHands).

Review of PR #5520

Scope check: this change belongs in OpenHands/software-agent-sdk. It modifies SDK tool-definition metadata and sub-agent scope enforcement, both owned by this repository.

What I verified

  • Head matches: 32f5c6e7f805e54101f390f1a20a2953cce5fde1 (title, body, links unchanged). Linked issue #5519 is open with bug, priority:medium, ready-for-dev.
  • CI: no failing/timed-out/action-required check runs on the current head.
  • Tests (in workspace): tests/tools/task/test_sub_agent_scope.py (15 passed), tests/sdk/subagent, tests/sdk/tool, tests/sdk/profiles, tests/tools/task, tests/tools/workflow — 614 passed. The two new tests and the updated general-purpose expectation pass. One unrelated failure, tests/sdk/subagent/test_subagent_loader.py::test_load_user_agents_from_openhands_dir, exists in a file this PR does not touch and fails on the base revision independently.
  • Lint/format: ruff check and ruff format --check clean on all changed files.

Assessment

  • The new ToolDefinition.conversation_local ClassVar defaults to False, so it is a no-op for every existing tool and has no serialization/persistence impact (ClassVars are not model fields).
  • SubAgentScope.missing_from is the single check behind the sub-agent listing, the TaskManager start check, and both workflow tools, so the exemption is applied consistently across all delegation entry points. I traced each caller (task/definition.py:298, task/manager.py:386).
  • TaskTrackerTool.create takes save_dir from conv_state.persistence_dir; for a sub-agent that resolves to conversations/<parent>/subagents/<sub-agent>/, so the tool genuinely only reads/writes its own conversation state, matching the exemption's stated rationale. No cross-conversation write path is introduced.
  • _conversation_local resolves the class via registered_tool_class(name) or effective_builtin_class(name) against the already-canonicalized names from _tool_names; for task_tracker this resolves to the registered TaskTrackerTool (flag True), confirmed at runtime.

No material correctness, security, compatibility, or acceptance-criterion defect found on the current head. The linked issue's reproducer is addressed and the PR includes before/after live evidence.

✅ APPROVED

@simonrosenberg
simonrosenberg merged commit c1dfd9c into main Oct 13, 2026
51 checks passed
@simonrosenberg
simonrosenberg deleted the sub-agent-scope-exempt-tools branch October 13, 2026 12:29
@github-actions github-actions Bot mentioned this pull request Oct 15, 2026
1 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A scoped profile can't delegate to general-purpose because it lacks task_tracker

3 participants