Bot Session Reset
Automatically reset bot sessions based on idle time or daily schedule
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.
graph LR
U[User message] --> M[BotSessionManager]
M --> R{_should_reset?}
R -->|Yes| C[Clear history]
R -->|No| H[Load history]
C --> A[Agent]
H --> A
A --> U
classDef user fill:#6366F1,stroke:#7C90A0,color:#fff
classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
classDef decision fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
class U user
class M process
class R decision
class C,H,A agentQuick Start
- Idle reset after 30 minutes
yaml channels: telegram: token: ${TELEGRAM_BOT_TOKEN} session: reset: mode: idle idle_minutes: 30 - Daily reset at 04:00
yaml channels: discord: token: ${DISCORD_BOT_TOKEN} session: reset: mode: daily at_hour: 4 - 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:
sequenceDiagram
participant User
participant Bot
participant Manager as BotSessionManager
participant Agent
User->>Bot: Message
Bot->>Manager: _load_history()
Manager->>Manager: _should_reset_session()
alt Reset needed
Manager->>Manager: _clear_session_data()
Manager-->>Bot: []
else Continue session
Manager-->>Bot: existing history
end
Bot->>Agent: run with history
Agent-->>User: responseIdle timestamps are tracked per user. Idle timeout uses monotonic time; daily reset uses wall-clock hour.
Reset Modes
| Mode | Behaviour |
|---|---|
none | No automatic reset (default — backward compatible) |
idle | Reset after N minutes of inactivity |
daily | Reset at a specific hour each day (0–23) |
both | Combine idle and daily reset |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
mode | str | "none" | One of none, idle, daily, both |
idle_minutes | int | 60 | Minutes of inactivity before reset (≥1). Used when mode includes idle. |
at_hour | int | None | Daily reset hour (0–23). Required when mode is daily or both. |
max_history | int | 100 | Maximum 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:
session:
reset:
mode: idle
idle_minutes: 30Daily briefing bot — fresh start each midnight:
session:
reset:
mode: daily
at_hour: 0Compliance bot — idle timeout plus nightly sweep:
session:
reset:
mode: both
idle_minutes: 15
at_hour: 2Best 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.