Skip to main content

Persistent memory for AI agents. Store, recall, and share knowledge across sessions.

Project description

AgentBay Python SDK

Persistent memory for AI agents. 3 lines to give your agent a brain.

Install

pip install agentbay

Quick Start -- Auto-Memory (Recommended)

The chat() method wraps your LLM call with automatic memory. No manual store/recall needed.

from agentbay import AgentBay

brain = AgentBay("ab_live_your_key", project_id="your-project-id")

# Memory happens automatically -- no manual store/recall needed
response = brain.chat([
    {"role": "user", "content": "fix the auth session expiry bug"}
])

# brain.chat() automatically:
# 1. Recalled relevant memories about auth and sessions
# 2. Injected them into the LLM context
# 3. Got the response from Claude
# 4. Extracted learnings and stored them for next time

Using OpenAI

response = brain.chat(
    [{"role": "user", "content": "refactor the payment module"}],
    model="gpt-4o",
    provider="openai",
)

Passing extra LLM parameters

response = brain.chat(
    [{"role": "user", "content": "optimize the database queries"}],
    max_tokens=8192,
    temperature=0.7,
)

Disabling auto-memory

# Recall only (don't store new learnings)
response = brain.chat(messages, auto_store=False)

# Store only (don't inject recalled memories)
response = brain.chat(messages, auto_recall=False)

# No memory at all (just use as a plain LLM wrapper)
response = brain.chat(messages, auto_recall=False, auto_store=False)

Mem0-Compatible API

If you're migrating from Mem0, AgentBay supports the same add() / search() interface:

brain = AgentBay("ab_live_your_key", project_id="your-project-id")

# Store with automatic type detection
brain.add("The auth bug was caused by expired JWT tokens not being refreshed")
brain.add("We decided to use PostgreSQL instead of MongoDB for ACID compliance")

# Search
results = brain.search("authentication issues")
for r in results:
    print(r["title"], r["confidence"])

Manual Memory Control

For full control, use store() and recall() directly:

from agentbay import AgentBay

brain = AgentBay("ab_live_your_key", project_id="your-project-id")
brain.store("Next.js 16 + Prisma + PostgreSQL", title="Project stack")
results = brain.recall("What stack does this project use?")

Or create a new brain on the fly:

from agentbay import AgentBay

brain = AgentBay("ab_live_your_key")
brain.setup_brain("My Agent's Memory")
brain.store("Always use UTC timestamps", title="Convention", type="PREFERENCE")

Core API

Method What it does
brain.chat(messages, model, provider, ...) LLM call with automatic memory
brain.add(data) Store with auto-detection (Mem0-compatible)
brain.search(query) Search memories (Mem0-compatible alias)
brain.store(content, title, type, tier, tags) Save a memory (full control)
brain.recall(query, limit, tier, tags) Search memories (semantic + keyword)
brain.forget(knowledge_id) Archive a memory
brain.verify(knowledge_id) Confirm a memory is still accurate
brain.health() Get memory stats
brain.setup_brain(name, description) Create a new Knowledge Brain

Memory Types

  • PATTERN -- Learned behaviors and recurring themes
  • FACT -- Verified information
  • PREFERENCE -- User/agent preferences
  • PROCEDURE -- Step-by-step processes
  • CONTEXT -- Situational context
  • PITFALL -- Bugs, errors, and fixes to avoid
  • DECISION -- Architecture and design decisions

With CrewAI

pip install agentbay[crewai]
from crewai import Agent
from agentbay.integrations.crewai import AgentBayCrewAIMemory

memory = AgentBayCrewAIMemory(
    api_key="ab_live_your_key",
    project_id="your-project-id",
)

agent = Agent(
    role="Researcher",
    goal="Find and remember information",
    memory=memory,
)

With LangChain

pip install agentbay[langchain]
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from agentbay.integrations.langchain import AgentBayMemoryTool

tool = AgentBayMemoryTool(
    api_key="ab_live_your_key",
    project_id="your-project-id",
)

llm = ChatOpenAI()
agent = initialize_agent(
    tools=[tool],
    llm=llm,
    agent=AgentType.OPENAI_FUNCTIONS,
)
agent.run("Remember that deploys happen every Tuesday at 2pm UTC")

Error Handling

from agentbay import AgentBayError, AuthenticationError, RateLimitError

try:
    results = brain.recall("query")
except AuthenticationError:
    print("Bad API key")
except RateLimitError:
    print("Slow down")
except AgentBayError as e:
    print(f"Error {e.status_code}: {e}")

Environment Variables

For chat(), set your LLM provider API key:

# For Anthropic (default provider)
export ANTHROPIC_API_KEY=sk-ant-...

# For OpenAI
export OPENAI_API_KEY=sk-...

Or pass it directly:

response = brain.chat(messages, api_key="sk-ant-...")

Links

Community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentbay-1.5.1.tar.gz (76.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentbay-1.5.1-py3-none-any.whl (88.8 kB view details)

Uploaded Python 3

File details

Details for the file agentbay-1.5.1.tar.gz.

File metadata

  • Download URL: agentbay-1.5.1.tar.gz
  • Upload date:
  • Size: 76.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for agentbay-1.5.1.tar.gz
Algorithm Hash digest
SHA256 4d1fbd8a6210508537a1835731aae02ced9e371c682ff682d7e75c0592aa9985
MD5 571b254df32f9b12f96cedd03a7e7d1c
BLAKE2b-256 3c0aaa4d7033f66c3f1237d8a0c96fae36a71bcd9e829901dce9989e31e34d68

See more details on using hashes here.

File details

Details for the file agentbay-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: agentbay-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 88.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for agentbay-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 187af2e8eb5c68e76c916b9f022ea03260a0d57611518cbe6696b4a66c04a21c
MD5 3867af25efe7066fda18c40ad1a99f26
BLAKE2b-256 a2bfebb5e23cc03d79cbb5af09109eacbcb1b372c17018bf19113d06d1972553

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page