Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ContextLoom is the shared "brain" for multi-agent systems. It weaves together memory threads from frameworks like DSPy and CrewAI into a unified, persistent context, powered by Redis and hydrated from your existing databases.

Notifications You must be signed in to change notification settings

danielckv/ContextLoom

Repository files navigation

ContextLoom 🧶

License: MIT Python 3.10+ Redis

High-performance, persistence-layer agnostic memory context awareness for Multi-Agent Systems.

ContextLoom is an open-source framework designed to decouple Memory from Compute. It creates a shared, persistent "Context State" residing in Redis that allows disparate LLM frameworks (DSPy, CrewAI, Agno, Google ADK) to share awareness, maintain continuity, and handle "Cold Start" data pulls from traditional databases.

image

🚀 Why ContextLoom?

Building multi-agent systems often results in "amnesic" architectures where:

  1. Context is siloed: An agent in CrewAI doesn't know what a DSPy module just optimized.
  2. Cold starts are hard: Injecting historical customer data from Postgres into a fresh agent session is manual and brittle.
  3. Cycles are broken: Long-running conversation flows lose coherence as context windows fill up or sessions time out.

ContextLoom acts as the cerebral cortex for your agents—a centralized, high-speed memory store that persists the state of the conversation cycle, not just the logs.

✨ Key Features

  • ⚡ Redis-First Architecture: Leverages Redis for sub-millisecond context retrieval and state updates, ensuring agents don't lag.
  • 🔌 Universal Connectors: "Cold Start" your context by pulling initial state automatically from PostgreSQL, MySQL, or MongoDB.
  • 🤝 Framework Agnostic: Native wrappers for:
    • DSPy (Signatures & Modules)
    • CrewAI (Agent Memory & Task Output)
    • Agno (Workflow State)
    • Google GenAI SDK (ADK)
  • 🔄 Cycle Management: Intelligent handling of communication loops to prevent repetition and ensure goal progression.

🧠 The "Cycle" of Communication

ContextLoom introduces the concept of Communication Cycles to maintain smarter agents.

In standard LLM interactions, context is linear. In ContextLoom, context is Cyclic and State-Aware:

  1. Ingest (Cold Start): The framework hydrates the Redis session with relevant entities from your SQL/NoSQL source (e.g., User Profile, last 5 orders).
  2. Interaction Phase: Agents read the GlobalContext. A CrewAI researcher adds findings; a DSPy optimizer refines the prompt based on that finding.
  3. State Snapshotting: After every interaction turn, ContextLoom calculates a "Cycle Hash".
    • Why this helps: If an agent begins looping (repeating logic), ContextLoom detects the duplicate hash and flags the agent to pivot strategies.
  4. Persistence: The updated state is pushed back to Redis, ready for the next agent, even if that agent is running on a different server or framework.

🛠️ Installation

pip install contextloom

💻 Usage Example

  1. Initialize with specific Backend
from contextloom import Loom, PostgresConnector

# Connect to Redis (Memory) and Postgres (History)
loom = Loom(
    memory_backend="redis://localhost:6379",
    data_source=PostgresConnector("postgresql://user:pass@localhost:5432/mydb")
)
  1. Hydrate & Run with DSPy
import dspy

# Create a session ID
session_id = "user_123_cycle_4"

# Pull data from Postgres automatically into Redis Context
context = loom.hydrate(session_id, query="SELECT * FROM users WHERE id=123")

# DSPy Integration
class IntentClassifier(dspy.Signature):
    """Classify user intent based on Loom Context."""
    context_snapshot = dspy.InputField(desc="Current state from Redis")
    user_query = dspy.InputField()
    intent = dspy.OutputField()

# The agent is now "Aware" of the DB data without manual injection
result = dspy.Predict(IntentClassifier)(
    context_snapshot=context.get_current_state(), 
    user_query="Where is my order?"
)

# Update the Loom Cycle
loom.update_cycle(session_id, step="classification", data=result)

Architecture

image

About

ContextLoom is the shared "brain" for multi-agent systems. It weaves together memory threads from frameworks like DSPy and CrewAI into a unified, persistent context, powered by Redis and hydrated from your existing databases.

Topics

Resources

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages