Skip to main content

LangGraph integration for MCAL - Goal-aware memory for AI agents

Project description

mcal-ai-langgraph

LangGraph integration for MCAL — Goal-aware memory for AI agents.

Installation

pip install mcal-ai-langgraph

This will automatically install mcal-ai and langgraph as dependencies.

Quick Start

from mcal import MCAL
from mcal_langgraph import MCALStore

# Initialize MCAL
mcal = MCAL(llm_provider="anthropic")

# Create LangGraph-compatible store
store = MCALStore(mcal)

# Use with LangGraph
from langgraph.prebuilt import create_react_agent

agent = create_react_agent(
    model=your_model,
    tools=your_tools,
    store=store  # Goal-aware memory!
)

Features

MCALStore (BaseStore)

Drop-in replacement for LangGraph's built-in stores with goal-aware memory:

from mcal_langgraph import MCALStore

store = MCALStore(mcal)

# Store memories
await store.aput(
    namespace=("user_123", "memories"),
    key="decision_1",
    value={"text": "Decided to use PostgreSQL for ACID compliance"}
)

# Goal-aware search — returns memories relevant to current goals
results = await store.asearch(
    namespace_prefix=("user_123",),
    query="database choice"
)

# Results include goal context and decisions
for item in results:
    print(item.value)

MCALMemory

Memory nodes for custom LangGraph workflows:

from mcal_langgraph import MCALMemory

# Initialize with provider (uses get_mcal() factory internally)
memory = MCALMemory(llm_provider="anthropic")

# Or pass an existing MCAL instance
memory = MCALMemory(mcal=mcal, user_id="user_123")

# Add as nodes in your graph
graph.add_node("update_memory", memory.update_node())
graph.add_node("get_context", memory.context_node())

MCALCheckpointer

State persistence for LangGraph graphs:

from mcal_langgraph import MCALCheckpointer

checkpointer = MCALCheckpointer(storage_path="~/.mcal")
graph = builder.compile(checkpointer=checkpointer)

Why mcal-ai-langgraph?

Feature LangGraph InMemoryStore MCALStore
BaseStore interface
Namespace organization
TTL support
Filter operators ($eq, $gt, etc.)
Goal-aware search
Decision tracking
Intent preservation

API Reference

MCALStore

class MCALStore(BaseStore):
    def __init__(self, mcal: MCAL): ...
    
    # Async API
    async def aput(self, namespace, key, value, index=None): ...
    async def aget(self, namespace, key) -> Optional[Item]: ...
    async def adelete(self, namespace, key): ...
    async def asearch(self, namespace_prefix, /, *, query=None, filter=None, limit=10, offset=0) -> list[Item]: ...
    async def alist_namespaces(self, *, prefix=None, suffix=None, max_depth=None, limit=100, offset=0) -> list[tuple[str, ...]]: ...
    
    # Sync API (also available)
    def put(self, namespace, key, value, index=None): ...
    def get(self, namespace, key) -> Optional[Item]: ...
    def delete(self, namespace, key): ...
    def search(self, namespace_prefix, /, *, query=None, filter=None, limit=10, offset=0) -> list[Item]: ...

MCALMemory

class MCALMemory:
    def __init__(
        self,
        mcal: Optional[MCAL] = None,
        llm_provider: str = "anthropic",
        embedding_provider: str = "openai",
        storage_path: Optional[str] = None,
        user_id: str = "default",
        **mcal_kwargs,
    ): ...
    
    def update_node(self) -> Callable: ...
    def context_node(self) -> Callable: ...
    async def add(self, messages, user_id=None): ...
    async def get_context(self, query, user_id=None): ...
    async def search(self, query, user_id=None, limit=5): ...

MCALCheckpointer

class MCALCheckpointer(BaseCheckpointSaver):
    def __init__(self, storage_path: Optional[str] = None): ...
    
    def get(self, config) -> Optional[dict]: ...
    def put(self, config, checkpoint): ...
    def list(self, config) -> list[dict]: ...

Migrating from mcal[langgraph]

If you were using the old extras-based installation:

# Old way (deprecated)
from mcal.integrations.langgraph import MCALStore

# New way (recommended)
from mcal_langgraph import MCALStore

The old import path still works but will show a deprecation warning.

Requirements

  • Python >= 3.11
  • mcal-ai >= 0.2.0
  • langgraph >= 0.2.0
  • langchain-core >= 0.3.0

License

MIT

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

mcal_ai_langgraph-0.2.6.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

mcal_ai_langgraph-0.2.6-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file mcal_ai_langgraph-0.2.6.tar.gz.

File metadata

  • Download URL: mcal_ai_langgraph-0.2.6.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for mcal_ai_langgraph-0.2.6.tar.gz
Algorithm Hash digest
SHA256 bfb2bbce71ed78503168db28b5084ef9b46ce87103da65940655023f038c1ea5
MD5 c546bc6d2fa1dd29758d012cc8f40b80
BLAKE2b-256 82a0188b584662a2078eeabf5360f25e86fb5e88729dade10aa70f3ddd1e7a0a

See more details on using hashes here.

File details

Details for the file mcal_ai_langgraph-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for mcal_ai_langgraph-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 031540d1b25a4b8f173083d8af129e8a68bdf28bd5b0088358bd5ebc4657233a
MD5 679fb8ace885cc514b96fe74c7058f6a
BLAKE2b-256 474d3d2e1274da318a2cda5cb4911dc05a26d233f1ea7aba991ea477d54bbdba

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