Skip to main content

CrewAI integration for MCAL - Goal-aware memory for AI agent crews

Project description

mcal-ai-crewai

Goal-aware memory integration for CrewAI agent crews, powered by MCAL.

Installation

pip install mcal-ai-crewai

This installs mcal-ai and crewai as dependencies.

Quick Start

Using MCALStorage with CrewAI Memory

MCAL provides a storage backend that integrates directly with CrewAI's memory system:

from crewai import Crew, Agent, Task, Process
from crewai.memory.short_term.short_term_memory import ShortTermMemory
from crewai.memory.long_term.long_term_memory import LongTermMemory
from crewai.memory.entity.entity_memory import EntityMemory
from mcal_crewai import MCALStorage

# Create MCAL-backed memories
short_term = ShortTermMemory(
    storage=MCALStorage(type="short_term", user_id="john")
)
long_term = LongTermMemory(
    storage=MCALStorage(type="long_term", user_id="john")
)
entity_memory = EntityMemory(
    storage=MCALStorage(type="entities", user_id="john")
)

# Use with CrewAI
crew = Crew(
    agents=[agent],
    tasks=[task],
    memory=True,
    short_term_memory=short_term,
    long_term_memory=long_term,
    entity_memory=entity_memory,
)

Using External Memory

For cross-session persistence with goal awareness:

from crewai.memory.external.external_memory import ExternalMemory
from mcal_crewai import MCALStorage

external = ExternalMemory(
    embedder_config={
        "provider": "mcal",
        "config": {
            "user_id": "john",
            "llm_provider": "anthropic",
            "enable_goal_tracking": True,
        }
    }
)

crew = Crew(
    agents=[...],
    tasks=[...],
    external_memory=external,
    process=Process.sequential,
)

What's New in 0.3.0

  • Expanded Relationship Edge Types — 10 new edge types (family, friend, colleague, likes, prefers, lives_in, works_at, etc.) for richer social and personal relationship graphs
  • Key Facts & Entities in Search Contextsearch() now surfaces extracted facts and background entities directly in result.context
  • Improved Chunk Retrieval — More results returned with equal weighting; conversation excerpts prioritized in context
  • Higher Extraction Fidelity — Increased message processing window reduces information loss during ingestion

What's New in 0.2.9

  • Configurable Extraction Profiles — Choose decision (rationale/alternatives/trade-offs), conversational (preferences/relationships), or comprehensive (both)
  • Hybrid Retrieval with ChunkStore — Graph traversal + embedding search for maximum recall
  • FACT/PERSON Node Protection — Graph compaction preserves factual and identity nodes
  • Benchmark Results — Decision profile achieves 93.3% detail retention, 62% token reduction in 150-turn CTO advisor tests
# New v0.2.8 — pass extraction profile via config
storage = MCALStorage(
    type="long_term",
    user_id="project_manager",
    config={
        "llm_provider": "anthropic",
        "extraction_profile": "decision",
        "enable_chunk_store": True,
    }
)

Features

Goal-Aware Memory

Unlike basic memory systems, MCAL tracks user goals and priorities:

storage = MCALStorage(
    type="long_term",
    user_id="project_manager",
    enable_goal_tracking=True,
    config={
        "llm_provider": "anthropic",
        "embedding_provider": "openai",
    }
)

Context Preservation

MCAL maintains reasoning context across agent handoffs:

# Agent 1 saves with context (sync API)
storage.save(
    "Research findings on market trends",
    metadata={
        "agent": "researcher",
        "goal": "market_analysis",
        "confidence": 0.95
    }
)

# Agent 2 retrieves with keyword search
results = storage.search(
    "What do we know about market trends?",
    limit=5,
    score_threshold=0.7
)

TTL Support

Automatic expiration for short-term memories:

storage = MCALStorage(
    type="short_term",
    user_id="session_user",
    default_ttl=3600,  # 1 hour in seconds
)

Thread Safety

All operations are thread-safe via internal RLock, safe for concurrent agent access.

Configuration

Constructor Parameters

Parameter Type Default Description
type str required Memory type: "short_term", "long_term", "entities", "external"
crew Any None Optional CrewAI Crew instance
config dict None Configuration dict (see below)
user_id str "default" User identifier for memory isolation
default_ttl int None Default TTL in seconds
enable_goal_tracking bool True Enable goal extraction from content

Config Dictionary Keys

Key Type Default Description
llm_provider str "anthropic" LLM provider for goal extraction
embedding_provider str "openai" Embedding model provider
storage_path str None Path for persistent storage
user_id str "default" Fallback user_id (constructor param takes priority)

API Reference

MCALStorage

class MCALStorage:
    """MCAL storage backend for CrewAI memory."""
    
    def save(self, value: Any, metadata: dict) -> None:
        """Save value with goal-aware processing."""
    
    def search(
        self, 
        query: str, 
        limit: int = 5, 
        score_threshold: float = 0.6
    ) -> list:
        """Search with keyword matching. Filters expired TTL entries."""
    
    def reset(self) -> None:
        """Clear all stored memories."""
    
    def get_all(self) -> list:
        """Return all non-expired memory items."""
    
    def delete(self, key: str) -> None:
        """Delete a specific memory entry by key."""

Note: MCALMemoryStorage is available as a backward-compatible alias for MCALStorage.

Comparison with Mem0

Feature Mem0 MCAL
Basic Memory
Goal Tracking
Priority Extraction
Context Preservation
TTL Support
Local Storage
Thread Safety
Cloud API Coming

Requirements

  • Python >= 3.11
  • mcal-ai >= 0.2.0
  • crewai >= 0.100.0

License

MIT License

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_crewai-0.4.0.tar.gz (9.4 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_crewai-0.4.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file mcal_ai_crewai-0.4.0.tar.gz.

File metadata

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

File hashes

Hashes for mcal_ai_crewai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d00e79cc1e40f35a26f9e8fcad68d9246ce8efb9990a7b8363bc20075cef32d5
MD5 dbf1ff1b82be4ef4dfa29043c5f8be31
BLAKE2b-256 45437bb042672726fdbeb7be1a819fd3dddad9ffb2c726ab511d86144bce86bc

See more details on using hashes here.

File details

Details for the file mcal_ai_crewai-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: mcal_ai_crewai-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for mcal_ai_crewai-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44146392e29da96f69cb5ab20b0248558dd7a2e1dd81ed95274eb5891e050a92
MD5 2513792acab578093d463a5b7525cfc8
BLAKE2b-256 2ec69096c638fd0c31c2f997708b7f1d7f106aab7095659755fffbc928b61221

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