MemoryStackMemoryStack/Documentation

    Multi-Agent Systems with Neural Weave

    Build collaborative AI systems where multiple agents share knowledge and work together seamlessly.

    Overview

    Multi-agent systems allow you to create teams of specialized AI agents that can collaborate, share memories, and solve complex problems together. Neural Weave provides the memory infrastructure to enable seamless agent coordination.

    Key Concepts

    • Shared Memory: Agents can access and contribute to a common memory pool
    • Agent Scoping: Control which memories each agent can access
    • Memory Handoffs: Transfer context between agents efficiently
    • Team Coordination: Enable agents to build on each other's work

    Basic Example

    from memorystack import MemoryStackClient
    
    # Initialize client
    client = MemoryStackClient(api_key="your-api-key")
    
    # Agent 1: Research Agent
    research_memory = client.create_memory(
        messages=[{
            "role": "assistant",
            "content": "Found key insights about market trends..."
        }],
        user_id="research-agent"
    )
    
    # Agent 2: Analysis Agent (accesses research agent's memory)
    analysis_context = client.search_memories(
        query="market trends",
        user_id="research-agent"
    )
    
    # Use the context for analysis
    analysis_memory = client.create_memory(
        messages=[{
            "role": "assistant",
            "content": f"Based on research: {analysis_context}..."
        }],
        user_id="analysis-agent"
    )

    Advanced Patterns

    1. Sequential Agent Handoffs

    Pass context from one agent to the next in a pipeline:

    # Agent pipeline: Research → Analysis → Report
    agents = ["researcher", "analyst", "reporter"]
    
    for i, agent in enumerate(agents):
        if i > 0:
            # Get context from previous agent
            context = client.search_memories(
                query="latest findings",
                user_id=agents[i-1]
            )
        
        # Process and store results
        result = process_with_agent(agent, context)
        client.create_memory(
            messages=[{"role": "assistant", "content": result}],
            user_id=agent
        )

    2. Parallel Agent Collaboration

    Multiple agents work simultaneously and share findings:

    import asyncio
    
    async def agent_task(agent_id, task):
        # Each agent works independently
        result = await process_task(task)
        
        # Store in shared memory
        client.create_memory(
            messages=[{"role": "assistant", "content": result}],
            user_id=agent_id
        )
    
    # Run agents in parallel
    await asyncio.gather(
        agent_task("agent-1", task1),
        agent_task("agent-2", task2),
        agent_task("agent-3", task3)
    )
    
    # Aggregate results
    all_findings = client.search_memories(
        query="findings",
        user_id=None  # Search across all agents
    )

    Best Practices

    • Use descriptive user_id values to identify agents
    • Implement proper error handling for agent failures
    • Monitor memory usage across your agent team
    • Use metadata to track agent interactions and handoffs
    • Implement access controls for sensitive agent data

    Integration Examples

    Neural Weave works seamlessly with popular agent frameworks:

    Next Steps