Assistants
Memory
Every Assistant comes with built-in memory that can be used to access the Chat History or LLM Messages. Access the assistant memory using assistant.memory
- Chat History: The messages between the user and LLM.
- LLM Messages: The full list of messages sent to the LLM, including system prompt, tool calls etc.
Example
memory.py
from rich.pretty import pprint
from phi.assistant import Assistant, AssistantMemory
assistant = Assistant()
# -*- Print a response
assistant.print_response("Share a 5 word horror story.")
# -*- Get the memory
memory: AssistantMemory = assistant.memory
# -*- Print Chat History
print("============ Chat History ============")
pprint(memory.chat_history)
# -*- Print LLM Messages
print("============ LLM Messages ============")
pprint(memory.llm_messages)
AssistantMemory only lasts while the session is active. To provide memory across sessions, add Storage
to the Assistant
.