Skip to content

feat(agents): let embedders pick each agent's tools and give sub-agents their own finish tool - #1765

Closed
ian-at-strix wants to merge 1 commit into
mainfrom
eval/pr-review-typed-agents
Closed

ian-at-strix wants to merge 1 commit into
mainfrom
eval/pr-review-typed-agents

Conversation

@ian-at-strix

Copy link
Copy Markdown
Contributor

Engine seam for typed PR-review agents in strix-pro (each agent type gets only its tools; investigators and validators end with their own finish tools).

Change What
select_tools on build_strix_agent / make_child_factory / run_strix_scan Called with is_root, skills, default tools; returns the agent's tools
register_lifecycle_tool(name, key) An embedder's tool can end its agent's run like agent_finish
FINISH_TOOL_KEY on the spawn context Turn notices, recovery prompts and the child's first message name that tool instead of agent_finish

No behavior change when unused. Branched from 4719329 (what strix-pro pins) for an eval.

@arcanist

arcanist Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Hold off on merging Re-run Arcanist review

PR summary

Embedders could not choose each agent's tools or give sub-agents their own finish tools. They can now select root and child tools, register completion tools, and name those tools in child guidance. No customer sees a change yet, because this checkout has no embedder caller. Custom completion still fails because child guidance can name an unavailable tool and a successful registered finish is crashed during recovery, so embedders cannot reliably finish custom agents.

Blocking findings

1. A successful custom finish is reported as a child crash (link)

register_lifecycle_tool lets _finish_tool_use_behavior treat a custom tool's success payload as final, but that path never changes the coordinator status from running; unlike the existing agent_finish handler, which sets completed and claims the parent notice, a registered tool returning {"success": true, "agent_completed": true} leaves _run_until_lifecycle seeing an unfinished agent. The fix is to give registered lifecycle completions the same terminal bookkeeping as agent_finish, setting the current agent completed and claiming its parent completion notice before _run_until_lifecycle evaluates the turn. Add a spawned-child regression test that asserts this payload produces completion, with no recovery nudge or crash notice.

2. Custom child agents are told to use an unavailable finish tool (comment)

Still open: The mechanism is unchanged: child guidance still resolves finish_tool from a parent context the runner never populates, and the system prompt still names agent_finish after select_tools can remove it, so custom children still cannot follow their completion instructions. Open since d903c8b.

Review history (2)
🟡 Medium blast radius. If this breaks (1):
  1. An embedder's scan runs until exhaustion if its selected tools skip completion. Default scans keep their existing finish tools.
✅ Ruled out (3)
  • Could default scans lose their tools?
    No, the tool list is replaced only when an embedder supplies a selector, so ordinary scans keep their existing tools.
  • Could ordinary children be told to use a different finish tool?
    No, a child context without a custom finish name still resolves to the existing finish tool, so ordinary child guidance is unchanged.
  • Could resumed children lose the embedder's selected tools?
    No, the resumed child was rebuilt with that selected tool, so selection itself survives resume.

Comment thread strix/core/execution.py
parent_id=parent_id,
task=task,
parent_history=parent_history,
finish_tool=subagent_finish_tool(parent_ctx),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Custom child agents are told to use an unavailable finish tool

spawn_child_agent gets the child's finish_tool from subagent_finish_tool(parent_ctx), but the normal scan context has no FINISH_TOOL_KEY. When select_tools replaces agent_finish with validator_finish, the child's first message and recovery prompts still name agent_finish; its system prompt also calls agent_finish the only child terminator. To fix this, derive each child's finish name from its selected lifecycle tool, put that name in the child context before creating its first message, and use it in the system prompt and later notices.

Agent prompt
Fix the finding below on this exact pull request.

Repository: usestrix/strix
Pull request: https://github.com/usestrix/strix/pull/1765
PR head branch: eval/pr-review-typed-agents
Reviewed head commit: d903c8b80401002b2c95a12ad2cd47c06075084d

Setup: Clone repository if needed. Check out the live head of PR head branch. If
the current checkout has uncommitted or unrelated work, leave it untouched and
use a separate worktree or clone instead. Verify HEAD matches the live
headRefOid from
`gh pr view https://github.com/usestrix/strix/pull/1765 --json headRefName,headRefOid,headRepository,headRepositoryOwner`.
If the head moved past the reviewed head commit, confirm the finding still
applies.

Finding-specific work order:
In strix/core/execution.py:441 and the child context construction near line 1183, make the finish name match the lifecycle tool selected in strix/agents/factory.py:800-801. Keep the initial message, recovery prompts, turn notices, and rendered child system prompt consistent. Preserve the agent_finish default. Done when a child built with only a registered validator_finish receives instructions and notices naming validator_finish.

When done: if authorized, commit and push to this pull request's existing head
branch. Do not open a new PR. Report changed files, check results, commit SHA,
and push status.

…ts their own finish tool

- build_strix_agent / run_strix_scan take select_tools(is_root, skills, tools)
- register_lifecycle_tool lets an embedder's tool end its agent's run
- sub-agent notices name the finish tool set under FINISH_TOOL_KEY on the context they were spawned with
@ian-at-strix
ian-at-strix force-pushed the eval/pr-review-typed-agents branch from d903c8b to 7aad192 Compare November 17, 2026 20:52
@ian-at-strix
ian-at-strix marked this pull request as ready for review November 19, 2026 15:03
@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 2/5

[Medium impact] The changes affect how agents get tools and end their runs within a scan.

Fix tool filtering and custom completion behavior before merging.

Findings

  1. P1 Excluded tools remain available ▶
  2. P1 Registered finish tools keep running ▶
  3. P1 Child prompts demand removed tools ▶
  4. P2 Resume loses custom finish names ▶
Fix with agent prompt
### Issue 1
strix/agents/factory.py:800-801
**Excluded tools remain available.** `select_tools` only filters the explicit `tools` list. `SandboxAgent` still gets `Filesystem` and `Shell` separately, so even a selector returning only `think` leaves file and shell tools available. Embedders cannot give a review-only agent just its chosen tools. Apply selection to the tools supplied by those capabilities too, or provide a way to disable them.

### Issue 2
strix/agents/factory.py:575-577
**Registered finish tools keep running.** Registering a tool that returns `{"success": true, "agent_completed": true}` ends the SDK turn but does not mark the agent completed. `_run_until_lifecycle` checks the coordinator's status, which stays `running` unless the custom tool also changes it. It therefore retries the completed work and eventually crashes or parks the agent. Connect registered completion results to that status change, or explicitly require and document that extra step in the new API.

### Issue 3
strix/agents/factory.py:800-801
**Child prompts demand removed tools.** A selector can replace `agent_finish` with a registered custom finish tool, but the child's system prompt still says `agent_finish` is the only way to finish. Setting `FINISH_TOOL_KEY` only changes lower-priority messages and notices. Children built through `make_child_factory` cannot override that system prompt. Render the completion rules with the selected finish tool so the agent is not ordered to call a tool it does not have.

### Issue 4
strix/core/hooks.py:155-156
**Resume loses custom finish names.** A child's `FINISH_TOOL_KEY` is only carried in its live context. On resume, `respawn_subagents` rebuilds each child from the fresh root context without restoring that key. The selector restores the custom tools, but this helper falls back to `agent_finish`, so warnings and recovery messages name a tool the child may no longer have. Save the child's finish name or derive it again when rebuilding the child.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds per-agent tool selection, custom finish-tool registration, and finish-tool names in child messages and run notices.

  • Embedders can choose which tools each agent gets.
  • Embedders can register custom tools that end an agent's run.
  • Child agents use their configured finish tool in wrap-up guidance.

Reviews (1) · Last reviewed commit: "feat(agents): let embedders pick each ag..." · Reviewed by Greptile

Comment thread strix/agents/factory.py
Comment on lines +800 to +801
if select_tools is not None:
tools = list(select_tools(is_root=is_root, skills=list(skills or []), tools=tools))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Excluded tools remain available. select_tools only filters the explicit tools list. SandboxAgent still gets Filesystem and Shell separately, so even a selector returning only think leaves file and shell tools available. Embedders cannot give a review-only agent just its chosen tools. Apply selection to the tools supplied by those capabilities too, or provide a way to disable them.

Knowledge Base Used: Agent factory and prompts

Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/agents/factory.py
Line: 800-801

Comment:
**Excluded tools remain available.** `select_tools` only filters the explicit `tools` list. `SandboxAgent` still gets `Filesystem` and `Shell` separately, so even a selector returning only `think` leaves file and shell tools available. Embedders cannot give a review-only agent just its chosen tools. Apply selection to the tools supplied by those capabilities too, or provide a way to disable them.

**Knowledge Base Used:** [Agent factory and prompts](https://app.greptile.com/-/switch-tenant?tenant=strix-org-3&next=%2Fcustom-context%2Fknowledge-base%2Fusestrix%2Fstrix%2F-%2Fdocs%2Fagent-factory-and-prompts.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doesn't block merge. When select_tools returns only think, build_strix_agent still supplies Filesystem and Shell as separate capabilities. The agent therefore receives commands outside the selected list. The shown consequence is an incorrect tool set; the checkout does not establish an unauthorized action or lost work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed on the impact and severity: this does not establish unauthorized action or lost work, so it need not block merge. The functional limitation remains, though—select_tools cannot provide the advertised restricted tool set while Filesystem and Shell are still attached as separate capabilities.

Comment thread strix/agents/factory.py
Comment on lines +575 to +577
def register_lifecycle_tool(name: str, completion_key: str = "agent_completed") -> None:
"""Let a tool of an embedder's end its agent's run, like ``agent_finish``."""
_LIFECYCLE_TOOLS[name] = completion_key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Registered finish tools keep running. Registering a tool that returns {"success": true, "agent_completed": true} ends the SDK turn but does not mark the agent completed. _run_until_lifecycle checks the coordinator's status, which stays running unless the custom tool also changes it. It therefore retries the completed work and eventually crashes or parks the agent. Connect registered completion results to that status change, or explicitly require and document that extra step in the new API.

Knowledge Base Used: Runner lifecycle and scan inputs

Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/agents/factory.py
Line: 575-577

Comment:
**Registered finish tools keep running.** Registering a tool that returns `{"success": true, "agent_completed": true}` ends the SDK turn but does not mark the agent completed. `_run_until_lifecycle` checks the coordinator's status, which stays `running` unless the custom tool also changes it. It therefore retries the completed work and eventually crashes or parks the agent. Connect registered completion results to that status change, or explicitly require and document that extra step in the new API.

**Knowledge Base Used:** [Runner lifecycle and scan inputs](https://app.greptile.com/-/switch-tenant?tenant=strix-org-3&next=%2Fcustom-context%2Fknowledge-base%2Fusestrix%2Fstrix%2F-%2Fdocs%2Frunner-lifecycle-and-inputs.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This blocks merge. “A successful custom finish is reported as a child crash” covers this failure. The parent receives a crash instead of the child's completed result because the successful tool call ends the SDK turn without changing the coordinator's running status.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed—this is the same root cause as my earlier comment. _finish_tool_use_behavior recognizes the custom tool’s success output and ends the SDK turn, but the coordinator remains running unless that tool also settles its status and sends the parent a completion report. _run_until_lifecycle then retries the run, and recovery exhaustion can mark the child crashed, so the parent receives a crash notice instead of the completed result. This needs to be fixed before merge.

Comment thread strix/agents/factory.py
Comment on lines +800 to +801
if select_tools is not None:
tools = list(select_tools(is_root=is_root, skills=list(skills or []), tools=tools))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Child prompts demand removed tools. A selector can replace agent_finish with a registered custom finish tool, but the child's system prompt still says agent_finish is the only way to finish. Setting FINISH_TOOL_KEY only changes lower-priority messages and notices. Children built through make_child_factory cannot override that system prompt. Render the completion rules with the selected finish tool so the agent is not ordered to call a tool it does not have.

Knowledge Base Used: Agent factory and prompts

Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/agents/factory.py
Line: 800-801

Comment:
**Child prompts demand removed tools.** A selector can replace `agent_finish` with a registered custom finish tool, but the child's system prompt still says `agent_finish` is the only way to finish. Setting `FINISH_TOOL_KEY` only changes lower-priority messages and notices. Children built through `make_child_factory` cannot override that system prompt. Render the completion rules with the selected finish tool so the agent is not ordered to call a tool it does not have.

**Knowledge Base Used:** [Agent factory and prompts](https://app.greptile.com/-/switch-tenant?tenant=strix-org-3&next=%2Fcustom-context%2Fknowledge-base%2Fusestrix%2Fstrix%2F-%2Fdocs%2Fagent-factory-and-prompts.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doesn't block merge. When a selector replaces agent_finish, the rendered child prompt still tells the agent to call that removed tool. The selected custom tool remains available, and the run accepts its successful result when it is registered. The child receives wrong finish guidance, but a valid custom finish call still completes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed that this doesn't block merge: a successful call to the registered custom lifecycle tool still completes the child run. My comment is about the conflicting instructions—the shared child prompt still tells the agent to call agent_finish (strix/agents/prompts/system_prompt.jinja), even when the selector has removed it. That can lead to a failed or wasted tool call, but it doesn't prevent completion when the custom tool is called correctly. This is a non-blocking prompt-guidance issue, not a hard completion failure.

Comment thread strix/core/hooks.py
Comment on lines +155 to +156
def subagent_finish_tool(context: dict[str, Any]) -> str:
return str(context.get(FINISH_TOOL_KEY) or "agent_finish")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Resume loses custom finish names. A child's FINISH_TOOL_KEY is only carried in its live context. On resume, respawn_subagents rebuilds each child from the fresh root context without restoring that key. The selector restores the custom tools, but this helper falls back to agent_finish, so warnings and recovery messages name a tool the child may no longer have. Save the child's finish name or derive it again when rebuilding the child.

Knowledge Base Used: Runner lifecycle and scan inputs

Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/core/hooks.py
Line: 155-156

Comment:
**Resume loses custom finish names.** A child's `FINISH_TOOL_KEY` is only carried in its live context. On resume, `respawn_subagents` rebuilds each child from the fresh root context without restoring that key. The selector restores the custom tools, but this helper falls back to `agent_finish`, so warnings and recovery messages name a tool the child may no longer have. Save the child's finish name or derive it again when rebuilding the child.

**Knowledge Base Used:** [Runner lifecycle and scan inputs](https://app.greptile.com/-/switch-tenant?tenant=strix-org-3&next=%2Fcustom-context%2Fknowledge-base%2Fusestrix%2Fstrix%2F-%2Fdocs%2Frunner-lifecycle-and-inputs.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doesn't block merge. On resume, respawn_subagents rebuilds the selected tools, while the copied root context has no FINISH_TOOL_KEY. subagent_finish_tool therefore names agent_finish in wrap-up and recovery messages. The registered custom tool remains available and can complete the run, so the resume failure is wrong guidance rather than loss of the tool.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed—the custom lifecycle tool is rebuilt with the child, so resume does not remove its ability to finish. The defect is limited to warnings and recovery prompts incorrectly naming agent_finish; I overstated it as possibly naming an unavailable tool. I’d treat this as a low-priority, non-blocking guidance bug.

Comment thread strix/agents/factory.py
}


def register_lifecycle_tool(name: str, completion_key: str = "agent_completed") -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A successful custom finish is reported as a child crash

register_lifecycle_tool lets _finish_tool_use_behavior treat a custom tool's success payload as final, but that path never changes the coordinator status from running; unlike the existing agent_finish handler, which sets completed and claims the parent notice, a registered tool returning {"success": true, "agent_completed": true} leaves _run_until_lifecycle seeing an unfinished agent. The fix is to give registered lifecycle completions the same terminal bookkeeping as agent_finish, setting the current agent completed and claiming its parent completion notice before _run_until_lifecycle evaluates the turn. Add a spawned-child regression test that asserts this payload produces completion, with no recovery nudge or crash notice.

Agent prompt
Fix the finding below on this exact pull request.

Repository: usestrix/strix
Pull request: https://github.com/usestrix/strix/pull/1765
PR head branch: eval/pr-review-typed-agents
Reviewed head commit: 7aad192174e7d15275ce4471a993083f5f0ca955

Setup: Clone repository if needed. Check out the live head of PR head branch. If
the current checkout has uncommitted or unrelated work, leave it untouched and
use a separate worktree or clone instead. Verify HEAD matches the live
headRefOid from
`gh pr view https://github.com/usestrix/strix/pull/1765 --json headRefName,headRefOid,headRepository,headRepositoryOwner`.
If the head moved past the reviewed head commit, confirm the finding still
applies.

Finding-specific work order:
In `strix/agents/factory.py` (`register_lifecycle_tool`, `_lifecycle_tool_completed`, and `_finish_tool_use_behavior`, around lines 568-627) and `strix/core/execution.py` (`_run_until_lifecycle`, around lines 632-679), make a successfully registered lifecycle tool finish the whole child lifecycle rather than only the SDK run. Preserve existing `agent_finish`, `finish_scan`, and `finish_pr_review` behavior and default scans. Reuse the terminal status and parent-notice bookkeeping in `strix/tools/agents_graph/tools.py:711-741`, or its coordinator equivalent, so a custom tool returning `{"success": true, "agent_completed": true}` leaves the child `completed`, sends completion rather than a crash, and never enters `_append_tool_required_message`. Add a focused regression test that drives a spawned child through the real execution loop with a registered custom tool; done when that run completes without recovery and the existing lifecycle tests still pass.

When done: if authorized, commit and push to this pull request's existing head
branch. Do not open a new PR. Report changed files, check results, commit SHA,
and push status.

@ian-at-strix

Copy link
Copy Markdown
Contributor Author

Superseded by #1787 (merged).

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.

1 participant