repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: CrewAI |
| #3 | --- |
| #4 | |
| #5 | Build an AI system that combines CrewAI's agent-based architecture with Mem0's memory capabilities. This integration enables persistent memory across agent interactions and personalized task execution based on user history. |
| #6 | |
| #7 | ## Overview |
| #8 | |
| #9 | In this guide, we'll create a CrewAI agent that: |
| #10 | 1. Uses CrewAI to manage AI agents and tasks |
| #11 | 2. Leverages Mem0 to store and retrieve conversation history |
| #12 | 3. Creates personalized experiences based on stored user preferences |
| #13 | |
| #14 | ## Setup and Configuration |
| #15 | |
| #16 | Install necessary libraries: |
| #17 | |
| #18 | ```bash |
| #19 | pip install crewai crewai-tools mem0ai |
| #20 | ``` |
| #21 | |
| #22 | Import required modules and set up configurations: |
| #23 | |
| #24 | <Note>Remember to get your API keys from [Mem0 Platform](https://app.mem0.ai), [OpenAI](https://platform.openai.com) and [Serper Dev](https://serper.dev) for search capabilities.</Note> |
| #25 | |
| #26 | ```python |
| #27 | import os |
| #28 | from mem0 import MemoryClient |
| #29 | from crewai import Agent, Task, Crew, Process |
| #30 | from crewai_tools import SerperDevTool |
| #31 | |
| #32 | # Configuration |
| #33 | os.environ["MEM0_API_KEY"] = "your-mem0-api-key" |
| #34 | os.environ["OPENAI_API_KEY"] = "your-openai-api-key" |
| #35 | os.environ["SERPER_API_KEY"] = "your-serper-api-key" |
| #36 | |
| #37 | # Initialize Mem0 client |
| #38 | client = MemoryClient() |
| #39 | ``` |
| #40 | |
| #41 | ## Store User Preferences |
| #42 | |
| #43 | Set up initial conversation and preferences storage: |
| #44 | |
| #45 | ```python |
| #46 | def store_user_preferences(user_id: str, conversation: list): |
| #47 | """Store user preferences from conversation history""" |
| #48 | client.add(conversation, user_id=user_id) |
| #49 | |
| #50 | # Example conversation storage |
| #51 | messages = [ |
| #52 | { |
| #53 | "role": "user", |
| #54 | "content": "Hi there! I'm planning a vacation and could use some advice.", |
| #55 | }, |
| #56 | { |
| #57 | "role": "assistant", |
| #58 | "content": "Hello! I'd be happy to help with your vacation planning. What kind of destination do you prefer?", |
| #59 | }, |
| #60 | {"role": "user", "content": "I am more of a beach person than a mountain person."}, |
| #61 | { |
| #62 | "role": "assistant", |
| #63 | "content": "That's interesting. Do you like hotels or Airbnb?", |
| #64 | }, |
| #65 | {"role": "user", "content": "I like Airbnb more."}, |
| #66 | ] |
| #67 | |
| #68 | store_user_preferences("crew_user_1", messages) |
| #69 | ``` |
| #70 | |
| #71 | ## Create CrewAI Agent |
| #72 | |
| #73 | Define an agent with memory capabilities: |
| #74 | |
| #75 | ```python |
| #76 | def create_travel_agent(): |
| #77 | """Create a travel planning agent with search capabilities""" |
| #78 | search_tool = SerperDevTool() |
| #79 | |
| #80 | return Agent( |
| #81 | role="Personalized Travel Planner Agent", |
| #82 | goal="Plan personalized travel itineraries", |
| #83 | backstory="""You are a seasoned travel planner, known for your meticulous attention to detail.""", |
| #84 | allow_delegation=False, |
| #85 | memory=True, |
| #86 | tools=[search_tool], |
| #87 | ) |
| #88 | ``` |
| #89 | |
| #90 | ## Define Tasks |
| #91 | |
| #92 | Create tasks for your agent: |
| #93 | |
| #94 | ```python |
| #95 | def create_planning_task(agent, destination: str): |
| #96 | """Create a travel planning task""" |
| #97 | return Task( |
| #98 | description=f"""Find places to live, eat, and visit in {destination}.""", |
| #99 | expected_output=f"A detailed list of places to live, eat, and visit in {destination}.", |
| #100 | agent=agent, |
| #101 | ) |
| #102 | ``` |
| #103 | |
| #104 | ## Set Up Crew |
| #105 | |
| #106 | Configure the crew with memory integration: |
| #107 | |
| #108 | ```python |
| #109 | def setup_crew(agents: list, tasks: list): |
| #110 | """Set up a crew with Mem0 memory integration""" |
| #111 | return Crew( |
| #112 | agents=agents, |
| #113 | tasks=tasks, |
| #114 | process=Process.sequential, |
| #115 | memory=True, |
| #116 | memory_config={ |
| #117 | "provider": "mem0", |
| #118 | "config": {"user_id": "crew_user_1"}, |
| #119 | } |
| #120 | ) |
| #121 | ``` |
| #122 | |
| #123 | ## Main Execution Function |
| #124 | |
| #125 | Implement the main function to run the travel planning system: |
| #126 | |
| #127 | ```python |
| #128 | def plan_trip(destination: str, user_id: str): |
| #129 | # Create agent |
| #130 | travel_agent = create_travel_agent() |
| #131 | |
| #132 | # Create task |
| #133 | planning_task = create_planning_task(travel_agent, destination) |
| #134 | |
| #135 | # Setup crew |
| #136 | crew = setup_crew([travel_agent], [planning_task]) |
| #137 | |
| #138 | # Execute and return results |
| #139 | return crew.kickoff() |
| #140 | |
| #141 | # Example usage |
| #142 | if __name__ == "__main__": |
| #143 | result = plan_trip("San Francisco", "crew_user_1") |
| #144 | print(result) |
| #145 | ``` |
| #146 | |
| #147 | ## Key Features |
| #148 | |
| #149 | 1. **Persistent Memory**: Uses Mem0 to maintain user preferences and conversation history |
| #150 | 2. **Agent-Based Architecture**: Leverages CrewAI's agent system for task execution |
| #151 | 3. **Search Integration**: Includes SerperDev tool for real-world information retrieval |
| #152 | 4. **Personalization**: Utilizes stored preferences for tailored recommendations |
| #153 | |
| #154 | ## Benefits |
| #155 | |
| #156 | 1. **Persistent Context & Memory**: Maintains user preferences and interaction history across sessions |
| #157 | 2. **Flexible & Scalable Design**: Easily extendable with new agents, tasks, and capabilities |
| #158 | |
| #159 | ## Conclusion |
| #160 | |
| #161 | By combining CrewAI with Mem0, you can create sophisticated AI systems that maintain context and provide personalized experiences while leveraging the power of autonomous agents. |
| #162 | |
| #163 | <CardGroup cols={2}> |
| #164 | <Card title="AutoGen Integration" icon="users" href="/integrations/autogen"> |
| #165 | Build multi-agent systems with AutoGen and Mem0 |
| #166 | </Card> |
| #167 | <Card title="LangGraph Integration" icon="diagram-project" href="/integrations/langgraph"> |
| #168 | Create stateful agent workflows with memory |
| #169 | </Card> |
| #170 | </CardGroup> |
| #171 | |
| #172 |