Skip to content

fix(tools): refuse an unserved subagent model up front and report an overridden one - #1940

Merged
edenreich merged 1 commit into
mainfrom
fix/agent-model-precedence
Nov 22, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/agent-model-precedence

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Resolves #1939

Summary

A desktop chat was asked to message the tester agent, whose file pinned model: mock/openai/gpt-4o, a model that only exists in mock mode. The Agent call reported Status: Success, then the subagent failed with opening the subagent's thread: model "mock/openai/gpt-4o" not available. Available: [...], listing about forty gateway models and never mentioning the agent's file. The calling agent retried with an explicit model: anthropic/claude-haiku-5-5, which ran the pinned model again (docs/subagents.md says the file's model wins) but silently. It told the user the retry ran on Haiku, and finally invented a stand-in agent. The precedence rule stays as documented. What changes is that the tool now says what happens. no docs ticket: the CLI docs are updated in this PR

Changes

  • internal/tools/agent.go:
    • The Agent tool lists the served models once per call (ListModels, cached with its TTL) and refuses a task whose resolved model is not among them, before anything is dispatched. For a model an agent file pins, the error names the agent and its file and says a task's model cannot override it, for example agent tester cannot run: its file ~/.infer/agents/tester.md pins model "mock/openai/gpt-4o", which the gateway does not serve.... Any other unserved model suggests the chat's own model. A failed or empty list never blocks a spawn.
    • When an agent file's model replaces an explicit task model, the result carries a note: model "anthropic/claude-haiku-5-5" not used for agent tester - its file pins "mock/openai/gpt-4o", and an agent file's model wins over a task's.
    • resolveModel's comment no longer claims the per-task model always comes first.
  • internal/tools/registry.go: RegistryDeps.Models (convdomain.ModelService) reaches the Agent tool. A nil value skips the check.
  • internal/container/container.go: the model service is built just before the tool registry instead of just after, so the registry can take it. It depends only on the daemon thread and the SDK client, both of which exist by then.
  • docs/subagents.md: the Model section describes the note and the up-front refusal.

Verification

  • New table test TestAgentTool_UnservedModelFailsBeforeDispatch, using the FakeModelService from tests/mocks/conversation. Four cases: a pinned unserved model is refused with the file path and nothing dispatched, an unserved task model suggests the chat's model, a served pinned model runs, and a list error never blocks.
  • New TestAgentTool_NamedAgentModelOverrideIsReported, and the existing TestAgentTool_NamedAgentModelPrecedence still pins "file model beats per-task model".
  • Mutation checks: with the served-model check disabled the table test fails, and with the note removed the override test fails.
  • go test ./...: 129 packages pass. task precommit:run: 0 lint issues.

…overridden one

A chat that messaged an agent whose file pins a model the gateway does
not serve got a dispatched Agent call reporting success, then a
subagent failure listing every gateway model, with nothing saying the
model came from the agent's file. Retrying with an explicit model ran
the pinned model again, as docs/subagents.md documents, but silently.

- The Agent tool lists the served models once per call and refuses a
  task whose model is not among them before anything is dispatched.
  For a model an agent file pins, the error names the file and says a
  task's model cannot override it. An unknown list never blocks a
  spawn.
- When an agent file's model replaces a task's explicit model, the
  tool result says so.
- The container builds the model service before the tool registry and
  hands it to the Agent tool through RegistryDeps.Models.
- resolveModel's comment and docs/subagents.md describe the behavior.

Resolves #1939
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 22, 2026
@edenreich
edenreich marked this pull request as ready for review November 22, 2026 22:31
@edenreich
edenreich requested a review from a team as a code owner November 22, 2026 22:31
@edenreich
edenreich merged commit f177e14 into main Nov 22, 2026
14 checks passed
@edenreich
edenreich deleted the fix/agent-model-precedence branch November 22, 2026 22:31
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.266.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 22, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Agent tool hides that an agent file's model overrides a task's model and reports an unserved one only after dispatch

1 participant