Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(cli): vibe agent run can start a new Session on a chosen model (#2723)

Call White22344035c49d
diff --git a/core/prompts/harness-agents.md b/core/prompts/harness-agents.md
index 9e1b4198a..6b2dcc8dd 100644
--- a/core/prompts/harness-agents.md
+++ b/core/prompts/harness-agents.md
@@ -12,7 +12,7 @@ Rules:
- `--fork-session <id>` creates a new Agent Session from that explicit source Session's native backend context.
- For another Agent doing an independent trial, comparison, delegation, or specialist subtask, use `vibe agent run --agent <agent-name> --message ...`.
- Use `vibe agent run --agent <agent-name> --session-id ... --message ...` only when the work should continue that same existing Session. Async callbacks return to this conversation by default.
-- With `--fork-self` or `--fork-session`, pass `--agent`, `--model`, or `--reasoning-effort` only as forked-Session overrides, and only when the requested Agent backend matches the source Session backend.
+- `--model` and `--reasoning-effort` set the model of the new Session a run creates (a blank new Session, `--create-session`, or a fork), and that Session keeps it; they are not valid with `--session-id`. With `--fork-self` or `--fork-session`, `--agent`, `--model`, and `--reasoning-effort` override the forked Session only when the requested Agent backend matches the source Session backend.
- `--sync` changes waiting behavior, not session identity: default async runs in the background and return through callbacks; synchronous runs wait for the result and are still recorded in `vibe runs`.
- Create or update Agents only when it captures a reusable role, reduces repeated prompting, or makes a long-running Harness more reliable.
diff --git a/docs/CLI.md b/docs/CLI.md
index 688f9a51f..10ec018f8 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -504,6 +504,16 @@ Session keeps the source backend. `--agent`, `--model`, and
stays the same; a cross-backend fork is rejected. Do not combine
`--fork-session` with `--session-id` or `--create-session`.
+`--model` and `--reasoning-effort` set the model of any new Session the run
+creates (a blank new Session, `--create-session`, or a fork), and the Session
+keeps it for its later turns. They are refused with `--session-id`; an existing
+Session's model is changed in the Web UI's Session model picker. The pair the
+new Session will run on (each override over the default it would otherwise
+keep) is checked against the Agent's catalog. A Vibey model or effort its Model
+Hub menu does not offer, or a menu that cannot be loaded, is refused; for claude
+and codex an unknown value is a warning, since their bundled catalogs can lag
+behind a new release. `vibe agent models <agent>` lists valid values.
+
Async runs need an explicit callback policy unless the command is running inside
an Avibe-injected Agent environment. Use `--callback-session-id` when the final
result text should return to a caller Session as a follow-up Agent message; use
diff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.md
index 2cdfab59e..37b0594d9 100644
--- a/docs/CLI_ZH.md
+++ b/docs/CLI_ZH.md
@@ -400,6 +400,14 @@ P1 操作,只提升现有的精确 FIFO 队头,不新增消息。过期队
覆盖 fork 后 Session 的 Agent、模型或推理强度;跨 backend fork 会被拒绝。
不要把 `--fork-session` 和 `--session-id` 或 `--create-session` 混用。
+`--model` 和 `--reasoning-effort` 可以为这次运行创建的任何新 Session(空白新
+Session、`--create-session` 或 fork)设置模型,该 Session 之后的轮次会沿用它。
+它们不能与 `--session-id` 一起使用;已有 Session 的模型在 Web UI 的 Session 模型
+选择器中修改。新 Session 实际运行的组合(覆盖值加上它原本沿用的默认值)会按 Agent
+的模型目录检查:Vibey 的 Model Hub 菜单不提供的模型或推理强度,或菜单无法加载时,
+会被拒绝;claude 和 codex 的未知值只给出警告,因为它们内置的目录可能落后于新版本。
+`vibe agent models <agent>` 会列出可用的值。
+
异步 run 需要明确 callback 策略,除非命令运行在 Avibe 已注入 caller context
的 Agent 环境内。当最终结果文本需要回到调用方 Session 时,使用
`--callback-session-id`;当你有意不自动回调、后续会通过 `vibe runs show`
diff --git a/docs/COMMANDS.md b/docs/COMMANDS.md
index 4073d69ef..ab80f1e72 100644
--- a/docs/COMMANDS.md
+++ b/docs/COMMANDS.md
@@ -983,6 +983,15 @@ Session. Forks keep the same backend as the source; `--agent`, `--model`, and
not change. Do not combine `--fork-session` with `--session-id` or
`--create-session`.
+`--model` and `--reasoning-effort` set the model of any new Session the run
+creates (a blank new Session, `--create-session`, or a fork); the Session keeps
+it. They are refused with `--session-id` (`model_override_with_existing_session`).
+The pair the new Session will run on (each override over the default it would
+otherwise keep) is checked: a Vibey model or effort its Model Hub menu does not
+offer, or a menu that cannot be loaded, is refused (`session_model_unavailable`);
+for claude and codex an unknown value is a warning. `vibe agent models <agent>`
+lists valid values.
+
## 5.4 `vibe runs`
`vibe runs` inspects concrete Agent Run records produced by tasks, watches, or
diff --git a/docs/COMMANDS_ZH.md b/docs/COMMANDS_ZH.md
index d3d306116..09e1dbc4c 100644
--- a/docs/COMMANDS_ZH.md
+++ b/docs/COMMANDS_ZH.md
@@ -911,6 +911,13 @@ fork 会保持源 Session 的 backend;只有 backend 不变时,`--agent`、`
和 `--reasoning-effort` 才能覆盖 fork 后 Session 的 Agent、模型或推理强度。
不要把 `--fork-session` 和 `--session-id` 或 `--create-session` 混用。
+`--model` 和 `--reasoning-effort` 可以为这次运行创建的任何新 Session(空白新
+Session、`--create-session` 或 fork)设置模型,该 Session 会沿用它。与
+`--session-id` 一起使用会被拒绝(`model_override_with_existing_session`)。新 Session
+实际运行的组合(覆盖值加上它原本沿用的默认值)会被检查:Vibey 的 Model Hub 菜单不提供
+的模型或推理强度,或菜单无法加载时,会被拒绝(`session_model_unavailable`);claude
+和 codex 的未知值只给出警告。`vibe agent models <agent>` 会列出可用的值。
+
## 5.4 `vibe runs`
`vibe runs` 用来查看由 task、watch 或直接 Agent Run 产生的一次次实际执行记录。
diff --git a/skills/use-avibe-harness/SKILL.md b/skills/use-avibe-harness/SKILL.md
index ece957dc3..dc04e7a5b 100644
--- a/skills/use-avibe-harness/SKILL.md
+++ b/skills/use-avibe-harness/SKILL.md
@@ -63,6 +63,8 @@ Use `vibe agent run --agent <agent-name> --message ...` when one Agent delegates
Use `vibe agent run --fork-self --message ...` when work should branch from this current Session's native backend context without mutating it. Use `--fork-session <source-session-id>` only when branching from a different explicit Session. Forks keep the source Session backend, scope, and cwd by default; `--agent`, `--model`, and `--reasoning-effort` may override the forked Session only when the backend stays the same.
+Any run that creates a new Session (a blank new Session from `--agent`, `--create-session`, or a fork) may set that Session's model with `--model` and `--reasoning-effort`; the Session keeps it for its later turns. A Vibey model or effort its Model Hub menu does not offer is refused; for claude and codex an unknown value is a warning. `vibe agent models <agent>` lists valid values.
+
When `vibe agent run --session-id <id>` targets an existing Session, it sends a new message into that Session. It does not change that Session's cwd, scope, Agent, model, or reasoning settings; those properties belong to the Session itself. Use a new Session or a fork when those properties need to differ.
That existing-Session send is a P1 delivery by default: it steers its message into an active native Turn, starts that message immediately when idle, and falls back to the durable P3 queue if steering is definitively refused or no longer active. Use `--queue` when the new Run should enter that P3 queue without steering. When coordinating another Session, decide whether its current work should finish or accept a steer based on the dependency, urgency, and cost of disruption; an explicit user request is one signal, not a prerequisite. `vibe agent run --session-id <id> --send-now --message ...` explicitly selects that same content-bearing P1 behavior; it does not promote an older queued message. Use `vibe session send-now <id>` only when no new Message should be added: this content-free P1 promotes the exact existing FIFO head. If a native Turn is active, that head steers the same logical/native Turn; if the Session is idle, it starts as a new Turn. Both commands work for Workbench and IM Sessions. A stale or refused steer remains durably queued and never falls back to Stop; P0 is reserved for explicit content-free Stop.
@@ -89,7 +91,7 @@ Rules:
- `--fork-session <id>` creates a new Agent Session from that explicit source Session's native backend context.
- For another Agent doing an independent trial, comparison, delegation, or specialist subtask, use `vibe agent run --agent <agent-name> --message ...`.
- Use `vibe agent run --agent <agent-name> --session-id ... --message ...` only when the work should continue that same existing Session. Async callbacks return to this conversation by default.
-- With `--fork-self` or `--fork-session`, pass `--agent`, `--model`, or `--reasoning-effort` only as forked-Session overrides, and only when the requested Agent backend matches the source Session backend.
+- `--model` and `--reasoning-effort` apply to the new Session a run creates and are refused with `--session-id`. With `--fork-self` or `--fork-session`, `--agent`, `--model`, and `--reasoning-effort` override the forked Session only when the requested Agent backend matches the source Session backend.
- `--sync` changes waiting behavior, not session identity: default async runs in the background and return through callbacks; synchronous runs wait for the result and are still recorded in `vibe runs`.
- Create or update Agents only when it captures a reusable role, reduces repeated prompting, or makes a long-running Harness more reliable.
diff --git a/skills/use-avibe/references/harness.md b/skills/use-avibe/references/harness.md
index 71aaed7f2..99b9158ed 100644
--- a/skills/use-avibe/references/harness.md
+++ b/skills/use-avibe/references/harness.md
@@ -50,7 +50,7 @@ Targeting and callbacks:
- `vibe task add` stores a message template — or, with `--shell` / a trailing `-- <argv>`, a command — and creates Runs when the time trigger fires. A command task runs with no Agent turn: silent on success, a failure notice on failure, `--on-failure agent` to escalate failures to an Agent.
- `vibe watch add` uses `--message` as the instruction template for the Agent Run created after the waiter reaches a reportable state.
- `--fork-self` forks this Session's native backend context. `--fork-session <id>` forks another explicit Session. Forks keep the source Session backend, scope, and cwd by default.
-- Fork overrides are intentionally narrow: `--agent`, `--model`, and `--reasoning-effort` can override the forked Session only if the backend stays the same. Do not combine fork flags with existing-session or session-creation flags.
+- `--model` and `--reasoning-effort` set the model of any new Session a run creates (blank, `--create-session`, or a fork); the Session keeps it, and they are refused with `--session-id`. Fork overrides stay narrow: `--agent`, `--model`, and `--reasoning-effort` can override the forked Session only if the backend stays the same. Do not combine fork flags with existing-session or session-creation flags.
Operational guidance:
diff --git a/tests/test_cli_task_command.py b/tests/test_cli_task_command.py
index 346152321..c6bbc0cad 100644
--- a/tests/test_cli_task_command.py
+++ b/tests/test_cli_task_command.py
@@ -5561,3 +5561,175 @@ def test_task_resume_rejects_orphaned_owner_without_execution_target(
"owner_session_id": "ses-removed",
}
assert cli.ScheduledTaskStore().get_task(task.id).enabled is False
+
+
+# The target Agent's model catalog (``api.agent_model_options``): Vibey's is its Model Hub menu, authoritative; codex's
+# is bundled and may lag behind a new release.
+_CATALOGS = {
+ "vibey": {
+ "ok": True,
+ "source": "model_hub",
+ "models": [{"value": "claude-opus-5-5", "reasoning_efforts": ["high", "xhigh"]}, {"value": "gpt-6-astra", "reasoning_efforts": []}],
+ },
+ "codex": {
+ "ok": True,
+ "source": "bundled",
+ "models": [{"value": "gpt-6-codex", "reasoning_efforts": ["medium", "xhigh"]}],
+ },
+}
+
+
+def _run_on_new_session(tmp_path: Path, capsys, db_path: Path, agent_store, request_store, argv: list[str]):
+ with (
+ patch("vibe.cli._agent_store", return_value=agent_store),
+ patch("vibe.cli._task_request_store", return_value=request_store),
+ patch("vibe.cli.paths.get_sqlite_state_path", return_value=db_path),
+ patch("vibe.cli.api.agent_model_options", side_effect=lambda backend, **_: _CATALOGS[backend]),
+ patch(
+ "storage.sessions_service.paths.get_show_page_dir",
+ side_effect=lambda session_id: tmp_path / "show" / session_id,
+ ),
+ ):
+ result = cli.cmd_agent_run(_parse_agent_run(["--async", "--no-callback", *argv]))
+ captured = capsys.readouterr()
+ return result, json.loads(captured.out if result == 0 else captured.err)
+
+
+ ("backend", "model", "effort", "warned"),
+ [("vibey", "claude-opus-5-5", "xhigh", False), ("codex", "gpt-6-codex-next", "xhigh", True)],
+ ids=["vibey", "codex-model-newer-than-its-catalog"],
+)
+def test_agent_run_starts_a_new_session_on_a_chosen_model_that_its_later_turns_keep(
+ tmp_path: Path, capsys, sqlite_schema_db_factory, backend, model, effort, warned
+) -> None:
+ """A run that creates a Session may choose its model and effort: they are kept on the Session, whose row every turn
+ of it is dispatched with (``resolve_session_id_target``), so a later run into it needs no flags. A codex model its
+ bundled catalog does not list yet is kept with a warning, as `vibe agent create` gives."""
+ db_path = sqlite_schema_db_factory(tmp_path / "state" / "vibe.sqlite")
+ agent_store = cli.VibeAgentStore(db_path)
+ agent_store.create(name="worker", backend=backend)
+ request_store = cli.TaskExecutionStore(tmp_path / "task_requests")
+
+ result, payload = _run_on_new_session(
+ tmp_path, capsys, db_path, agent_store, request_store,
+ ["--agent", "worker", "--model", model, "--reasoning-effort", effort, "--message", "first"],
+ )
+
+ assert result == 0, payload
+ session_id = payload["session_id"]
+ assert bool(payload.get("warnings")) is warned
+ queued = json.loads((request_store.pending_dir / f"{payload['run_id']}.json").read_text())
+ assert (queued["model"], queued["reasoning_effort"]) == (model, effort)
+ with sqlite3.connect(db_path) as conn:
+ row = conn.execute("select model, reasoning_effort from agent_sessions where id = ?", (session_id,)).fetchone()
+ assert row == (model, effort)
+
+ # The second turn: a run into the Session, with no flags, is dispatched on the model the Session keeps.
+ result, payload = _run_on_new_session(
+ tmp_path, capsys, db_path, agent_store, request_store, ["--session-id", session_id, "--message", "second"]
+ )
+ assert result == 0, payload
+ with patch("core.scheduled_tasks.paths.get_sqlite_state_path", return_value=db_path):
+ target = cli.resolve_session_id_target(session_id)
+ assert (target.model, target.reasoning_effort) == (model, effort)
+
+
+ ("defaults", "extra", "catalog", "language", "message"),
+ [
+ ({}, ["--model", "claude-opus-9"], None, "en", "model 'claude-opus-9' is not in the vibey model catalog"),
+ (
+ {},
+ ["--model", "claude-opus-5-5", "--reasoning-effort", "medium"],
+ None,
+ "en",
+ "reasoning_effort 'medium' is not valid for model 'claude-opus-5-5'",
+ ),
+ # A model the menu lists with no efforts takes none.
+ ({}, ["--model", "gpt-6-astra", "--reasoning-effort", "high"], None, "en",
+ "reasoning_effort 'high' is not valid for model 'gpt-6-astra'"),
+ # The pair the Session would run on: an effort override over the Agent's default model...
+ ({"model": "claude-opus-5-5"}, ["--reasoning-effort", "medium"], None, "en",
+ "reasoning_effort 'medium' is not valid for model 'claude-opus-5-5'"),
+ # ...and a model override over the Agent's default effort.
+ ({"model": "claude-opus-5-5", "reasoning_effort": "xhigh"}, ["--model", "gpt-6-astra"], None, "en",
+ "reasoning_effort 'xhigh' is not valid for model 'gpt-6-astra'"),
+ # A menu that cannot be loaded vouches for nothing.
+ ({}, ["--model", "claude-opus-5-5"], {"ok": False, "error": "config_unavailable"}, "en",
+ "the vibey model catalog could not be loaded, so the model and reasoning effort cannot be checked"),
+ ({}, ["--model", "claude-opus-9"], None, "zh", "模型 'claude-opus-9' 不在 vibey 的模型目录中"),
+ ],
+ ids=["unknown-model", "effort-the-model-does-not-take", "effort-on-a-model-that-takes-none",
+ "effort-over-the-agents-model", "model-over-the-agents-effort", "menu-unavailable", "zh"],
+)
+def test_agent_run_refuses_a_vibey_model_its_menu_does_not_offer_and_keeps_no_session(
+ tmp_path: Path, capsys, sqlite_schema_db_factory, defaults, extra, catalog, language, message
+) -> None:
+ """The effective pair a new Vibey Session would run on (each override over the Agent's default) is checked against
+ the Model Hub menu, which is authoritative: a pair it does not offer, or a menu that cannot load, is refused in the
+ caller's language with the catalog hint; the reserved Session is released and no run is queued."""
+ db_path = sqlite_schema_db_factory(tmp_path / "state" / "vibe.sqlite")
+ agent_store = cli.VibeAgentStore(db_path)
+ agent_store.create(name="worker", backend="vibey", **defaults)
+ request_store = cli.TaskExecutionStore(tmp_path / "task_requests")
+
+ with (
+ patch("vibe.cli._configured_cli_language", return_value=language),
+ patch.dict(_CATALOGS, {"vibey": catalog} if catalog is not None else {}),
+ ):
+ result, payload = _run_on_new_session(
+ tmp_path, capsys, db_path, agent_store, request_store, ["--agent", "worker", *extra, "--message", "hi"]
+ )
+
+ assert result == 1
+ assert (payload["code"], payload["error"]) == ("session_model_unavailable", message)
+ assert payload["hint"] == cli.i18n_t("harness.cli.agentRunModel.catalogHint", language, agent="worker")
+ with sqlite3.connect(db_path) as conn:
+ assert conn.execute("select count(*) from agent_sessions").fetchone() == (0,)
+ assert not list(request_store.pending_dir.glob("*.json"))
+
+
[email protected](("forkable", "code"), [(True, "session_model_unavailable"), (False, "session_fork_failed")])
+def test_agent_run_refuses_a_fork_onto_a_vibey_model_its_menu_does_not_offer(
+ tmp_path: Path, capsys, sqlite_schema_db_factory, forkable, code
+) -> None:
+ """A fork's override is checked by the same rule as a new Session's, against the source Session's Agent, but only
+ once the fork service has admitted the caller to the source: a source it refuses answers with the fork's own
+ refusal, never a catalog one that would tell what the source runs on. The fork it reserved is released."""
+ db_path = sqlite_schema_db_factory(tmp_path / "state" / "vibe.sqlite")
+ agent_store = cli.VibeAgentStore(db_path)
+ agent_store.create(name="worker", backend="vibey")
+ request_store = cli.TaskExecutionStore(tmp_path / "task_requests")
+ result, payload = _run_on_new_session(
+ tmp_path, capsys, db_path, agent_store, request_store, ["--agent", "worker", "--message", "source"]
+ )
+ assert result == 0, payload
+ if forkable:
+ # The source has run a turn, so its native Session exists to fork.
+ with sqlite3.connect(db_path) as conn:
+ conn.execute(
+ "update agent_sessions set native_session_id = ? where id = ?",
+ (f"vibey:{payload['session_id']}", payload["session_id"]),
+ )
+
+ with patch("core.scheduled_tasks.paths.get_sqlite_state_path", return_value=db_path):
+ result, payload = _run_on_new_session(
+ tmp_path, capsys, db_path, agent_store, request_store,
+ ["--fork-session", payload["session_id"], "--model", "claude-opus-9", "--message", "branch"],
+ )
+
+ assert result == 1
+ assert payload["code"] == code
+ with sqlite3.connect(db_path) as conn:
+ assert conn.execute("select count(*) from agent_sessions").fetchone() == (1,)
+
+
+def test_agent_run_refuses_a_model_for_an_existing_session_and_says_how_to_change_it(capsys) -> None:
+ args = _parse_agent_run(["--session-id", "ses_existing1", "--model", "claude-opus-5-5", "--message", "hi"])
+
+ result, payload = _capture_stderr_json(cli.cmd_agent_run, args)
+
+ assert result == 1
+ assert payload["code"] == "model_override_with_existing_session"
+ assert "Web UI's Session model picker" in payload["hint"] and "--fork-session" in payload["hint"]
diff --git a/tests/test_prompt_render_export.py b/tests/test_prompt_render_export.py
index 260934b42..6b4940a1a 100644
--- a/tests/test_prompt_render_export.py
+++ b/tests/test_prompt_render_export.py
@@ -43,6 +43,16 @@ _HISTORY_AS_MEMORY_GUIDANCE = (
"and channel, and it is the clearest, most direct, and rawest source of memory. "
"Do not rely on vague impressions or ask the user to repeat themselves."
)
+_PREVIOUS_FORK_OVERRIDE_GUIDANCE = (
+ "- With `--fork-self` or `--fork-session`, pass `--agent`, `--model`, or `--reasoning-effort` only as "
+ "forked-Session overrides, and only when the requested Agent backend matches the source Session backend."
+)
+_NEW_SESSION_MODEL_GUIDANCE = (
+ "- `--model` and `--reasoning-effort` set the model of the new Session a run creates (a blank new Session, "
+ "`--create-session`, or a fork), and that Session keeps it; they are not valid with `--session-id`. With "
+ "`--fork-self` or `--fork-session`, `--agent`, `--model`, and `--reasoning-effort` override the forked Session "
+ "only when the requested Agent backend matches the source Session backend."
+)
_PREVIOUS_FOLLOW_THROUGH_PRINCIPLE = (
"- **Follow through.** Maintain ongoing responsibility for entrusted work rather than forgetting it "
"when a turn ends. When repeatedly blocked, revisit assumptions and root causes; when necessary, "
@@ -533,6 +543,8 @@ def test_approved_guidance_changes_preserve_all_other_injection_bytes(monkeypatc
assert text.count(_EVIDENCE_LED_PRINCIPLE) == 1
assert text.count(_HISTORY_AS_MEMORY_GUIDANCE) == 1
assert text.count(_FOLLOW_THROUGH_PRINCIPLE) == 1
+ assert text.count(_NEW_SESSION_MODEL_GUIDANCE) == 1
+ text = text.replace(_NEW_SESSION_MODEL_GUIDANCE, _PREVIOUS_FORK_OVERRIDE_GUIDANCE)
text = text.replace(_HISTORY_AS_MEMORY_GUIDANCE, _PREVIOUS_HISTORY_GUIDANCE)
text = text.replace(_FOLLOW_THROUGH_PRINCIPLE, _PREVIOUS_FOLLOW_THROUGH_PRINCIPLE)
outputs.append(text.replace(_EVIDENCE_LED_PRINCIPLE, _PREVIOUS_VERIFICATION_PRINCIPLE))
@@ -541,6 +553,7 @@ def test_approved_guidance_changes_preserve_all_other_injection_bytes(monkeypatc
# omitting only the approved quick-reply, Computer Use and Skill-loading
# guidance blocks (including the Codex-only reuse sentence) and restoring the
# previous verification principle and conversation-history guidance and
- # Follow-through principle.
+ # Follow-through principle, and the Harness rule that a run's --model applies
+ # only to forks (now: to any new Session a run creates).
# Every other byte/order stays pinned, including all Claude/OpenCode output.
assert digest == "9475df69a6c14f6ddda396dc33d665f4ebda657517cd3ea3134d23d7f5c5c712"
diff --git a/vibe/cli.py b/vibe/cli.py
index a41a0a6aa..ef39ae577 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -35,7 +35,7 @@ from sqlalchemy import select
from config import paths
from config.atomic_io import write_atomic
from config.v2_config import V2Config
-from modules.agents.catalog import AGENT_BACKENDS, NATIVE_CLI_BACKENDS, display_name_for_backend
+from modules.agents.catalog import AGENT_BACKENDS, NATIVE_CLI_BACKENDS, display_name_for_backend, is_native_cli_backend
from core.scheduled_tasks import (
AGENT_RUN_CLOSE_AFTER_METADATA_KEY,
AGENT_RUN_DELIVERY_QUEUE,
@@ -5805,52 +5805,91 @@ def cmd_agent_models(args):
return 1
-def _agent_value_warning_fields(agent) -> dict:
- """Best-effort, non-fatal warnings when an Agent's model/effort is unknown.
+def _catalog_mismatches(
+ backend: str, model: Optional[str], reasoning_effort: Optional[str], *, language: str
+) -> tuple[list[str], bool]:
+ """What the backend's model catalog says against ``model`` and ``reasoning_effort``, and whether it is authoritative.
- Cheap (file-based) check for claude/codex only; OpenCode availability is
- live (needs the OpenCode server) so it is skipped here to keep create/update
- fast — ``vibe agent models`` is the place for the full OpenCode check.
+ The catalog is ``api.agent_model_options``, the one ``vibe agent models`` and the Web picker read. Vibey's is the
+ Model Hub menu, authoritative: a model it does not list cannot run, and an effort its model does not list is never
+ sent, so one it cannot load vouches for nothing and is itself a mismatch. claude and codex catalogs are bundled and
+ may lag behind a new release, so a mismatch is advisory. OpenCode's is live (it needs the OpenCode server), so it
+ is not checked here, keeping the commands fast; ``vibe agent models`` is the place for the full OpenCode check.
"""
- if agent.backend not in ("claude", "codex"):
- return {}
- if not agent.model and not agent.reasoning_effort:
- return {}
+ if backend == "opencode" or (not model and not reasoning_effort):
+ return [], False
+ words = "harness.cli.agentRunModel"
+ authoritative = not is_native_cli_backend(backend)
try:
- options = api.agent_model_options(agent.backend)
+ options = api.agent_model_options(backend)
except Exception:
- return {}
+ options = {}
if not options.get("ok"):
- return {}
+ return ([i18n_t(f"{words}.catalogUnavailable", language, backend=backend)] if authoritative else []), authoritative
by_value = {entry.get("value"): entry for entry in options.get("models") or []}
- model_unknown = bool(agent.model) and agent.model not in by_value
- warnings: list[str] = []
+ model_unknown = bool(model) and model not in by_value
+ mismatches: list[str] = []
if model_unknown:
- warnings.append(
- f"model '{agent.model}' is not in the known {agent.backend} model list; "
- "it may be a typo or newer than the catalog"
- )
- if agent.reasoning_effort:
- if agent.model and not model_unknown:
- allowed = set(by_value[agent.model].get("reasoning_efforts") or [])
- scope = f"model '{agent.model}'"
+ key = "modelNotInCatalog" if authoritative else "modelMaybeNewer"
+ mismatches.append(i18n_t(f"{words}.{key}", language, model=model, backend=backend))
+ if reasoning_effort:
+ if model and not model_unknown:
+ allowed = set(by_value[model].get("reasoning_efforts") or [])
+ # An authoritative model that lists no efforts takes none.
+ constrained = bool(allowed) or authoritative
+ message = i18n_t(f"{words}.effortInvalidForModel", language, effort=reasoning_effort, model=model)
else:
# model unset or unknown: accept any effort valid for some model of this backend
# (Codex efforts are backend-wide; Claude's widest set still lives in some model)
allowed = set()
for entry in by_value.values():
allowed.update(entry.get("reasoning_efforts") or [])
- scope = f"backend '{agent.backend}'"
- if allowed and agent.reasoning_effort not in allowed:
- warnings.append(f"reasoning_effort '{agent.reasoning_effort}' is not valid for {scope}")
+ constrained = bool(allowed)
+ message = i18n_t(f"{words}.effortInvalidForBackend", language, effort=reasoning_effort, backend=backend)
+ if constrained and reasoning_effort not in allowed:
+ mismatches.append(message)
+ return mismatches, authoritative
+
+
+def _agent_value_warning_fields(agent) -> dict:
+ """Best-effort, non-fatal warnings when an Agent's model/effort is unknown (``_catalog_mismatches``)."""
+ if agent.backend not in ("claude", "codex"):
+ return {}
+ language = _configured_cli_language()
+ warnings, _ = _catalog_mismatches(agent.backend, agent.model, agent.reasoning_effort, language=language)
if not warnings:
return {}
return {
"warnings": warnings,
- "hint": f"Run `vibe agent models {agent.name}` to list valid models and reasoning efforts.",
+ "hint": i18n_t("harness.cli.agentRunModel.catalogHint", language, agent=agent.name),
}
+def _session_model_override_fields(
+ *, backend: str, agent_label: str, model: Optional[str], reasoning_effort: Optional[str], help_command: str
+) -> dict:
+ """Check the model and effort a new Session will run on against the target Agent's catalog.
+
+ ``model`` and ``reasoning_effort`` are the effective pair: the run's overrides over the defaults the Session would
+ otherwise keep. Where the catalog is authoritative (Vibey's Model Hub menu), a pair it does not offer is refused
+ and its reservation released; elsewhere a mismatch is a warning on the run, as ``vibe agent create/update`` gives.
+ """
+ language = _configured_cli_language()
+ mismatches, authoritative = _catalog_mismatches(backend, model, reasoning_effort, language=language)
+ if not mismatches:
+ return {}
+ hint = i18n_t("harness.cli.agentRunModel.catalogHint", language, agent=agent_label)
+ if authoritative:
+ raise TaskCliError(
+ mismatches[0],
+ code="session_model_unavailable",
+ hint=hint,
+ help_command=help_command,
+ details={"backend": backend, "model": model, "reasoning_effort": reasoning_effort},
+ )
+ return {"warnings": mismatches, "hint": hint}
+
+
def cmd_agent_create(args):
try:
system_prompt = args.system_prompt
@@ -6133,14 +6172,15 @@ def _validate_run_session_policy(args, *, help_command: str) -> str:
hint="Fork creates a new Session from the source Session.",
help_command=help_command,
)
- if not (fork_session or fork_self) and (
+ if session_id and (
(getattr(args, "model", None) or "").strip()
or (getattr(args, "reasoning_effort", None) or "").strip()
):
+ language = _configured_cli_language()
raise TaskCliError(
- "--model and --reasoning-effort are only valid with forked Sessions",
- code="fork_override_without_fork",
- hint="Use --agent, --model, and --reasoning-effort as overrides when forking a Session.",
+ i18n_t("harness.cli.agentRunModel.existingSession", language),
+ code="model_override_with_existing_session",
+ hint=i18n_t("harness.cli.agentRunModel.existingSessionHint", language),
help_command=help_command,
)
if session_id and (same_scope or scope_id):
@@ -6763,7 +6803,10 @@ def _reserve_cli_session(
session_anchor_target=None,
visibility: str = "background",
authorization_context=None,
+ model: Optional[str] = None,
+ reasoning_effort: Optional[str] = None,
) -> str:
+ """Reserve a new Agent Session; ``model`` and ``reasoning_effort`` override the Agent's defaults for it."""
# Route through ``core.services.sessions`` so the CLI shares the same
# business API as the UI server and the future N3 internal endpoint;
# see docs/plans/workbench-dispatch-architecture.md §6 (C2).
@@ -6779,8 +6822,8 @@ def _reserve_cli_session(
session_anchor=session_anchor,
agent_id=agent.id,
agent_name=agent.name,
- model=agent.model,
- reasoning_effort=agent.reasoning_effort,
+ model=model or agent.model,
+ reasoning_effort=reasoning_effort or agent.reasoning_effort,
workdir=workdir,
visibility=visibility,
metadata={"scope_placement": "explicit", **dict(metadata or {})},
@@ -6794,8 +6837,8 @@ def _reserve_cli_session(
session_anchor=session_anchor,
agent_id=agent.id,
agent_name=agent.name,
- model=agent.model,
- reasoning_effort=agent.reasoning_effort,
+ model=model or agent.model,
+ reasoning_effort=reasoning_effort or agent.reasoning_effort,
workdir=workdir,
visibility=visibility,
metadata=metadata,
@@ -7079,6 +7122,10 @@ def cmd_agent_run(args):
# The caller's own authority, resolved once. A remote caller reserves
# under it; a local caller stays ``None`` and keeps Owner semantics.
caller_authorization = caller_resource_user_context(caller_context)
+ # A new Session (blank, --create-session, or a fork) may run on its own model, kept on the Session, which
+ # every later turn reads; it is checked against the Agent's catalog once the Session is reserved (below).
+ model_override = (getattr(args, "model", None) or "").strip() or None
+ effort_override = (getattr(args, "reasoning_effort", None) or "").strip() or None
if session_policy == "create":
session_id = _reserve_cli_session(
agent=agent,
@@ -7088,6 +7135,8 @@ def cmd_agent_run(args):
session_anchor_target=legacy_reservation_target,
visibility=visibility,
authorization_context=caller_authorization,
+ model=model_override,
+ reasoning_effort=effort_override,
)
reserved_session_id = session_id
elif session_policy == "none":
@@ -7098,6 +7147,8 @@ def cmd_agent_run(args):
metadata=session_metadata,
visibility=visibility,
authorization_context=caller_authorization,
+ model=model_override,
+ reasoning_effort=effort_override,
)
reserved_session_id = session_id
elif session_policy == "fork":
@@ -7126,6 +7177,21 @@ def cmd_agent_run(args):
session_key=session_key,
help_command="vibe agent run --help",
)
+ override_fields: dict = {}
+ if model_override or effort_override:
+ # Checked only after the reservation, which admitted the caller to the source Session or the Agent, so a
+ # refusal tells nothing about a Session or Agent the caller cannot reach; a refused pair releases the
+ # reservation (the ``except`` below). The pair is the one the Session will run on: each override over the
+ # default it would otherwise keep, the source Session's for a fork, else the Agent's.
+ override_fields = _session_model_override_fields(
+ backend=agent.backend,
+ agent_label=agent.name,
+ model=fork_result.model if fork_result else model_override or agent.model,
+ reasoning_effort=(
+ fork_result.reasoning_effort if fork_result else effort_override or agent.reasoning_effort
+ ),
+ help_command="vibe agent run --help",
+ )
if (session_policy in {"create", "none"} or fork_result) and args.post_to:
_validate_delivery_args(
session_id=session_id,
@@ -7156,9 +7222,12 @@ def cmd_agent_run(args):
agent_name=agent.name if agent else None,
agent_id=agent.id if agent else None,
agent_backend=agent.backend if agent else None,
- model=fork_result.model if fork_result else (agent.model if agent else None),
+ # An existing Session's run never carries an override (``_validate_run_session_policy``).
+ model=fork_result.model if fork_result else model_override or (agent.model if agent else None),
reasoning_effort=(
- fork_result.reasoning_effort if fork_result else (agent.reasoning_effort if agent else None)
+ fork_result.reasoning_effort
+ if fork_result
+ else effort_override or (agent.reasoning_effort if agent else None)
),
session_policy=session_policy,
session_key=session_key,
@@ -7221,7 +7290,7 @@ def cmd_agent_run(args):
request_store.mark_callback_pending(request.id)
run_payload["callback_status"] = "pending"
payload["run"] = run_payload
- _print_cli_payload("agent_run", **payload)
+ _print_cli_payload("agent_run", **payload, **override_fields)
return 0
except Exception as exc:
if reserved_session_id:
@@ -17887,8 +17956,13 @@ def build_parser():
help="Make the new or forked Session user-facing from the start",
)
agent_run_parser.add_argument("--deliver-key", help=argparse.SUPPRESS)
- agent_run_parser.add_argument("--model", help="Model override for the new forked Session")
- agent_run_parser.add_argument("--reasoning-effort", help="Reasoning effort override for the new forked Session")
+ agent_run_help_language = _configured_cli_language()
+ agent_run_parser.add_argument(
+ "--model", help=i18n_t("harness.cli.agentRunModel.helpModel", agent_run_help_language)
+ )
+ agent_run_parser.add_argument(
+ "--reasoning-effort", help=i18n_t("harness.cli.agentRunModel.helpEffort", agent_run_help_language)
+ )
agent_run_parser.add_argument(
"--cwd",
help=(
diff --git a/vibe/i18n/en.json b/vibe/i18n/en.json
index 53c0f1922..245ef6196 100644
--- a/vibe/i18n/en.json
+++ b/vibe/i18n/en.json
@@ -91,6 +91,18 @@
"harness": {
"agentInitiatedContinuation": "Agent-initiated continuation",
"cli": {
+ "agentRunModel": {
+ "existingSession": "--model and --reasoning-effort only apply when the run creates a new Session",
+ "existingSessionHint": "An existing Session keeps its model; change it in the Web UI's Session model picker. To run on another model now, start a new Session (--agent <name> --model ...) or fork this one (--fork-session <id> --model ...).",
+ "modelNotInCatalog": "model '{model}' is not in the {backend} model catalog",
+ "modelMaybeNewer": "model '{model}' is not in the {backend} model catalog; it may be a typo or newer than the catalog",
+ "effortInvalidForModel": "reasoning_effort '{effort}' is not valid for model '{model}'",
+ "effortInvalidForBackend": "reasoning_effort '{effort}' is not valid for backend '{backend}'",
+ "catalogUnavailable": "the {backend} model catalog could not be loaded, so the model and reasoning effort cannot be checked",
+ "catalogHint": "Run `vibe agent models {agent}` to list valid models and reasoning efforts.",
+ "helpModel": "Model for the new Session this run creates (a blank new Session, --create-session, or a fork); kept on that Session for its later turns. Not valid with --session-id. See `vibe agent models <agent>`.",
+ "helpEffort": "Reasoning effort for the new Session this run creates; kept on that Session. Not valid with --session-id."
+ },
"help": {
"command": "Inspect unified Harness live state and anomalies",
"description": "Inspect active Runs, armed Watches, upcoming Tasks, and live anomalies.",
diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.json
index 42e3676bd..9f1fae7aa 100644
--- a/vibe/i18n/zh.json
+++ b/vibe/i18n/zh.json
@@ -91,6 +91,18 @@
"harness": {
"agentInitiatedContinuation": "Agent 主动发起的续接",
"cli": {
+ "agentRunModel": {
+ "existingSession": "--model 和 --reasoning-effort 只在这次运行创建新 Session 时可用",
+ "existingSessionHint": "已有 Session 保持自己的模型;请在 Web UI 的 Session 模型选择器中修改。如果现在就要换模型运行,请新建一个 Session(--agent <名称> --model ...),或分叉当前 Session(--fork-session <id> --model ...)。",
+ "modelNotInCatalog": "模型 '{model}' 不在 {backend} 的模型目录中",
+ "modelMaybeNewer": "模型 '{model}' 不在 {backend} 的模型目录中;可能是拼写错误,也可能比目录更新",
+ "effortInvalidForModel": "推理强度 '{effort}' 不适用于模型 '{model}'",
+ "effortInvalidForBackend": "推理强度 '{effort}' 不适用于 backend '{backend}'",
+ "catalogUnavailable": "无法加载 {backend} 的模型目录,因此无法检查模型和推理强度",
+ "catalogHint": "运行 `vibe agent models {agent}` 查看可用的模型和推理强度。",
+ "helpModel": "这次运行所创建的新 Session(空白新 Session、--create-session 或分叉)使用的模型;该 Session 之后的轮次会沿用它。不能与 --session-id 一起使用。参见 `vibe agent models <agent>`。",
+ "helpEffort": "这次运行所创建的新 Session 使用的推理强度;该 Session 会沿用它。不能与 --session-id 一起使用。"
+ },
"help": {
"command": "检查统一的 Harness 实时状态和异常",
"description": "检查活跃 Run、已启用 Watch、即将触发的 Task 和实时异常。",