-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(agent): default agent selection in acp and headless mode #8678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(agent): default agent selection in acp and headless mode #8678
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found the following potentially related PRs: Related PRs:
These are not direct duplicates of PR #8678, but they address related aspects of agent selection, configuration, and mode handling. The most closely related is #7796 which also deals with guarding default agent selection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes default agent selection in ACP and headless modes to properly respect the default_agent configuration while filtering out unsuitable agents (subagents and hidden agents).
Changes:
- Modified
Agent.defaultAgent()to filter out subagents and hidden agents from default selection - Added logic to persist the default agent mode in ACP session initialization
- Added 7 comprehensive unit tests covering various default agent selection scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/opencode/src/agent/agent.ts | Updated defaultAgent() function with proper filtering logic for subagents and hidden agents with appropriate fallback behavior |
| packages/opencode/src/acp/agent.ts | Added setMode() call to persist default agent mode during ACP session initialization |
| packages/opencode/test/agent/agent.test.ts | Added 7 test cases covering default agent selection including config respect, subagent filtering, hidden agent filtering, non-existent agents, and disabled build scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ction Signed-off-by: assagman <[email protected]>
Signed-off-by: assagman <[email protected]>
Signed-off-by: assagman <[email protected]>
8d1a6ef to
9dc3746
Compare
Previously used 3-step fallback (primary -> visible -> build). Now uses single check: find primary+visible OR hardcoded 'build'. Same behavior, cleaner implementation. Signed-off-by: assagman <[email protected]>
packages/opencode/src/agent/agent.ts
Outdated
| export async function defaultAgent() { | ||
| return state().then((x) => Object.keys(x)[0]) | ||
| const agents = await list() | ||
| const primaryVisible = agents.find((a) => a.mode !== "subagent" && a.hidden !== true) | ||
| return primaryVisible?.name || "build" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should prolly throw an error if no primary agent is available... Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm currently thinking about it. Maybe you're right.
TUI throws unhandled exception here: https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/cli/cmd/tui/context/local.tsx#L41-L41
(when no primary visible agent found)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rekram1-node , I've updated the logic as throwing errors for invalid cases:
- cfg.default_agent is set:
a. cfg.default_agent is not found in state
b. cfg.default_agent is a subagent
c. cfg.default_agent is hidden - cfg.default_agent is not set and all of them either subagent or hidden -> no primary visible agent found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Users now see specific error messages explaining why their configured default_agent cannot be used (not found, is subagent, or is hidden) instead of silently falling back to a different agent. Signed-off-by: assagman <[email protected]>
b1ba56d to
e6a6e61
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/review |
|
lgtm |
Summary
Make ACP and headless mode respect
default_agentconfig and properly handle agent modes and visibilities. Previously, subagents and hidden agents could be incorrectly selected as the default agent.Fixes #8680
Changes
mode === "subagent") from defaultAgent candidateshidden === true) from defaultAgent candidatesdefault agent "${cfg.default_agent}" not founddefault agent "${cfg.default_agent}" is a subagentdefault agent "${cfg.default_agent}" is hiddenno primary visible agent foundBreaking Changes
None
Testing