Hermes Agent Session Lifecycle and Scheduled Tasks
Session reset policy
The reset policy controls when a session automatically 'forgets' - obtaining a new session_id while the old context is archived.
A well-configured reset policy prevents the Agent's context from growing without bound while ensuring the user experience is unaffected.
Four reset modes
| Mode | Behavior | Applicable scenarios |
|---|---|---|
| none | Never reset automatically; context is managed only by the compression mechanism | Scenarios that need long-term continuous context |
| idle | Reset automatically after N minutes of inactivity | Agents used occasionally |
| daily | Reset automatically at a specified time each day | Agents used on a daily routine |
| both | Inactivity timeout or daily reset, whichever triggers first is applied | Most scenarios (default recommendation) |
Configure the reset policy
Example
config.yaml - global reset policy
session_reset
:
mode
:
both
none | idle | daily | both
at_hour
:
4
Daily reset time (4 AM, local time)
idle_minutes
:
1440
Inactivity timeout (1440 minutes = 24 hours)
notify
:
true
Notify the user on reset
Customize the reset policy per platform
platforms
:
telegram
:
session_reset
:
mode
:
idle
idle_minutes
:
720
Telegram sessions reset after 12 hours of inactivity
slack
:
session_reset
:
mode
:
none
Slack sessions never reset automatically
Effects of a reset
When a session triggers a reset, the following happens:
- The old session is marked as ended in SQLite (reason: "session_reset")
- Generate a new session_id (format: YYYYMMDD_HHMMSS_8-digit random hex)
- The new SessionEntry's was_auto_reset is set to true
- The cached Agent instance is cleared
- The user receives a 'session has been reset' notice in the next message
Sessions with active background processes are never reset. Hermes checks the has_active_processes callback to ensure running tasks are not interrupted.
Restart recovery mechanism
The Hermes Gateway restart recovery mechanism ensures that ongoing sessions are not lost after an unexpected crash or a planned restart.
Two recovery flags
| Markup | Trigger scenario | Behavior | Severity |
|---|---|---|---|
| resume_pending | Crash recovery, drain timeout | Keep the session_id and continue the conversation on the next visit | Soft recovery |
| suspended | /stop command, 3 consecutive restart failures | Force a reset and generate a new session_id | Hard reset |
Startup recovery flow
When the Gateway starts, the recovery flow is as follows:
Step 1: check the .clean_shutdown flag.
If it exists, the last shutdown was clean, so skip the recovery flow.
Step 2: if the .clean_shutdown flag does not exist, the last exit was abnormal.
The Gateway calls suspend_recently_active() to mark sessions active within the last 120 seconds as resume_pending.
Step 3: detect a stuck-loop.
If a session is still active after 3 consecutive restarts, it may be stuck in a loop, and the Gateway marks it as suspended.
Step 4: recover pending sessions.
The Gateway synthesizes a MessageEvent for each resume_pending session, triggering the Agent to continue automatically.
Drain timeout flag
During a normal shutdown/restart, if a session is being processed but exceeds the drain wait time, the Gateway marks it as resume_pending.
Marking reasons for different scenarios:
| Marking reason | Meaning |
|---|---|
| restart_timeout | Drain timeout during restart |
| shutdown_timeout | Drain timeout during shutdown |
| restart_interrupted | Crash recovery (triggered from suspend_recently_active) |
The resume_pending flag is not cleared by get_or_create_session() - it is cleared after the next successful Agent reply. If the recovered session is interrupted again, the flag is retained, allowing a retry on the next restart. After 3 consecutive failures it is escalated to suspended.
Message queue mechanism
When a user sends multiple messages in a row while the Agent is processing, the Gateway's message queue mechanism ensures no messages are lost.
Queue structure
The Gateway uses a two-level queue design:
- Single-slot pending (_pending_messages): each session has only one 'next' slot; repeated sends overwrite it
- Overflow queue (_queued_events): when the slot is occupied, subsequent messages are appended to the tail of the overflow queue
/queue command
The /queue command lets you submit tasks in bulk, each producing a full Agent turn.
Example
Send in Telegram/Discord
/
queue review src
/
the code style of main.py
/
queue for src
/
write unit tests for utils.py
/
queue update the installation instructions in README.md
Each task in the queue executes in FIFO order, one after another; each task produces a complete Agent turn and is not merged.
Use the /new or /reset command to clear the current session's message queue.
When multiple messages are sent in a row while the Agent is processing, the intermediate ones are overwritten (only the last is kept), but messages in the /queue command are not overwritten - each /queue task executes in order.
Scheduled tasks (Cron)
Hermes has built-in first-class support for scheduled tasks, letting you configure the Agent to run specific tasks periodically.
Scheduled tasks can be bound to a Skill and deliver results to a specified platform.
Configure scheduled tasks
Scheduled tasks are defined in jobs.json and support multiple scheduling formats.
{
"jobs": [
{
"id": "daily-news-summary",
"schedule": "0 8 * * *",
"description": "每天早上 8 点抓取 AI 行业新闻并生成摘要",
"skill": "ai-news-summarizer",
"deliver_to": {
"platform": "telegram",
"chat_id": "-1001234567890"
}
},
{
"id": "weekly-code-review",
"schedule": "0 10 * * 1",
"description": "每周一早上 10 点审查项目代码变更",
"skill": "code-review-assistant",
"deliver_to": {
"platform": "discord",
"chat_id": "123456789"
}
},
{
"id": "health-check",
"schedule": "*/30 * * * *",
"description": "每 30 分钟检查服务器健康状态",
"skill": "server-health-checker",
"deliver_to": {
"platform": "telegram",
"chat_id": "123456789"
}
}
]
}
Supported schedule formats
| Format | Example | Description |
|---|---|---|
| Cron expression | 0 8 * * * | Standard 5-field cron expression |
| Interval | 30m | Every 30 minutes |
| Relative time | +90s | Run once after 90 seconds |
| Repeat count | repeat.times: 5 | Stop automatically after 5 executions |
You can configure it in the desktop version, click the schedule in the bottom-left corner:

Click Create New Scheduled Task:

Create a task:

After a scheduled task is bound to a Skill, its output is automatically formatted to the output format defined by the Skill. This ensures that when scheduled task results are delivered to a messaging platform, they are presented consistently and readably.
Chronos managed Cron (advanced)
Chronos is Hermes's managed scheduled-task solution, designed for scale-to-zero deployments.
When your Gateway stops completely while idle, Chronos can still ensure scheduled tasks trigger on time.
Why do you need Chronos?
The built-in cron ticker requires the Gateway process to keep running - if the Gateway scales to zero, scheduled tasks will not trigger.
Chronos delegates scheduled-task management to NAS (Nous Account Service), using an external scheduler to wake the Gateway when a task triggers.
Chronos workflow
The Chronos workflow has four steps:
Step 1: the Agent computes the next trigger time and registers a one-shot timer with NAS.
Step 2: NAS uses an external scheduler (such as Fly Machines' scheduled triggers) to fire a callback at the specified time.
Step 3: the external scheduler calls back to NAS, and NAS generates a short-lived JWT Token.
Step 4: NAS uses the JWT Token to call the Agent's /api/cron/fire endpoint; after the Agent verifies it, it runs the task and re-registers the next one-shot.
At-most-once guarantee
Chronos guarantees each scheduled task runs only once through store-level CAS (Compare-And-Set) operations.
Even if the scheduler sends duplicate trigger requests due to network retries, the Agent deduplicates via CAS to ensure the task is not executed twice.
Configure Chronos
Example
config.yaml - Chronos managed Cron configuration
cron
:
provider
:
"chronos"
Use Chronos instead of the built-in ticker
chronos
:
portal_url
:
"https://portal.nousresearch.com"
callback_url
:
"https://my-agent.fly.dev"
The Agent's publicly accessible URL
expected_audience
:
"agent:inst_abc123"
The audience for JWT verification
nas_jwks_url
:
"https://portal.nousresearch.com/.well-known/jwks.json"
Chronos is the recommended scheduled-task solution for managed Hermes deployments. If you use a self-hosted deployment where the Gateway does not scale to zero, the built-in cron ticker is sufficient. If callback_url is empty or the Agent has no Nous login, the system automatically falls back to the built-in ticker.