Merge pull request #1040 from NousResearch/hermes/hermes-5da06378

feat: include session ID in system prompt via --pass-session-id flag
This commit is contained in:
Teknium 2026-03-12 05:52:26 -07:00 committed by GitHub
commit 1e3607150c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 3 deletions

6
cli.py
View file

@ -1099,6 +1099,7 @@ class HermesCLI:
compact: bool = False,
resume: str = None,
checkpoints: bool = False,
pass_session_id: bool = False,
):
"""
Initialize the Hermes CLI.
@ -1113,6 +1114,7 @@ class HermesCLI:
verbose: Enable verbose logging
compact: Use compact display mode
resume: Session ID to resume (restores conversation history from SQLite)
pass_session_id: Include the session ID in the agent's system prompt
"""
# Initialize Rich console
self.console = Console()
@ -1194,6 +1196,7 @@ class HermesCLI:
cp_cfg = {"enabled": cp_cfg}
self.checkpoints_enabled = checkpoints or cp_cfg.get("enabled", False)
self.checkpoint_max_snapshots = cp_cfg.get("max_snapshots", 50)
self.pass_session_id = pass_session_id
# Ephemeral system prompt: env var takes precedence, then config
self.system_prompt = (
@ -1511,6 +1514,7 @@ class HermesCLI:
thinking_callback=self._on_thinking,
checkpoints_enabled=self.checkpoints_enabled,
checkpoint_max_snapshots=self.checkpoint_max_snapshots,
pass_session_id=self.pass_session_id,
)
# Apply any pending title now that the session exists in the DB
if self._pending_title and self._session_db:
@ -4654,6 +4658,7 @@ def main(
worktree: bool = False,
w: bool = False,
checkpoints: bool = False,
pass_session_id: bool = False,
):
"""
Hermes Agent CLI - Interactive AI Assistant
@ -4759,6 +4764,7 @@ def main(
compact=compact,
resume=resume,
checkpoints=checkpoints,
pass_session_id=pass_session_id,
)
# Inject worktree context into agent's system prompt

View file

@ -495,6 +495,7 @@ def cmd_chat(args):
"resume": getattr(args, "resume", None),
"worktree": getattr(args, "worktree", False),
"checkpoints": getattr(args, "checkpoints", False),
"pass_session_id": getattr(args, "pass_session_id", False),
}
# Filter out None values
kwargs = {k: v for k, v in kwargs.items() if v is not None}
@ -1895,6 +1896,12 @@ For more help on a command:
default=False,
help="Bypass all dangerous command approval prompts (use at your own risk)"
)
parser.add_argument(
"--pass-session-id",
action="store_true",
default=False,
help="Include the session ID in the agent's system prompt"
)
subparsers = parser.add_subparsers(dest="command", help="Command to run")
@ -1966,6 +1973,12 @@ For more help on a command:
default=False,
help="Bypass all dangerous command approval prompts (use at your own risk)"
)
chat_parser.add_argument(
"--pass-session-id",
action="store_true",
default=False,
help="Include the session ID in the agent's system prompt"
)
chat_parser.set_defaults(func=cmd_chat)
# =========================================================================

View file

@ -233,6 +233,7 @@ class AIAgent:
fallback_model: Dict[str, Any] = None,
checkpoints_enabled: bool = False,
checkpoint_max_snapshots: int = 50,
pass_session_id: bool = False,
):
"""
Initialize the AI Agent.
@ -287,6 +288,7 @@ class AIAgent:
self.ephemeral_system_prompt = ephemeral_system_prompt
self.platform = platform # "cli", "telegram", "discord", "whatsapp", etc.
self.skip_context_files = skip_context_files
self.pass_session_id = pass_session_id
self.log_prefix_chars = log_prefix_chars
self.log_prefix = f"{log_prefix} " if log_prefix else ""
# Store effective base URL for feature detection (prompt caching, reasoning, etc.)
@ -1483,9 +1485,10 @@ class AIAgent:
from hermes_time import now as _hermes_now
now = _hermes_now()
prompt_parts.append(
f"Conversation started: {now.strftime('%A, %B %d, %Y %I:%M %p')}"
)
timestamp_line = f"Conversation started: {now.strftime('%A, %B %d, %Y %I:%M %p')}"
if self.pass_session_id and self.session_id:
timestamp_line += f"\nSession ID: {self.session_id}"
prompt_parts.append(timestamp_line)
platform_key = (self.platform or "").lower().strip()
if platform_key in PLATFORM_HINTS: