History injection is enabled via memory presets like
memory="history" or memory=MemoryConfig(history=True).Overview
History injection automatically loads previous conversation messages from a session and includes them in the agent’s context. This enables:- Multi-turn conversations across sessions
- Context continuity when users return
- Persistent memory without complex setup
Quick Start
1
Simple Usage
- Preset (Simple)
- Chat Preset
- Custom Limit
2
With Configuration
Switch presets (memory=“chat”) or use a MemoryConfig for token limits and injection rules — see the remaining tabs.
Memory Presets
Enable history via memory presets:MemoryConfig
For full control, useMemoryConfig:
Default sessions are workspace-scoped — the same agent name in a different project is a different session. See Where sessions live for details and the
PRAISONAI_GLOBAL_SESSIONS opt-out.With auto_save
When usingauto_save, the session ID is automatically used for history:
- MemoryConfig (Recommended)
- Legacy (Deprecated)
How It Works
The user sends a message; the agent loads prior turns from the session store and prepends them to the messages array before calling the model.1
Agent Initialization
History settings are resolved from
memory parameter:memory="history"→ enabled with limit=10memory="chat"→ enabled with limit=20memory=MemoryConfig(history=True, history_limit=N)→ custom limit
2
Message Building
When
_build_messages() is called:- System prompt is added
- Session history is injected (if enabled)
- In-memory chat history is added
- User prompt is added
3
Session Store
History is loaded from the session store using
get_working_history(session_id, max_messages=limit) when the store supports it — this replays a compacted summary + retained tail if a compaction checkpoint exists. Stores that implement only get_chat_history fall back to raw history automatically. See Compacted Session Resume.Per-turn persistence is exact. When
memory="history" (or MemoryConfig(history=True)) is combined with auto_save, each agent turn persists exactly the user message and the assistant response — no duplicates, even on repeated save_state() calls. Fixed in PraisonAI PR #1897.Auto-derived session ids are workspace-scoped. When
history is enabled without an explicit session_id, the id now folds in a workspace identity so same-named agents in different projects don’t share history. Opt out with PRAISONAI_GLOBAL_SESSIONS=true. See Session Resume.Best Practices
Set reasonable limits
Set reasonable limits
Use
memory="history" (10 messages) to avoid token bloat. More history means more tokens and higher cost.Use meaningful session IDs
Use meaningful session IDs
Always use session IDs like
user-{user_id} for multi-user apps via auto_save.Combine with auto_save
Combine with auto_save
Use
auto_save to persist conversations and memory="history" to reload them. Repeated turns persist incrementally.Monitor token usage
Monitor token usage
Monitor token usage when enabling history to ensure costs stay reasonable.
Comparison
Related
Memory
Full memory system with backends
Sessions
Session management and persistence

