Bot Session Reset

Automatically reset bot sessions based on idle time or daily schedule

python
from praisonaiagents import Agent, BotConfig

agent = Agent(name="assistant", instructions="You are a helpful assistant.")
config = BotConfig(session_reset_hours=24)
agent.start("Reset sessions after 24 hours of inactivity.")

The user returns after idle time; session reset clears stale history so the agent starts fresh.

Session reset policies automatically clear bot conversation history after inactivity or at a scheduled time, preventing unbounded context growth.

Diagram

Yes

No

User message

BotSessionManager

_should_reset?

Clear history

Load history

Agent

Quick Start

  1. Idle reset after 30 minutes
    yaml
    channels:
      telegram:
        token: ${TELEGRAM_BOT_TOKEN}
        session:
          reset:
            mode: idle
            idle_minutes: 30
  2. Daily reset at 04:00
    yaml
    channels:
      discord:
        token: ${DISCORD_BOT_TOKEN}
        session:
          reset:
            mode: daily
            at_hour: 4
  3. Combined idle + daily
    yaml
    channels:
      slack:
        token: ${SLACK_BOT_TOKEN}
        app_token: ${SLACK_APP_TOKEN}
        session:
          max_history: 100
          reset:
            mode: both
            idle_minutes: 60
            at_hour: 4

How It Works

Reset checks run in BotSessionManager._load_history() before reusing existing history:

Diagram
AgentBotSessionManagerBotUserAgentBotSessionManagerBotUseralt[Reset needed][Continue session]Message_load_history()_should_reset_session()_clear_session_data()[]existing historyrun with historyresponse

Idle timestamps are tracked per user. Idle timeout uses monotonic time; daily reset uses wall-clock hour.


Reset Modes

ModeBehaviour
noneNo automatic reset (default — backward compatible)
idleReset after N minutes of inactivity
dailyReset at a specific hour each day (0–23)
bothCombine idle and daily reset

Configuration Options

OptionTypeDefaultDescription
modestr"none"One of none, idle, daily, both
idle_minutesint60Minutes of inactivity before reset (≥1). Used when mode includes idle.
at_hourintNoneDaily reset hour (0–23). Required when mode is daily or both.
max_historyint100Maximum history entries (parent session block).

Configure under each channel’s session.reset block in gateway.yaml or bot.yaml.


Common Patterns

Customer support — drop stale conversations when the customer leaves:

yaml
session:
  reset:
    mode: idle
    idle_minutes: 30

Daily briefing bot — fresh start each midnight:

yaml
session:
  reset:
    mode: daily
    at_hour: 0

Compliance bot — idle timeout plus nightly sweep:

yaml
session:
  reset:
    mode: both
    idle_minutes: 15
    at_hour: 2

Best Practices

Session Reset vs Session Reaper

Session Reset Policy (this feature) clears a user’s conversation history based on idle or scheduled time — configured per channel in YAML.

Session Reaper (session_ttl on BotConfig) prunes the in-memory session record of stale users. They solve different problems; use both for long-running bots.

Pair with max_history and session compaction

Combine session.max_history with reset policies to cap context size and cost. Reset clears history entirely; max_history trims retained turns during an active session; session.compaction summarises older turns instead of dropping them. See Bot Session Compaction.

Manual /new command

Users can always send /new for an immediate reset. Manual reset works alongside automatic policies — see Bot Commands.


Related