For advanced coordination, use AegisAgentMemory to enable scoped memory and self-improvement patterns:
from aegis_memory.integrations.crewai import AegisAgentMemory, AegisCrewMemorycrew_mem = AegisCrewMemory(api_key="...")# Memory scoped to a specific agent roleresearcher_mem = AegisAgentMemory( crew_memory=crew_mem, agent_id="Researcher", scope="agent-shared")# Store a reflection after a task (ACE pattern)researcher_mem.add_reflection( content="Always verify data sources from .gov sites first", correct_approach="Start with official government databases")# Handoff state to another agentbaton = researcher_mem.handoff_to("Writer", task_context="Data verified")
┌─────────────────────────────────────────────────────────┐│ GLOBAL SCOPE ││ "Always use type hints in Python" ││ Visible to: ALL agents, ALL projects │├─────────────────────────────────────────────────────────┤│ AGENT-SHARED SCOPE ││ "Current task: Build user authentication" ││ Visible to: Specified agents in this project │├──────────────┬──────────────┬───────────────────────────┤│ AGENT-PRIVATE│ AGENT-PRIVATE│ AGENT-PRIVATE ││ Researcher │ Writer │ Reviewer │└──────────────┴──────────────┴───────────────────────────┘
from aegis_memory.integrations.crewai import AegisCrewMemoryfrom crewai import Crew, Agent, Task# Initialize persistent memorymemory = AegisCrewMemory( api_key="your-aegis-key", namespace="market-research")# Define agentsresearcher = Agent( role="Market Researcher", goal="Gather comprehensive market data", backstory="Expert in market analysis with 10 years experience", memory=True)analyst = Agent( role="Data Analyst", goal="Analyze data and identify trends", backstory="Statistical expert specializing in market trends", memory=True)writer = Agent( role="Report Writer", goal="Create clear, actionable reports", backstory="Business writer with Fortune 500 experience", memory=True)# Define tasksresearch_task = Task( description="Research the AI agent market size and growth", expected_output="Market data with sources", agent=researcher)analysis_task = Task( description="Analyze research data for key insights", expected_output="Top 5 market trends with supporting data", agent=analyst)report_task = Task( description="Write executive summary of findings", expected_output="2-page executive summary", agent=writer)# Create and run crew with memorycrew = Crew( agents=[researcher, analyst, writer], tasks=[research_task, analysis_task, report_task], memory=memory, verbose=True)result = crew.kickoff()# Next time you run this crew, it remembers:# - What sources were reliable# - What analysis approaches worked# - What report formats were effective