Skip to content

The agent that grows with you

fix(gateway): a typed /model --reasoning on a local session commits the level with the model

Teknium53c825938287
diff --git a/gateway/session_setting_commands.py b/gateway/session_setting_commands.py
index fdfaf9172dc..a62aa1afc79 100644
--- a/gateway/session_setting_commands.py
+++ b/gateway/session_setting_commands.py
@@ -73,7 +73,7 @@ def local_authority_live(runner, source):
return None, None
-def defer_local_model_pick(authority, live, result):
+def defer_local_model_pick(authority, live, result, effort=''):
"""A typed ``/model`` on a local session: the resolved target becomes the session's canonical
``model`` mutation, committed by the owner at the next turn boundary (the typed command is
itself the running admission). One writer, so the next request, ``sessions.model`` and
@@ -87,5 +87,7 @@ def defer_local_model_pick(authority, live, result):
payload = {'model': result.new_model}
if result.target_provider:
payload['provider'] = result.target_provider
+ if effort:
+ payload['reasoning'] = effort # `--reasoning <level>`: committed in the same selection
defer_pick(authority, owner, SessionRef(authority.profile_id, sid),
{'request_id': 'typed-model:' + uuid.uuid4().hex, 'payload': payload})
diff --git a/gateway/slash_commands_model.py b/gateway/slash_commands_model.py
index 2fb2af1e97a..1f18c0de111 100644
--- a/gateway/slash_commands_model.py
+++ b/gateway/slash_commands_model.py
@@ -420,7 +420,10 @@ class GatewayModelCommandsMixin:
# only commit, landing at the next turn boundary (this command is the running turn).
if one_turn:
return t("gateway.model.error_prefix", error=t("gateway.model.err_once_local"))
- await asyncio.to_thread(defer_local_model_pick, authority, live, result)
+ from hermes_constants import parse_reasoning_effort
+ effort = (ctx.reasoning_effort or "").strip().lower()
+ level = effort if parse_reasoning_effort(effort) is not None else ""
+ await asyncio.to_thread(defer_local_model_pick, authority, live, result, level)
self._record_switch_metrics(result, ctx, source)
global_error = None
if ctx.persist_global:
@@ -429,9 +432,20 @@ class GatewayModelCommandsMixin:
except Exception as e:
logger.warning("Failed to persist model switch", exc_info=True)
global_error = t("gateway.model.err_config_not_updated", error=str(e) or type(e).__name__)
- return await self._model_switch_confirmation(
- result, ctx, one_turn=False, picker=picker, global_error=global_error) + (
- "\n" + t("gateway.model.local_next_turn"))
+ reply = await self._model_switch_confirmation(
+ result, ctx, one_turn=False, picker=picker, global_error=global_error)
+ if level:
+ saved = (ctx.persist_global and global_error is None
+ and self._save_gateway_config_key("agent.reasoning_effort", level))
+ reply += "\n" + t("gateway.reasoning.set_global" if saved else "gateway.reasoning.set_session",
+ effort=level)
+ elif effort:
+ # A display toggle / reset / unknown word is not a level: the /reasoning applier answers.
+ from gateway.run import _platform_config_key
+ reply += "\n" + self._apply_reasoning_selection(
+ ctx.session_key, _platform_config_key(source.platform), effort,
+ persist_global=ctx.persist_global and global_error is None)
+ return reply + "\n" + t("gateway.model.local_next_turn")
error = self._switch_cached_agent_model(result, ctx, picker)
if error is not None:
return error
diff --git a/tests/gateway/test_session_model_command_commits.py b/tests/gateway/test_session_model_command_commits.py
index ba7de2b0804..778aca9b103 100644
--- a/tests/gateway/test_session_model_command_commits.py
+++ b/tests/gateway/test_session_model_command_commits.py
@@ -55,9 +55,11 @@ def test_typed_model_command_on_a_local_session_moves_the_next_request(tmp_path)
sid = (await call('session.create', source='tui', request_id='owner', toolsets=[]))['session_id']
await turn(sid, 'BEFORE')
- await turn(sid, '/model switched')
+ await turn(sid, '/model switched --reasoning high')
await turn(sid, 'AFTER')
assert [r['model'] for r in peer.requests] == ['original', 'switched'], [(r['model'], r['messages'][-1]['content']) for r in peer.requests]
+ # The level typed with the model commits in the same selection.
+ assert peer.requests[-1].get('reasoning_effort') == 'high', peer.requests[-1]
assert (await call('session.info', session_id=sid))['model'] == 'switched'
with sqlite3.connect(home / 'state.db') as db:
assert db.execute('SELECT model FROM sessions WHERE id=?', (sid,)).fetchone()[0] == 'switched'