|
|
CrewAI with Memory - Short-Term and Long-Term
Author: Venkata Sudhakar
CrewAI agents can be equipped with memory so they retain context within a session and across sessions. CrewAI provides four memory types: short-term memory (in-context task history within a run), long-term memory (stored in a local SQLite database that persists across runs), entity memory (tracks facts about specific entities like people, places, or products), and contextual memory (combines all three when composing the agent's prompt).
Memory is enabled at the Crew level by passing memory=True to the Crew constructor. When enabled, agents automatically save task outputs to long-term memory and retrieve relevant past context before starting each new task. For ShopMax India, this means an analyst agent can recall the findings from last week's inventory report when writing this week's sales summary, without the user needing to repeat the context.
The following example creates a ShopMax India analytics crew with memory enabled. The second kickoff benefits from the first run's stored findings.
It gives the following output,
ShopMax India Q1 2025 was led by Mumbai with Rs 4.2 crore in revenue, with laptops
dominating sales across all cities. Q2 outlook is strong: laptop demand is expected
to continue as the back-to-school season peaks in May-June across Mumbai and Bangalore.
Memory stored: True
Long-term memory is stored in a .crewai/memory SQLite database in the working directory. You can inspect or clear it by deleting this directory. For production use at ShopMax India, configure a shared database path so all crew instances on different servers share the same memory. Entity memory is especially useful for tracking customer profiles, product SKUs, and supplier details across many agent runs.
|
|