Repository navigation
feat(agents): let embedders pick each agent's tools and give sub-agents their own finish tool - #1765
ian-at-strix wants to merge 1 commit into
Conversation
Hold off on merging
PR summaryEmbedders 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 findings1. A successful custom finish is reported as a child crash (link)
2. Custom child agents are told to use an unavailable finish tool (comment) Still open: The mechanism is unchanged: child guidance still resolves Review history (2)
🟡 Medium blast radius. If this breaks (1):
✅ Ruled out (3)
|
| parent_id=parent_id, | ||
| task=task, | ||
| parent_history=parent_history, | ||
| finish_tool=subagent_finish_tool(parent_ctx), |
There was a problem hiding this comment.
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
d903c8b to
7aad192
Compare
[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
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.SummaryAdds per-agent tool selection, custom finish-tool registration, and finish-tool names in child messages and run notices.
Reviews (1) · Last reviewed commit: "feat(agents): let embedders pick each ag..." · Reviewed by Greptile |
| if select_tools is not None: | ||
| tools = list(select_tools(is_root=is_root, skills=list(skills or []), tools=tools)) |
There was a problem hiding this 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
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this 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
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if select_tools is not None: | ||
| tools = list(select_tools(is_root=is_root, skills=list(skills or []), tools=tools)) |
There was a problem hiding this 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
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| def subagent_finish_tool(context: dict[str, Any]) -> str: | ||
| return str(context.get(FINISH_TOOL_KEY) or "agent_finish") |
There was a problem hiding this 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
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| } | ||
|
|
||
|
|
||
| def register_lifecycle_tool(name: str, completion_key: str = "agent_completed") -> None: |
There was a problem hiding this comment.
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.
|
Superseded by #1787 (merged). |
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).
select_toolsonbuild_strix_agent/make_child_factory/run_strix_scanis_root,skills, defaulttools; returns the agent's toolsregister_lifecycle_tool(name, key)agent_finishFINISH_TOOL_KEYon the spawn contextagent_finishNo behavior change when unused. Branched from
4719329(what strix-pro pins) for an eval.