The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): accept `hermes chat --source tool` and keep the label stored
Teknium5a5e1570ae3e
diff --git a/agent/managed_worker.py b/agent/managed_worker.pyindex 2847acc1f20..944511ab347 100644--- a/agent/managed_worker.py+++ b/agent/managed_worker.py@@ -306,7 +306,9 @@ def execute(frame, channel):agent = _construct_agent(frame, AIAgent, model=policy.model, provider=policy.provider, base_url=policy.base_url,api_key=frame['api_key'], session_db=store, session_id=scope['session_id'],enabled_toolsets=list(policy.toolsets), max_iterations=policy.max_turns,- reasoning_config=policy.reasoning_config, platform=policy.source,+ reasoning_config=policy.reasoning_config,+ # ``tool`` is a storage label for a CLI-surface agent (session_policy.SURFACES).+ platform=policy.platform if policy.source == 'tool' else policy.source,gateway_session_key=frame['route'], user_id=frame['user_id'], chat_id=frame['chat_id'],skip_context_files=policy.ignore_rules, load_soul_identity=not policy.ignore_rules,skip_memory=policy.ignore_rules, skip_background_review=True, quiet_mode=True,diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex 819df340a7c..7c932ce87d9 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -4684,7 +4684,7 @@ export interface GroupsDiscardResult {export interface CanonicalCreateParams {profile?: string | nullrequest_id?: string | null- source?: 'cli' | 'tui' | 'gui' | 'acp'+ source?: 'cli' | 'tui' | 'gui' | 'acp' | 'tool'cwd?: string | nullmodel?: string | nullprovider?: string | nulldiff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 5f1880becd2..f849ab756e4 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -8519,7 +8519,8 @@"cli","tui","gui",- "acp"+ "acp",+ "tool"],"title": "Source","type": "string"diff --git a/gateway/session_a2a.py b/gateway/session_a2a.pyindex 3be3795db23..c060ce57331 100644--- a/gateway/session_a2a.py+++ b/gateway/session_a2a.py@@ -47,7 +47,7 @@ def forward_author(policy):def storage_source(db, source, session_id, fallback):- """Retain the owner's native label when its transport refreshes peer metadata."""+ """Retain the owner's creation label when its LOCAL transport refreshes peer metadata."""from gateway.config import Platformif source.platform != Platform.LOCAL or not str(source.chat_id).startswith('local-'):return fallback@@ -55,7 +55,11 @@ def storage_source(db, source, session_id, fallback):receipt = local_receipt(db, source.chat_id)if session_id not in receipt.get('lineage', [receipt['session_id']]):raise RuntimeStoreError('admission_conflict')- return 'a2a' if receipt['policy']['source'] == 'a2a' else fallback+ # Producer labels (a2a, cron, kanban, bot_room, ``--source tool``) survive the refresh: pickers+ # filter on them (kanban/tool hidden, cron in its own section). Interactive+ # surfaces keep the transport's ``local``, outside the state-owned stale-open sweeps keyed on cli/tui/acp.+ label = receipt['policy']['source']+ return fallback if label in {'cli', 'tui', 'gui', 'acp'} else labelasync def forward(connection, params):diff --git a/gateway/session_controls.py b/gateway/session_controls.pyindex 930088f3030..3ff123b13f1 100644--- a/gateway/session_controls.py+++ b/gateway/session_controls.py@@ -281,11 +281,11 @@ class AuthorityConnection:async def describe(self, ref, params):await self.ping(ref, params)- from gateway.session_policy import CREATE_FIELDS+ from gateway.session_policy import CREATE_FIELDS, SURFACESreturn {'instance_id': self.authority.instance_id, 'profile_id': self.authority.profile_id,'authority_epoch': self.authority.epoch,'capabilities': ['durable-admission-v1', 'event-replay-v1', 'local-cli-create-v1', 'acp-editor-policy-v1', 'acp-session-mcp-v1'],- 'session_create': {'sources': ['cli', 'tui', 'gui', 'acp'],+ 'session_create': {'sources': sorted(SURFACES),'parameters': sorted(CREATE_FIELDS | {'title'})}}async def info(self, ref, params):@@ -319,6 +319,7 @@ class AuthorityConnection:'message_count': row.get('message_count', 0),'running': found.session_id in self.authority.sessions}],'scope': 'stored'}+ from hermes_state_sessions import INTERNAL_LISTING_SOURCESsessions = []for sid in tuple(self.authority.sessions):candidate = SessionRef(self.actor.profile_id, sid)@@ -329,6 +330,10 @@ class AuthorityConnection:raisecontinuerow = self.authority.db.get_session(sid)+ # The human picker feed (TUI switcher): kanban workers and `--source tool` integrations+ # are not conversations, as on every other picker (INTERNAL_LISTING_SOURCES).+ if row.get('source') in INTERNAL_LISTING_SOURCES:+ continuesessions.append({'session_id': sid, 'id': sid, 'title': row.get('title') or '','source': row.get('source'), 'started_at': row.get('started_at'),'message_count': row.get('message_count', 0),diff --git a/gateway/session_managed_worker.py b/gateway/session_managed_worker.pyindex 99f51bbda2b..6b378bdfc1b 100644--- a/gateway/session_managed_worker.py+++ b/gateway/session_managed_worker.py@@ -41,7 +41,7 @@ def managed_policy(authority, ref):if policy.config().get('gateway', {}).get('managed_workers') is not True:return Nonerequest = json.loads(policy.request_json)- if policy.source != 'cli' or request.get('provider') != 'custom' or not request.get('base_url'):+ if policy.platform != 'cli' or request.get('provider') != 'custom' or not request.get('base_url'):raise RuntimeStoreError('unsupported_managed_policy')return policydiff --git a/gateway/session_policy.py b/gateway/session_policy.pyindex 17782154ac8..94ed23a7ede 100644--- a/gateway/session_policy.py+++ b/gateway/session_policy.py@@ -13,7 +13,9 @@ CREATE_FIELDS = frozenset({'request_id', 'source', 'cwd', 'model', 'toolsets','skills', 'checkpoints', 'accept_hooks', 'pass_session_id'})BYPASS_FIELDS = ('safe_mode', 'ignore_user_config')_ACTIVE_POLICY: ContextVar = ContextVar('local_session_policy', default=None)-SURFACES = {'cli': 'cli', 'tui': 'tui', 'gui': 'desktop', 'acp': 'acp'}+# Creation label -> agent surface. ``tool`` (third-party integrations, ``hermes chat --source tool``) runs as+# the CLI but keeps its own stored label, so human pickers hide it (INTERNAL_LISTING_SOURCES).+SURFACES = {'cli': 'cli', 'tui': 'tui', 'gui': 'desktop', 'acp': 'acp', 'tool': 'cli'}@dataclass(frozen=True)diff --git a/gateway/session_worker_delegation.py b/gateway/session_worker_delegation.pyindex 1528cab7355..bc08ccee0d4 100644--- a/gateway/session_worker_delegation.py+++ b/gateway/session_worker_delegation.py@@ -54,7 +54,7 @@ def _dispatch(db, conn, session_id, payload, *, execution_id, worker_pid, workersession = conn.execute('SELECT source,session_key FROM sessions WHERE id=?', (session_id,)).fetchone()# Only compute registrations are currently enabled. Native/child origins need# an owner-reserved source envelope, not worker-selected transport identities.- if session is None or session['source'] not in ('cli', 'tui', 'gui'):+ if session is None or session['source'] not in ('cli', 'tui', 'gui', 'tool'):raise RuntimeStoreError('unsupported_producer')if (payload['parent_session_id'] != session_idor payload['session_key'] != (session['session_key'] or '')diff --git a/tests/gateway/test_local_source_labels.py b/tests/gateway/test_local_source_labels.pynew file mode 100644index 00000000000..2ab84523186--- /dev/null+++ b/tests/gateway/test_local_source_labels.py@@ -0,0 +1,53 @@+"""A canonical local session keeps the source label it was created with, and human pickers hide the+non-conversation labels (``tool`` integrations) as on the classic surfaces."""+from pathlib import Path+from types import SimpleNamespace++import pytest++from gateway.session_controls import AuthorityConnection+++async def _authority(tmp_path, monkeypatch):+ from gateway.config import GatewayConfig+ from gateway.session import SessionStore+ from gateway.session_authority import initialize_session_authority+ import gateway.run as run++ monkeypatch.setattr(run, '_load_gateway_config', lambda: {'model': {'default': 'fixture'}, 'platform_toolsets': {'cli': []}})+ monkeypatch.setattr(run, '_resolve_gateway_model', lambda config: 'fixture')+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())+ runner = run.GatewayRunner.__new__(run.GatewayRunner)+ runner.adapters, runner.session_store, runner._session_db, runner._draining = {}, store, store._db, False+ authority = await initialize_session_authority(runner, profile_id=str(Path(store._db.db_path).parent), instance_id='test')+ authority._schedule = lambda ref: None+ return authority, store+++async def _create(conn, authority, store, source, request_id):+ conn_cwd = Path(authority.db.db_path).parent+ created = await conn.dispatch({'id': request_id, 'method': 'session.create',+ 'params': {'request_id': request_id, 'source': source, 'cwd': str(conn_cwd)}})+ assert 'result' in created, created+ sid = created['result']['stored_session_id']+ live = authority.sessions[sid]+ # Every turn refreshes the routing peer; the creation label must survive it.+ store._record_gateway_session_peer(sid, live.route, live.source)+ return sid+++async def test_source_tool_is_admitted_stored_and_hidden_from_pickers(tmp_path, monkeypatch):+ authority, store = await _authority(tmp_path, monkeypatch)+ conn = AuthorityConnection(authority, SimpleNamespace(write=lambda frame: None), {'user_id': 'owner'})+ described = await conn.dispatch({'id': 0, 'method': 'runtime.describe', 'params': {}})+ assert 'tool' in described['result']['session_create']['sources']+ chat = await _create(conn, authority, store, 'cli', 'chat')+ tool = await _create(conn, authority, store, 'tool', 'integration')+ assert authority.db.get_session(tool)['source'] == 'tool'+ assert authority.sessions[tool].source.platform.value == 'local'+ listed = await conn.dispatch({'id': 9, 'method': 'session.list', 'params': {}})+ assert [row['id'] for row in listed['result']['sessions']] == [chat]+ await conn.close()+ authority.db.close()+diff --git a/tui_gateway/contracts/canonical_sessions.py b/tui_gateway/contracts/canonical_sessions.pyindex 3f6fcf91313..93766cf9651 100644--- a/tui_gateway/contracts/canonical_sessions.py+++ b/tui_gateway/contracts/canonical_sessions.py@@ -16,7 +16,7 @@ class CanonicalSessionParams(ProfileParams):class CanonicalCreateParams(ProfileParams):request_id: str | None = None- source: Literal['cli', 'tui', 'gui', 'acp'] = 'cli'+ source: Literal['cli', 'tui', 'gui', 'acp', 'tool'] = 'cli'cwd: str | None = Nonemodel: str | None = Noneprovider: str | None = None