Skip to main content

Open source memory & context backend for AI agents

Project description

CrewLayer Python SDK

Open source memory & context backend for AI agents. Persistent memory, action logging, and shared blackboard — all in one REST API.

PyPI Python License: MIT

Source & docs: github.com/GerardSole/CrewLayer


Install

pip install crewlayer

Requires Python 3.12+. Runtime dependency: httpx only.


Quick start

from crewlayer import CrewLayerClient

client = CrewLayerClient(api_key="crwl_...", base_url="http://localhost:8000")

# Persist a message to short-term memory
client.memory.append(agent_id="agent-uuid", role="user", content="I prefer dark mode")

# Semantic recall from long-term memory
results = client.memory.recall(agent_id="agent-uuid", query="UI preferences", limit=5)
for item in results.results:
    print(f"[{item.similarity:.2f}] {item.content}")

# Log an action (full audit trail)
client.actions.log(agent_id="agent-uuid", tool_name="web_search",
                   input_params={"q": "crewlayer"}, status="success", duration_ms=120)

# Shared blackboard between agents
client.context.write(namespace="project-42", key="phase", value={"stage": "planning"})
entry = client.context.read("project-42", "phase")
print(entry.value)   # {"stage": "planning"}

client.close()

Async client

import asyncio
from crewlayer import CrewLayerAsyncClient

async def main():
    async with CrewLayerAsyncClient(api_key="crwl_...") as client:
        await client.memory.append(agent_id="agent-uuid", role="user", content="Hello")
        result = await client.memory.recall(agent_id="agent-uuid", query="greeting")
        print(result.results)

asyncio.run(main())

Integrations

Optional extras bring first-class support for popular AI frameworks. Each integration falls back gracefully when the framework is not installed.

Extra Install What you get
langchain pip install crewlayer[langchain] AgentLayerMemory, AgentLayerVectorStore, AgentLayerCallbackHandler
crewai pip install crewlayer[crewai] AgentLayerMemoryProvider, AgentLayerTaskLogger
llamaindex pip install crewlayer[llamaindex] CrewLayerMemoryBuffer, CrewLayerVectorIndex, CrewLayerQueryEngine, CrewLayerCallbackManager
autogen pip install crewlayer[autogen] CrewLayerConversableAgent, CrewLayerGroupChatManager, CrewLayerAgentMemory, sync_agent_status
all-integrations pip install crewlayer[all-integrations] All of the above

LangChain

from crewlayer import CrewLayerClient
from crewlayer.integrations.langchain import AgentLayerMemory
from langchain.chains import ConversationChain
from langchain_openai import ChatOpenAI

client = CrewLayerClient(api_key="crwl_...")
memory = AgentLayerMemory(client=client, agent_id="agent-uuid", session_id="user-123")
chain = ConversationChain(llm=ChatOpenAI(), memory=memory)
chain.predict(input="What's my name?")

CrewAI

from crewlayer.integrations.crewai import AgentLayerMemoryProvider, AgentLayerTaskLogger
from crewai.memory import LongTermMemory
from crewai import Task

storage = AgentLayerMemoryProvider(client=client, agent_id="agent-uuid")
ltm = LongTermMemory(storage=storage)

logger = AgentLayerTaskLogger(client=client, agent_id="agent-uuid")
task = Task(description="Summarize feedback", expected_output="...", agent=agent, callback=logger)

LlamaIndex

from crewlayer.integrations.llamaindex import CrewLayerVectorIndex
from llama_index.core.schema import Document

index = CrewLayerVectorIndex(client=client, agent_id="agent-uuid", similarity_top_k=4)
index.insert(Document(text="User prefers dark mode"))
engine = index.as_query_engine()
response = engine.query("UI preferences")
print(response.response)

AutoGen (multi-agent blackboard)

The killer feature: CrewLayerGroupChatManager writes every turn to a shared blackboard. Any agent — or external observer — can read live group state without being in the chat.

from crewlayer.integrations.autogen import (
    CrewLayerConversableAgent, CrewLayerGroupChatManager, CrewLayerAgentMemory,
)
import autogen

client = CrewLayerClient(api_key="crwl_...")
researcher = CrewLayerConversableAgent(name="researcher", client=client, agent_id="uuid-r",
                                       llm_config={"config_list": [...]})
writer = CrewLayerConversableAgent(name="writer", client=client, agent_id="uuid-w",
                                   llm_config={"config_list": [...]})

groupchat = autogen.GroupChat(agents=[researcher, writer], messages=[], max_round=10)
manager = CrewLayerGroupChatManager(client=client, group_id="project-alpha", groupchat=groupchat)
CrewLayerAgentMemory(client=client, agent_id="uuid-r").apply(researcher)

researcher.initiate_chat(manager, message="Let's plan the release.")

# From anywhere — see who spoke last
latest = client.context.read("project-alpha", "latest_turn")
print(latest.value)  # {"agent": "writer", "content": "...", "turn": 3}

Error handling

from crewlayer import CrewLayerError, AuthError, NotFoundError, ConflictError, RateLimitError

try:
    client.memory.recall(agent_id="bad-id", query="test")
except AuthError:
    print("Invalid API key")
except NotFoundError:
    print("Agent not found")
except ConflictError as e:
    print(f"Version conflict: {e}")
except RateLimitError:
    print("Rate limited")
except CrewLayerError as e:
    print(f"HTTP {e.status_code}: {e}")

All exceptions expose .status_code (int | None) and .response (dict | None).


Self-hosting

git clone https://github.com/GerardSole/CrewLayer
cd CrewLayer
docker compose up -d       # starts PostgreSQL + Redis
alembic upgrade head
uvicorn main:app --reload  # API at http://localhost:8000

Full documentation: github.com/GerardSole/CrewLayer

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

crewlayer-0.1.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

crewlayer-0.1.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file crewlayer-0.1.0.tar.gz.

File metadata

  • Download URL: crewlayer-0.1.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crewlayer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55ff200fefa011e6c520378bc8282f5de04792c7d4ad5b9b81cb67fcd5fb9aa5
MD5 18a454d3b5d66b05e3c386e81fb8668f
BLAKE2b-256 1cdf92738cdb31e7a6884400a8f58a19386c17a7c0a1f98d15c7780017c19b35

See more details on using hashes here.

File details

Details for the file crewlayer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: crewlayer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crewlayer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f756833eacf191221d32fb186b4d992169f354fd785e1880e225f14e19fb5a3c
MD5 6ce62d962d7061f9346c75e720c0ea15
BLAKE2b-256 8f4a286b96e5220fcde62637239e77e6ea69f5b1cc5b5095574f4d5015773cae

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