Skip to content

fix(agent): Change 'agent' tool model to be the small model#2365

Open
taoeffect wants to merge 8 commits intocharmbracelet:mainfrom
taoeffect:issue-2358
Open

fix(agent): Change 'agent' tool model to be the small model#2365
taoeffect wants to merge 8 commits intocharmbracelet:mainfrom
taoeffect:issue-2358

Conversation

@taoeffect
Copy link
Copy Markdown
Contributor

@taoeffect taoeffect commented Mar 5, 2026

I don't know if it is intentional that the agent tool uses the large task model but to me this was a surprise. I assumed it used the small task model, and to me this seems to make more sense and gives a way to save on cost while also improving speed/performance. In the case that you agree the agent tool should use the small task model I offer this PR as a fix for #2358.

As an alternative I could work on a PR that offers the user a menu setting to allow the user to select which model the agent tool uses.

Closes #2358

NOTE: code written by Opus 4.6 under my supervision.

The `buildAgent()` function always passed the large model to sub-agents,
ignoring the `Agent.Model` config field entirely. This meant the `agent`
tool sub-agent would use the large model (e.g. Opus) even when the user
had configured a different small task model (e.g. Gemini Flash), causing
the sub-agent to incorrectly identify as the large model's identity.

Now `buildAgent()` selects the primary model based on `agent.Model`,
and `AgentTask` defaults to `SelectedModelTypeSmall` so the task
sub-agent uses the user's configured small model for inference, system
prompt construction, and provider prefix resolution.

Assisted-by: Crush
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 PR updates the default model used by the agent tool’s “Task” sub-agent to prefer the configured small model (to reduce cost/latency) and adjusts agent construction so the agent’s configured model selection is respected.

Changes:

  • Switch the default Task agent in Config.SetupAgents() to use SelectedModelTypeSmall.
  • Update coordinator.buildAgent() to select the primary model based on agent.Model when constructing a SessionAgent.
  • Update prompt.Build(...) and SystemPromptPrefix selection to use the chosen primary model/provider.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/config/config.go Changes the default Task agent model from large to small.
internal/agent/coordinator.go Makes buildAgent() respect the agent’s configured model when selecting the primary model and building prompts/prefixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/agent/coordinator.go Outdated
Comment thread internal/agent/coordinator.go
…ildAgent

Address two issues from Copilot PR review:

1. Convert SessionAgentOptions initialization from positional to keyed
   struct literal for readability and resilience to field reordering.

2. Always pass the real large model as LargeModel so that generateTitle's
   small→large fallback remains functional when the sub-agent is
   configured to use the small model for primary execution.

Assisted-by: Opus 4.6 via Crush <crush@charm.land>
The Copilot review fix (251dc5a) regressed issue charmbracelet#2358 by always passing
the real `large` model as `LargeModel` to `NewSessionAgent`. Since `Run()`
dispatches inference via `a.largeModel`, the sub-agent always used the large
model regardless of `agent.Model`.

Fix: pass `primary` (which resolves to `small` when
`agent.Model == SelectedModelTypeSmall`) as `LargeModel`, matching the
pattern already used by `agentic_fetch_tool.go`.

Assisted-by: Claude via Crush <crush@charm.land>
@taoeffect
Copy link
Copy Markdown
Contributor Author

The CLA Assistant failed because of some network error - note I did sign the CLA in a separate PR.

@taoeffect taoeffect changed the title fix(2358): Change 'agent' tool model to be the small model fix(agent): Change 'agent' tool model to be the small model Mar 6, 2026
@meowgorithm
Copy link
Copy Markdown
Member

Thanks for the PR, @taoeffect. This may need to be something that's configurable, but maybe we should try this PR our first and evaluate the results (with a few of the normal big-small model combinations).

P.S. I much appreciate the NOTE portion—thanks!

Reconcile the buildAgent() conflict between the issue-2358 branch and
main. The branch introduced a `primary` model variable that selects
between large/small based on agent config, while main refactored
ConfigStore access to use .Config() and added new SessionAgentOptions
fields (SystemPrompt, Tools, Notify). The resolution preserves both:
the primary model selection logic and main's updated API surface.
@taoeffect
Copy link
Copy Markdown
Contributor Author

Note: one test is failing after merging main because it's failing on main too.

taoeffect added a commit to taoeffect/crush that referenced this pull request Mar 19, 2026
…tool

Merge the agent model selection feature (PR charmbracelet#2365) with the LLM-driven
compaction feature (PR charmbracelet#2333). The two branches independently modified
`buildAgent()` in coordinator.go:

- issue-2358 introduced per-agent model selection via a `primary` variable
  that picks the large or small model based on each agent's config, allowing
  the `agent` tool to default to the small (cheaper/faster) model.

- new_session_tool added compaction flag derivation via `compactionFlags()`,
  which reads the configured `CompactionMethod` to control auto-summarize
  and context-status behavior for LLM-driven compaction.

The resolution combines both: the primary model is selected per agent config,
its provider config is used for the system prompt prefix, and the compaction
flags are derived from the compaction method — preserving the full intent of
both branches.

Also retains `.tldr/` and `.tldrignore` gitignore entries from
new_session_tool that were absent in issue-2358.
taoeffect added a commit to taoeffect/crush that referenced this pull request Mar 19, 2026
Merge changes from taoeffect2 which includes:

- feat: LLM and user-controlled compaction via `new_session` tool (charmbracelet#2333)
  Adds a `new_session` tool for customizable compaction, a compaction
  method switching menu in the UI, and context status injection into the
  system prompt when using LLM/user-driven compaction.

- fix(agent): change agent tool model to use the small model (charmbracelet#2365)
  Switches the `agent` tool from the large task model to the small task
  model for cost savings and improved speed.

Additionally merges Docker MCP support (enable/disable toggle in the
commands menu, config persistence, and MCP client lifecycle management),
session continuation on startup via --continue/--session flags, and
RefreshTools on the Coordinator interface.

Conflicts resolved (preferring taoeffect2):
- internal/agent/coordinator.go: removed extra blank line before
  NewSessionAgent (cosmetic only)
- internal/ui/model/ui.go: removed redundant cfg nil-check in
  compaction dialog handler, now uses m.com.Store() directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agent tool uses large task model [Was: Why does Gemini think it's Claude?]

4 participants