Skip to content

feat(agent): measure each local model on its first run and warn when unproven - #565

Merged
dovvnloading merged 4 commits into
mainfrom
feat/agent-profile-models-on-first-use
Nov 22, 2026
Merged

dovvnloading merged 4 commits into
mainfrom
feat/agent-profile-models-on-first-use

Conversation

@dovvnloading

Copy link
Copy Markdown
Owner

Problem

Nothing in the product called the capability probe (agent/model_profiles.probe_model), and nothing wrote the profile store. So every Agent run, for every model, used the weakest wire format, plain_json (prompt-only JSON, with no native tool calls or constrained decoding).

In a live test, none of the local models tried could follow it. qwen3:8b and granite4.1:8b failed with invalid_model_replies after inventing envelope fields. With a measured native_tools profile, the same granite model made valid tool calls and fixed the bug.

Decision (maintainer)

Measure a model on first use and cache the result. Run on the format it was measured on, even when it is not recommended, and show a visible warning. Approvals still gate every action.

Change

Backend (services/agent_runs.py, agent/model_profiles.py)

  • New AgentRuns(profile_models=...) switch. It is off by default (tests and embedded apps), and app_factory.build_app turns it on through a new create_app(agent_profile_models=...) argument.
  • When a local model has no saved profile, the worker probes it before the run's first model call. The run stays pending and emits status {status: "pending", phase: "model_check"}. The probe uses DEFAULT_PROBE_CONTEXT_SIZE, so budgets and num_ctx match the defaults the loop was built with, and only the wire format changes.
  • The run uses the measured format whenever the model passed single_call on it. Otherwise it keeps plain_json. Recommendation now only decides the warning.
  • The running status event carries model_check: {recommended, failed_checks} for both cached and newly measured profiles.
  • The result is saved with the new ProfileStore.upsert, which replaces only that model's record. Guards:
    • Unreadable store: an unreadable or unsupported store is neither trusted nor overwritten.
    • All checks failed: that probe is not cached (a stopped runtime looks the same), so the next run measures again.
    • Cloud models: never probed.
    • Stop: honoured between checks through probe_model(should_stop=...), which raises ProbeStopped. Nothing is saved.

Frontend

  • useAgentRun exposes checkingModel and modelCheck. A model is never shown as recommended when a failed check is listed.
  • During the probe, the run panel shows "Checking how this model uses tools".
  • An unrecommended model gets a warning alert that names the failed checks in plain words. The injection check adds a line saying the model may follow instructions hidden in project files.

Tests

  • test_agent_runs_wiring.py:
    • probed once, then cached, on native_tools;
    • unrecommended model runs on its measured format, with the warning event and a saved profile;
    • all-failed probe is not cached and is measured again;
    • profiling off, cloud models and unreadable stores never probe, and the store bytes are unchanged;
    • Stop during the probe ends it after the first check and saves nothing.
  • test_agent_model_profiles.py: should_stop before and between checks, upsert replaces only one model, upsert never overwrites an unreadable store.
  • test_app_paths.py: the launched app turns profiling on, and a plain AgentRuns() keeps it off.
  • UI:
    • useAgentRun: the checking state, then the result, with malformed results ignored and failures never shown as recommended;
    • AgentPage: the probe heading, then the warning, and no warning for a recommended model;
    • modelCheck: the warning text.
  • Focused: the agent wiring, profiles, routes and app-paths tests pass. vitest src/features/agent (112 passed). ruff is clean, and mypy is clean over 145 files.

Risk and rollback

The first run with each local model takes longer, while seven short synthetic exchanges run, and the UI says so. Probe content is synthetic, and only check outcomes are stored, never transcripts. Rollback is reverting this commit. Saved profiles then go back to being used only when recommended.

Limits

  • Profiles are keyed by model name, so a model re-pulled under the same tag keeps its old profile. There is no "check again" control yet.
  • The warning is shown for live runs. It is not stored with the run, so it doesn't appear for runs reopened after a restart.

🤖 Generated with Claude Code

dovvnloading and others added 4 commits November 21, 2026 22:00
…unproven

Nothing in the product called the capability probe, so every Agent run
used the prompt-only plain_json format, which none of the local models
tried in a live test could follow.

The launched app now probes a local model that has no saved profile on
the worker, before its first run, and caches the result. A run uses the
wire format the model was measured on whenever it managed a basic tool
call there; a model that failed a check still runs, and the run panel
warns, naming the failed checks in plain language. Approvals still gate
every action. Cloud models are never probed, an unreadable profile
store is neither trusted nor overwritten, a probe in which every check
failed is not cached, and Stop is honoured between checks. Test apps
keep profiling off unless they ask for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dovvnloading
dovvnloading merged commit 8cbb689 into main Nov 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant