Sessions provide conversation context while memory enables long-term knowledge retention. Together, they create intelligent, personalized agent interactions that improve over time!
Understanding Sessions
Think of sessions as your agent’s short-term memory during a conversation!Conversation History
Every message between your agent and user is tracked
Context Preservation
State persists across multiple interactions
State Storage
Keep track of important conversation data
Memory Links
Connect to long-term agent memory
Creating and Managing Sessions
Using Sessions with Agents
Let’s see how easy it is to maintain conversations across multiple interactions!app/Http/Controllers/ChatController.php
Session Models
Sessions are first-class citizens in Vizra, stored safely in your database!AgentContext Magic
TheAgentContext is your Swiss Army knife for session management!
app/Agents/MyAgent.php
Memory System
Give your agents the gift of memory! Vizra provides persistent memory across sessions through the powerfulAgentMemory model and MemoryManager service:
Session State
Short-term context stored in AgentContext during a conversation - like working memory!
Agent Memory
Long-term memory with learnings, facts, and session summaries - like permanent storage!
Using Persistent Memory
Agent Memory API
Every agent now has a built-in memory system that’s super easy to use!app/Agents/SupportAgent.php
Memory Methods
The agent memory API provides specialized methods for different types of information:Memory Manager Service
For advanced use cases, you can still access the Memory Manager directly:app/Services/AgentService.php
Using Memory Tool
Agents can manage their own memory - how cool is that?app/Agents/SupportAgent.php
Memory Context in Instructions
Inject past memories into your agent’s instructions for truly personalized interactions!Memory Model Structure
Let’s peek under the hood! TheAgentMemory model is beautifully organized:
Memory Properties
database/agent_memories table
Accessing Memory Data
Working with memory data is a breeze! Check out these handy methods:Session and Memory Integration
Automatic Memory Updates
The magic happens automatically! Sessions and memory work together seamlessly:Memory Extraction
Watch as Vizra intelligently extracts insights from conversations!Memory Lifecycle
Session Summarization
Keep memories fresh and relevant with intelligent summarization!Memory Cleanup
Keep your database tidy with smart cleanup strategies!Implementation Examples
Customer Support Agent
A complete example of a memory-aware support agent that learns and adapts!app/Agents/CustomerSupportAgent.php
Educational Tutor Agent
An agent that tracks learning progress and adapts teaching style!app/Agents/TutorAgent.php
Memory-Aware Agent Base Class
Create a reusable base class for all memory-aware agents:app/Agents/MemoryAwareAgent.php
Session State Management
Store complex data structures in session state - it’s that flexible!Memory Best Practices
Short-term Memory
Use AgentContext for session state
Long-term Memory
Store important facts in AgentMemory
Auto-summarization
Let MemoryManager handle summaries
Agent Control
Use MemoryTool for self-management
Cleanup Strategy
Implement cleanup for old sessions
Context Injection
Include memory in instructions
Next: Workflows
Learn about agent workflows and multi-step processes
Next: Dynamic Prompts
Learn about dynamic prompt versioning and variants