Skip to content

feat(session): thread agent_id through session identity & DB schema (2/6)#37496

Open
davidgut1982 wants to merge 2 commits into
NousResearch:mainfrom
davidgut1982:feat/mga-2-session-agent-id
Open

feat(session): thread agent_id through session identity & DB schema (2/6)#37496
davidgut1982 wants to merge 2 commits into
NousResearch:mainfrom
davidgut1982:feat/mga-2-session-agent-id

Conversation

@davidgut1982

Copy link
Copy Markdown
Contributor

What

Thread agent_id through session identity and the SQLite session schema (new agent_id column + index, INSERT path, and session helpers).

Why

Sessions must be attributable to a specific agent so routing, history, and per-agent behavior stay isolated when one gateway serves multiple agents.

How to test

python -m pytest tests/gateway/test_session.py tests/gateway/test_session_boundary_hooks.py tests/cli/test_session_boundary_hooks.py -q

Platforms tested

Linux (CT 133 / Proxmox LXC)

Part 2 of 6 in the multi-agent gateway decomposition (replaces #34741). Depends on: #37495

Note on conflict resolution: cherry-picking onto current main conflicted in hermes_state.py where main had since added the fts5_available-guarded FTS5/trigram setup and a cwd session column. Resolved by keeping both — the new agent_id index is created before the FTS block, and the INSERT column list/placeholders now carry both agent_id and cwd (10 columns).

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery labels Jun 2, 2026
@davidgut1982 davidgut1982 force-pushed the feat/mga-2-session-agent-id branch from 24b05f5 to 7bb5da3 Compare June 3, 2026 03:01
02356abc added 2 commits June 4, 2026 00:28
Introduce AgentProfile dataclass and a ContextVar (_current_agent_profile)
that lets path getters (get_hermes_home, get_skills_dir, get_memory_dir)
resolve to the active agent's home directory under asyncio.

- agent/profile.py: AgentProfile, use_profile() context manager,
  load_agent_registry() from GatewayConfig
- hermes_constants.py: get_hermes_home() reads ContextVar before env fallback
- tests/agent/test_profile_contextvar.py: ContextVar isolation under
  asyncio.gather, nested contexts, registry loading

Single-agent installs see zero change — no profile bound means fallback
to HERMES_HOME env var as before.
Add agent_id field to SessionSource and SessionEntry, prefix session keys
with agent:<id>: in build_session_key. Default "main" preserves every
historical key string for single-agent installs.

- gateway/session.py: SessionSource.agent_id, SessionEntry.agent_id,
  build_session_key prefixing
- hermes_state.py: sessions table migration (agent_id TEXT DEFAULT 'main'),
  new idx_sessions_agent index
- tests/gateway/test_session.py: build_session_key prefixing for all
  chat_type × agent_id combinations
- tests/*/test_session_boundary_hooks.py: hook payload agent_id kwarg
@davidgut1982 davidgut1982 force-pushed the feat/mga-2-session-agent-id branch from 7bb5da3 to 34e1e12 Compare June 4, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants