Agentic sessions in mistral.rs manage state for tool-calls, tool responses, and multimodal payloads (images, videos). This state is stored in memory and reconciled with incoming requests to maintain context across turns.
Session Storage Constraints
- Capacity: The store is bounded to 128 sessions; once exceeded, the least-recently-used (LRU) session is evicted.
- TTL: Sessions have a 30-minute idle Time-To-Live (TTL).
- Persistence: Sessions are stored in process memory only. They do not survive server restarts unless explicitly exported and imported.
Session Matching Logic
Requests match an existing session via:
- Explicit
session_id: A direct lookup using the provided ID. - Content matching: If no
session_id is provided, the engine scans stored sessions and returns the first one where the user-visible message prefix matches the incoming messages. Note that if multiple sessions match, the returned one is arbitrary (not necessarily the longest match).
Splicing and Merging
When a session is matched, the engine performs 'splicing' to merge stored history with the new request:
- Preservation: Tool-role entries and assistant-with-tool-calls entries from stored history are kept.
- Precedence: User and assistant messages from the incoming request take precedence over stored versions.
- Divergence: If incoming messages differ from stored ones, the engine stops consuming stored history at the point of divergence and appends the new messages.
- Multimodal Upgrade: Images and videos from the session are automatically re-attached to the request, upgrading plain-text requests to multimodal shape.