The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(gateway): serve session /fast on the owner
Tekniumd3411d7d22ff
diff --git a/gateway/session_config.py b/gateway/session_config.pyindex f16985a225f..74ba630d372 100644--- a/gateway/session_config.py+++ b/gateway/session_config.py@@ -83,9 +83,7 @@ async def config_get(connection, ref, params):for k in ('mcp', 'mcp_servers', 'tools')},sort_keys=True).encode()).hexdigest()[:12]},'reasoning': lambda: _reasoning(agent, policy, cfg),- 'fast': lambda: {'value': 'fast' if (getattr(agent, 'service_tier', None) or- (policy.config() if policy else cfg).get('agent', {}).get('service_tier'))- in {'priority', 'fast', 'on'} else 'normal'},+ 'fast': lambda: _fast(connection, ref, policy, agent, cfg),'skin': lambda: {'value': display.get('skin', 'default')},'theme': lambda: {'value': display.get('tui_theme', 'auto')},'indicator': lambda: {'value': display.get('tui_status_indicator', DEFAULT_INDICATOR_STYLE)},@@ -101,6 +99,16 @@ async def config_get(connection, ref, params):return await asyncio.to_thread(read)+def _fast(connection, ref, policy, agent, cfg):+ from agent.fast_mode import parse_service_tier+ if ref.session_id: # the session's next-turn tier: its /fast pin, else its policy's+ from gateway.session_tui_config import current_tier+ tier = current_tier(connection, ref, policy)+ else:+ tier = getattr(agent, 'service_tier', None) or parse_service_tier(cfg.get('agent', {}).get('service_tier'))+ return {'value': {'priority': 'fast', 'ultrafast': 'ultrafast'}.get(tier, 'normal')}++def _reasoning(agent, policy, cfg):from hermes_constants import resolve_reasoning_configvalue = getattr(agent, 'reasoning_config', None)diff --git a/gateway/session_tui_config.py b/gateway/session_tui_config.pyindex 2f7d97b83fa..7e7d0f6d6d5 100644--- a/gateway/session_tui_config.py+++ b/gateway/session_tui_config.py@@ -169,8 +169,10 @@ async def config_set(connection, ref, params):return await busy_config(connection, ref, params, write=True)if set(params) - {'session_id', 'profile', 'key', 'value'}:raise RuntimeStoreError('invalid_params')- _authorize_write(connection, ref, params)+ policy = _authorize_write(connection, ref, params)value = params.get('value')+ if key == 'fast':+ return await _set_fast(connection, ref, policy, value)result = await asyncio.to_thread(_write_profile_config, connection,lambda cfg: _set_display(cfg, key, value))if key == 'focus' and ref.session_id and 'tool_progress' in result:@@ -197,3 +199,51 @@ async def _broadcast_skin(connection):for session_id, live in list(connection.authority.sessions.items()):if live.subscribers:live.event_stream.publish(session_id, payload, event_type='skin.changed')+++# /fast word -> stored tier (main's ``_FAST_WORDS``; None = explicit normal).+_FAST_TIERS = {'fast': 'priority', 'on': 'priority', 'normal': None, 'off': None, 'auto': 'auto',+ 'cold': 'cold', 'ultrafast': 'ultrafast', 'ultra': 'ultrafast'}+++def current_tier(connection, ref, policy):+ """The tier this session's next turn runs: its /fast pin, else its policy's (or the profile's)."""+ runner, live = connection.authority.runner, connection.authority.sessions[ref.session_id]+ if policy is not None:+ return policy.current_service_tier(runner, live.route)+ return runner._resolve_session_service_tier(source=live.source, session_key=live.route)+++async def _set_fast(connection, ref, policy, value):+ """Session-scoped /fast like main's: validated against the session's route, never config.yaml.+ The pin is the runner's per-session override the next turn reads (``current_service_tier``)."""+ from agent.fast_mode import STATIC_TIERS, service_tier_word+ if not ref.session_id:+ raise RuntimeStoreError('invalid_params')+ raw, current = _word(value), current_tier(connection, ref, policy)+ if raw == 'status':+ return {'key': 'fast', 'value': service_tier_word(current)}+ if raw in ('', 'toggle'):+ raw = 'normal' if current in STATIC_TIERS else 'fast'+ if raw not in _FAST_TIERS:+ raise RuntimeStoreError('invalid_params')+ tier = _FAST_TIERS[raw]+ if tier in STATIC_TIERS:+ agent = connection.authority.agent(ref)+ model = getattr(agent, 'model', None) or (policy.current_model(connection.authority) if policy else None)+ provider = getattr(agent, 'provider', None) or (policy.provider if policy else None)+ base_url = getattr(agent, 'base_url', None) or (policy.base_url if policy else None)++ def offered():+ from agent.codex_service_tiers import ultrafast_offered+ from hermes_cli.models import resolve_fast_mode_overrides+ if not model or resolve_fast_mode_overrides(model, provider=provider, base_url=base_url,+ tier=tier if tier == 'ultrafast' else None) is None:+ return False+ return tier != 'ultrafast' or ultrafast_offered(model, provider=provider, base_url=base_url,+ access_token=getattr(agent, 'api_key', None))+ if not await asyncio.to_thread(offered):+ raise RuntimeStoreError('fast_unavailable')+ connection.authority.runner._set_session_service_tier_override(+ connection.authority.sessions[ref.session_id].route, tier)+ return {'key': 'fast', 'value': service_tier_word(tier)}diff --git a/tests/gateway/test_session_tui_config.py b/tests/gateway/test_session_tui_config.pyindex 1c73d23af36..479cb312f0a 100644--- a/tests/gateway/test_session_tui_config.py+++ b/tests/gateway/test_session_tui_config.py@@ -106,3 +106,34 @@ def test_skin_persists_and_repaints_every_attached_tui_of_the_profile(tmp_path):assert (await rpc(ws, 'config.set', key='skin', value='')).get('error', {}).get('message') == 'invalid_params'assert not admissions(home) and not peer.requestsasyncio.run(probe())++[email protected]("linux")+def test_fast_is_session_scoped_validated_and_read_back(tmp_path):+ with owner(tmp_path) as (home, peer, desc):+ async def probe():+ async with websocket(home, desc) as ws:+ # A route that bills Priority Processing (never called: no turn runs).+ sid = (await rpc(ws, 'session.create', request_id='fast', source='tui', toolsets=[],+ model='gpt-5.4', provider='openai',+ base_url='https://api.openai.com/v1'))['result']['session_id']+ other = (await rpc(ws, 'session.create', request_id='slow', source='tui',+ toolsets=[]))['result']['session_id']+ before = (home / 'config.yaml').read_bytes()+ result = await rpc(ws, 'config.set', key='fast', value='fast', session_id=sid)+ assert result.get('result') == {'key': 'fast', 'value': 'fast'}, result+ assert (await rpc(ws, 'config.get', key='fast', session_id=sid))['result']['value'] == 'fast'+ assert (await rpc(ws, 'config.get', key='fast', session_id=other))['result']['value'] == 'normal'+ assert (await rpc(ws, 'config.set', key='fast', value='toggle', session_id=sid)+ )['result']['value'] == 'normal'+ assert (await rpc(ws, 'config.get', key='fast', session_id=sid))['result']['value'] == 'normal'+ for params, reason in [+ ({'key': 'fast', 'value': 'fast', 'session_id': other}, 'fast_unavailable'),+ ({'key': 'fast', 'value': 'warp', 'session_id': sid}, 'invalid_params'),+ ({'key': 'fast', 'value': 'fast'}, 'invalid_params'),+ ]:+ assert (await rpc(ws, 'config.set', **params)).get('error', {}).get('message') == reason, params+ # Session-scoped like main: config.yaml is untouched.+ assert (home / 'config.yaml').read_bytes() == before+ assert not admissions(home) and not peer.requests+ asyncio.run(probe())diff --git a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts b/ui-tui/src/__tests__/canonicalSlashCommands.test.tsindex 3b9d043e2d4..d42939df311 100644--- a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts+++ b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts@@ -203,7 +203,7 @@ it('/stop is session-scoped; process-global /reload-mcp refuses on the shared gait('setting writes the shared gateway has no verb for say so instead of a bare invalid_params; reads still work', async () => {const { request, slash, sys } = harness()- for (const cmd of ['/reasoning high --global', '/fast fast', '/personality pirate', '/skin']) {+ for (const cmd of ['/reasoning high --global', '/personality pirate', '/skin']) {slash(cmd)}@@ -214,7 +214,7 @@ it('setting writes the shared gateway has no verb for say so instead of a bare iconst notices = sys.mock.calls.map(([text]) => String(text))- for (const name of ['reasoning', 'fast', 'personality']) {+ for (const name of ['reasoning', 'personality']) {expect(notices).toContain(`/${name} is not available on the shared gateway yet`)}@@ -231,6 +231,17 @@ it('/skin writes the profile through the owner\'s config.set like main (the owneexpect(sys.mock.calls.map(([text]) => String(text))).toEqual(['skin → mono'])})+it('/fast <mode> is the owner\'s session-scoped config.set like main', async () => {+ const { request, slash, sys } = harness()++ slash('/fast fast')+ await flush()++ expect(request).toHaveBeenCalledWith('config.set', { key: 'fast', session_id: 'owner', value: 'fast' })+ expect(sys.mock.calls.map(([text]) => String(text))).toEqual(['fast mode: fast'])+ expect(getUiState().info).toMatchObject({ fast: true, service_tier: 'priority' })+})+it('/theme and /indicator write the profile through the owner\'s config.set like main', async () => {const { request, slash, sys } = harness()diff --git a/ui-tui/src/app/slash/commands/session.ts b/ui-tui/src/app/slash/commands/session.tsindex b1d92ab2142..9e8271215c2 100644--- a/ui-tui/src/app/slash/commands/session.ts+++ b/ui-tui/src/app/slash/commands/session.ts@@ -696,12 +696,6 @@ export const sessionCommands: SlashCommand[] = [.catch(ctx.guardedErr)}- // The shared owner serves this setting's read, not its write (a config.yaml / per-session- // setting it has no frozen-policy verb for yet): say so instead of a bare invalid_params.- if (ctx.gateway.gw?.isCanonical) {- return ctx.transcript.sys(t('canonical.controls.notAvailable', 'fast'))- }-ctx.gateway.rpc<ConfigSetResponse>('config.set', { key: 'fast', session_id: ctx.sid, value: mode }).then(