mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-24 05:41:40 +00:00
feat(session): add /handoff command for cross-platform session transfer
Adds /handoff <platform> CLI command that queues the current session for resume on the configured home channel of any messaging platform. CLI side: - /handoff telegram — marks session in shared DB, sends summary to the Telegram home channel via send_message - /handoff discord — same for Discord - Supports telegram, discord, slack, whatsapp, signal, matrix Gateway side: - On new session creation, checks for pending handoffs for the incoming message's platform - If found, loads the CLI session's full conversation history and injects it into the context prompt as a handoff transcript - Agent continues the conversation seamlessly Files: - hermes_state.py: handoff_pending, handoff_platform columns + helpers - cli.py: _handle_handoff_command dispatch + handler - hermes_cli/commands.py: CommandDef entry - gateway/run.py: handoff detection in _handle_message_with_agent - tests/hermes_cli/test_session_handoff.py: 8 tests
This commit is contained in:
parent
6e5c49bdc4
commit
878611a79d
5 changed files with 294 additions and 0 deletions
|
|
@ -215,6 +215,8 @@ CREATE TABLE IF NOT EXISTS sessions (
|
|||
pricing_version TEXT,
|
||||
title TEXT,
|
||||
api_call_count INTEGER DEFAULT 0,
|
||||
handoff_pending INTEGER DEFAULT 0,
|
||||
handoff_platform TEXT,
|
||||
FOREIGN KEY (parent_session_id) REFERENCES sessions(id)
|
||||
);
|
||||
|
||||
|
|
@ -2861,3 +2863,46 @@ class SessionDB:
|
|||
|
||||
return result
|
||||
|
||||
# ── Handoff (cross-platform session transfer) ──────────────────────────
|
||||
|
||||
def set_handoff_pending(self, session_id: str, platform: str) -> bool:
|
||||
"""Mark a session as pending handoff to the given platform.
|
||||
|
||||
Returns True if the session was found and updated.
|
||||
"""
|
||||
def _do(conn):
|
||||
cur = conn.execute(
|
||||
"UPDATE sessions SET handoff_pending = 1, handoff_platform = ? "
|
||||
"WHERE id = ? AND handoff_pending = 0",
|
||||
(platform, session_id),
|
||||
)
|
||||
return cur.rowcount > 0
|
||||
return self._execute_write(_do)
|
||||
|
||||
def find_pending_handoff(self, platform: str) -> Optional[Dict[str, Any]]:
|
||||
"""Find the most recent session pending handoff for a platform.
|
||||
|
||||
Returns the session dict or None.
|
||||
"""
|
||||
try:
|
||||
cur = self._conn.execute(
|
||||
"SELECT * FROM sessions "
|
||||
"WHERE handoff_pending = 1 AND handoff_platform = ? "
|
||||
"ORDER BY started_at DESC LIMIT 1",
|
||||
(platform,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
return dict(row) if row else None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def clear_handoff_pending(self, session_id: str) -> None:
|
||||
"""Clear the handoff_pending flag on a session."""
|
||||
def _do(conn):
|
||||
conn.execute(
|
||||
"UPDATE sessions SET handoff_pending = 0, handoff_platform = NULL "
|
||||
"WHERE id = ?",
|
||||
(session_id,),
|
||||
)
|
||||
self._execute_write(_do)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue