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.2.0.tar.gz (53.0 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.2.0-py3-none-any.whl (67.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentbay-1.2.0.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentbay-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e8c95100ec97694a0ea1aa998739bc746d5f3216c985b8bc6572cb6665d7db1e
MD5 4f637f65a72c94b9b7fc96ac2af26113
BLAKE2b-256 94670b429fdd0b761636ea7820cc4c207dc3f33e6b1021ad990a4a22c422d1a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentbay-1.2.0.tar.gz:

Publisher: publish.yml on thomasjumper/agentbay-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: agentbay-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 67.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentbay-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bc1d2e51108600479fadf4b65479270353e9143be4dee0e0ba96eac0bd75fa6
MD5 bd235d87451b8d1295cb169e62a782fc
BLAKE2b-256 2bf106a2360befcc6884a5dbc0598f83396c43f3de479ea4c023b03adcec17e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentbay-1.2.0-py3-none-any.whl:

Publisher: publish.yml on thomasjumper/agentbay-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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