fix: resolve agent by name fallback and guard undefined agent (#13790)#13821
Closed
echoVic wants to merge 1 commit into
Closed
fix: resolve agent by name fallback and guard undefined agent (#13790)#13821echoVic wants to merge 1 commit into
echoVic wants to merge 1 commit into
Conversation
…gents (anomalyco#13790) Root cause: Agent.defaultAgent() returned agent.name (display name) instead of the state map key. When a custom agent sets a different name (e.g., name: 'Build (guarded)' with config key 'build-guarded'), Agent.get() would receive the display name, find no match in the map, and return undefined — causing TypeError on agent.variant access. Fix: - defaultAgent() now returns the map key (config key) instead of agent.name - Added defensive guard in createUserMessage to throw a clear error if Agent.get() returns undefined
echoVic
force-pushed
the
fix/13790-agent-variant-undefined
branch
from
February 16, 2026 10:01
19e6542 to
ba2fd4c
Compare
Contributor
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
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.
Problem
When a custom primary agent's config key differs from its display name,
Agent.get()fails to find the agent, returningundefined. This causes aTypeError: undefined is not an object (evaluating 'agent.variant')increateUserMessage.Example config:
{ "agent": { "build-guarded": { "name": "Build (guarded)", ... } } }The TUI passes the agent's display name (
Build (guarded)) toAgent.get(), but the state map is keyed by config key (build-guarded), so the lookup returnsundefined.Fix
Agent.get()now falls back to lookup bynamefield when key lookup fails, so agents can be found regardless of whether the caller uses the config key or the display name.createUserMessage()now throws a clear error (Agent "..." not found) instead of crashing with a cryptic TypeError when the agent is not found.Changes
packages/opencode/src/agent/agent.ts: Add name-based fallback inAgent.get()packages/opencode/src/session/prompt.ts: Guard against undefined agent increateUserMessage()Closes #13790