feat: add switch_agent tool for model-initiated agent switching#262
Open
marius-kilocode wants to merge 2 commits intodevfrom
Open
feat: add switch_agent tool for model-initiated agent switching#262marius-kilocode wants to merge 2 commits intodevfrom
marius-kilocode wants to merge 2 commits intodevfrom
Conversation
Allow the AI model to request switching between primary agents (code, plan, debug, orchestrator) during a conversation. Uses the existing permission system (ctx.ask) so users can configure it as ask/allow/deny. Creates a synthetic user message with the new agent name, which the session loop picks up naturally. The TUI agent indicator now also reactively updates when a mid-turn switch occurs.
| await ctx.ask({ | ||
| permission: "switch_agent", | ||
| patterns: [params.agent], | ||
| always: ["*"], |
Contributor
There was a problem hiding this comment.
WARNING: always: ["*"] makes "Always allow" approval apply to all future agent switches
For switch_agent, approving "always" effectively allows switching to any agent without prompting, which can act like a permission escalation path. Scoping the persisted approval to the requested agent name keeps the UX ("always allow this") while reducing blast radius.
Suggested change
| always: ["*"], | |
| always: [params.agent], |
Contributor
Code Review SummaryStatus: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (5 files)
|
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.
Summary
switch_agenttool that allows the AI model to request switching between primary agents (code, plan, debug, orchestrator) during a conversationctx.ask) so users can configure it asask(default, prompts user),allow(auto-approve), ordeny(block) in theiropencode.jsonHow it works
ctx.ask(), then creates a synthetic user message with the new agent namelastUser.agent- no loop changes neededlastUserMessage().idto update the agent indicator on mid-turn switchesFiles changed
packages/opencode/src/tool/switch-agent.tspackages/opencode/src/tool/switch-agent.txt{agents}placeholderpackages/opencode/src/tool/registry.tsSwitchAgentToolpackages/opencode/src/agent/agent.tsswitch_agentpermission:denydefault,askfor code/plan/debug/orchestratorpackages/opencode/src/cli/cmd/tui/component/prompt/index.tsxpackages/opencode/test/agent/switch-agent.test.tsUser configuration
{ "agent": { "code": { "permission": { "switch_agent": "allow" } } } }