v0.4.0 — Persistent agent memory
v0.4.0 — Persistent agent memory
What's new
Persistent agent memory (#24) — the agent now survives restarts and recalls context from past sessions. Conversations can be stored between runs, an agent can be recreated on top of its own history, and relevant fragments of older dialogs are mixed into new ones automatically.
from pathlib import Path
from ember import Agent, FileMemory, OpenAIProvider
memory = FileMemory(Path(".ember/memory"))
agent = Agent(
provider=OpenAIProvider(api_key=os.environ["OPENAI_API_KEY"]),
memory=memory,
session_id="daily-standup",
)
print(agent.run("What did we decide yesterday?")) • New ember.memory subpackage: Memory — abstract storage interface (load_session / save_session / search / delete_session), so you can plug in your own backend (SQLite, Redis, Postgres…). FileMemory(directory) — file-based storage: one JSONL file per session, atomic writes (tmp + rename), sanitized session_id so history can't escape the directory.
• Agent accepts memory + session_id (both or neither, otherwise ValueError): on creation it loads the saved history of the session and keeps working — the agent outlives process restarts.
• Recall from past sessions: each run searches older sessions (bag-of-words) and injects relevant fragments as a separate system message — the conversation history and the store stay untouched. • The conversation is saved after every run() / stream_run(), including exceptions and stream interruptions (try/finally); the system prompt is never stored.
• reset() starts over and rewrites the current session to empty.
• Fully backwards compatible: without memory the agent works exactly as before.
Installation
pip install "emberio-labs-ember" # agent memory is in the core, no extra
needed
pip install "emberio-labs-ember[openai]" # OpenAI-compatible APIs
pip install "emberio-labs-ember[mcp]" # MCP client
Full Changelog: v0.3.0...v0.4.0 PyPI:
https://pypi.org/project/emberio-labs-ember/0.4.0/