Skip to main content
History injection is enabled via memory presets like memory="history" or memory=MemoryConfig(history=True).
Session history is preserved even across long conversations — see Retention Policies for how overflow is summarised and archived.
When history is replayed into an OpenAI model that uses the Responses API path (gpt-4o, gpt-4.1, gpt-5, o1/o3/o4, chatgpt-4o), assistant turns with tool_calls may carry content as a plain string, a list of text parts, None, or an empty list — all shapes are translated transparently. Multimodal list content with tool_calls was fixed in PraisonAI PR #5695; earlier versions raised AttributeError on that shape. See OpenAI → Transparent Responses API routing for the full behaviour.
On the same Responses API path, tool results whose tool_call_id has no matching assistant function_call in the same payload are dropped before the Responses request is built. This is the normal shape when history trimming removes the assistant turn but keeps its tool reply, or when a new user turn follows a tool round from an earlier session. Fixed in PraisonAI PR #5682; on earlier versions the Responses API rejected the payload with No tool call found for function call output with call_id … and the client silently fell back to Chat Completions. See OpenAI → Fallback is quieter now.

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
The user returns to a session; prior messages are injected before the model runs.

Quick Start

1

Simple Usage

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, use MemoryConfig:
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 using auto_save, the session ID is automatically used for history:

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=10
  • memory="chat" → enabled with limit=20
  • memory=MemoryConfig(history=True, history_limit=N) → custom limit
2

Message Building

When _build_messages() is called:
  1. System prompt is added
  2. Session history is injected (if enabled)
  3. In-memory chat history is added
  4. 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

Use memory="history" (10 messages) to avoid token bloat. More history means more tokens and higher cost.
Always use session IDs like user-{user_id} for multi-user apps via auto_save.
Use auto_save to persist conversations and memory="history" to reload them. Repeated turns persist incrementally.
Monitor token usage when enabling history to ensure costs stay reasonable.

Comparison

Use memory="history" for conversation continuity with reasonable context. Use memory="chat" for longer conversational context.

Memory

Full memory system with backends

Sessions

Session management and persistence