Give your AI agents persistent, evolving memory across sessions.
pip install elephantasmfrom elephantasm import inject, extract, EventType
# Get memory context for your LLM
pack = inject()
system_prompt = f"You are a helpful assistant.\n\n{pack.as_prompt()}"
# Capture conversation events
extract(EventType.MESSAGE_IN, "Hello!", role="user")
extract(EventType.MESSAGE_OUT, "Hi there!", role="assistant")Set these environment variables:
| Variable | Required | Description |
|---|---|---|
| ELEPHANTASM_API_KEY | Yes | Your API key (starts with sk_live_) |
| ELEPHANTASM_ANIMA_ID | No | Default anima ID for operations |
| ELEPHANTASM_ENDPOINT | No | API endpoint (default: https://api.elephantasm.com) |
| ELEPHANTASM_TIMEOUT | No | Request timeout in seconds (default: 30) |
Retrieves a compiled MemoryPack containing relevant memories, knowledge, and identity context. Use .as_prompt() to inject into your LLM system prompt.
Captures events (messages, tool calls, etc.) for memory synthesis. Events are processed by the Dreamer to form memories, lessons, and knowledge over time.
Your agent entity. Each anima has its own memories, events, knowledge, and identity. Create multiple animas for different agents or users.
A compiled bundle of session memories, long-term memories, knowledge, and identity context optimized for your token budget.
For more control, use the Elephantasm class directly:
from elephantasm import Elephantasm, EventType
# Initialize with credentials
with Elephantasm(api_key="sk_live_...", anima_id="...") as client:
# Get memory pack
pack = client.inject()
# Capture events
client.extract(EventType.MESSAGE_IN, "Hello!", role="user")
# Create a new anima
anima = client.create_anima("my-agent", description="Personal assistant")from elephantasm import EventType
EventType.MESSAGE_IN # User messages
EventType.MESSAGE_OUT # Assistant responses
EventType.TOOL_CALL # Tool invocations
EventType.TOOL_RESULT # Tool outputs
EventType.SYSTEM # System eventsfrom elephantasm import inject
from elephantasm.exceptions import (
AuthenticationError, # 401 - Invalid API key
NotFoundError, # 404 - Anima not found
RateLimitError, # 429 - Too many requests
ValidationError, # 422 - Invalid parameters
ServerError, # 5xx - Server error
)
try:
pack = inject()
except AuthenticationError:
print("Check your ELEPHANTASM_API_KEY")
except NotFoundError:
print("Anima not found - check ELEPHANTASM_ANIMA_ID")
except RateLimitError:
print("Rate limited - retry later")See the examples directory for complete integration patterns:
To use the SDK, you need an API key from your Elephantasm dashboard:
sk_live_)ELEPHANTASM_API_KEY in your environmentQuestions? Open an issue on GitHub or reach out on X: @elephantasm_ai