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: Agno |
| #3 | --- |
| #4 | |
| #5 | This integration of [**Mem0**](https://github.com/mem0ai/mem0) with [Agno](https://github.com/agno-agi/agno) enables persistent, multimodal memory for Agno-based agents - improving personalization, context awareness, and continuity across conversations. |
| #6 | |
| #7 | ## Overview |
| #8 | |
| #9 | 1. Store and retrieve memories from Mem0 within Agno agents |
| #10 | 2. Support for multimodal interactions (text and images) |
| #11 | 3. Semantic search for relevant past conversations |
| #12 | 4. Personalized responses based on user history |
| #13 | 5. One-line memory integration via `Mem0Tools` |
| #14 | |
| #15 | ## Prerequisites |
| #16 | |
| #17 | Before setting up Mem0 with Agno, ensure you have: |
| #18 | |
| #19 | 1. Installed the required packages: |
| #20 | ```bash |
| #21 | pip install agno mem0ai python-dotenv |
| #22 | ``` |
| #23 | |
| #24 | 2. Valid API keys: |
| #25 | - [Mem0 API Key](https://app.mem0.ai/dashboard/api-keys) |
| #26 | - OpenAI API Key (for the agent model) |
| #27 | |
| #28 | ## Quick Integration (Using `Mem0Tools`) |
| #29 | |
| #30 | The simplest way to integrate Mem0 with Agno Agents is to use Mem0 as a tool using built-in `Mem0Tools`: |
| #31 | |
| #32 | ```python |
| #33 | from agno.agent import Agent |
| #34 | from agno.models.openai import OpenAIChat |
| #35 | from agno.tools.mem0 import Mem0Tools |
| #36 | |
| #37 | agent = Agent( |
| #38 | name="Memory Agent", |
| #39 | model=OpenAIChat(id="gpt-4.1-nano-2025-04-14"), |
| #40 | tools=[Mem0Tools()], |
| #41 | description="An assistant that remembers and personalizes using Mem0 memory." |
| #42 | ) |
| #43 | ``` |
| #44 | |
| #45 | This enables memory functionality out of the box: |
| #46 | |
| #47 | - **Persistent memory writing**: `Mem0Tools` uses `MemoryClient.add(...)` to store messages from user-agent interactions, including optional metadata such as user ID or session. |
| #48 | - **Contextual memory search**: Compatible queries use `MemoryClient.search(...)` to retrieve relevant past messages, improving contextual understanding. |
| #49 | - **Multimodal support**: Both text and image inputs are supported, allowing richer memory records. |
| #50 | |
| #51 | > `Mem0Tools` uses the `MemoryClient` under the hood and requires no additional setup. You can customize its behavior by modifying your tools list or extending it in code. |
| #52 | |
| #53 | ## Full Manual Example |
| #54 | |
| #55 | > Note: Mem0 can also be used with Agno Agents as a separate memory layer. |
| #56 | |
| #57 | The following example demonstrates how to create an Agno agent with Mem0 memory integration, including support for image processing: |
| #58 | |
| #59 | ```python |
| #60 | import base64 |
| #61 | from pathlib import Path |
| #62 | from typing import Optional |
| #63 | |
| #64 | from agno.agent import Agent |
| #65 | from agno.media import Image |
| #66 | from agno.models.openai import OpenAIChat |
| #67 | from mem0 import MemoryClient |
| #68 | |
| #69 | # Initialize the Mem0 client |
| #70 | client = MemoryClient() |
| #71 | |
| #72 | # Define the agent |
| #73 | agent = Agent( |
| #74 | name="Personal Agent", |
| #75 | model=OpenAIChat(id="gpt-4"), |
| #76 | description="You are a helpful personal agent that helps me with day to day activities." |
| #77 | "You can process both text and images.", |
| #78 | markdown=True |
| #79 | ) |
| #80 | |
| #81 | |
| #82 | def chat_user( |
| #83 | user_input: Optional[str] = None, |
| #84 | user_id: str = "alex", |
| #85 | image_path: Optional[str] = None |
| #86 | ) -> str: |
| #87 | """ |
| #88 | Handle user input with memory integration, supporting both text and images. |
| #89 | |
| #90 | Args: |
| #91 | user_input: The user's text input |
| #92 | user_id: Unique identifier for the user |
| #93 | image_path: Path to an image file if provided |
| #94 | |
| #95 | Returns: |
| #96 | The agent's response as a string |
| #97 | """ |
| #98 | if image_path: |
| #99 | # Convert image to base64 |
| #100 | with open(image_path, "rb") as image_file: |
| #101 | base64_image = base64.b64encode(image_file.read()).decode("utf-8") |
| #102 | |
| #103 | # Create message objects for text and image |
| #104 | messages = [] |
| #105 | |
| #106 | if user_input: |
| #107 | messages.append({ |
| #108 | "role": "user", |
| #109 | "content": user_input |
| #110 | }) |
| #111 | |
| #112 | messages.append({ |
| #113 | "role": "user", |
| #114 | "content": { |
| #115 | "type": "image_url", |
| #116 | "image_url": { |
| #117 | "url": f"data:image/jpeg;base64,{base64_image}" |
| #118 | } |
| #119 | } |
| #120 | }) |
| #121 | |
| #122 | # Store messages in memory |
| #123 | client.add(messages, user_id=user_id) |
| #124 | print("✅ Image and text stored in memory.") |
| #125 | |
| #126 | if user_input: |
| #127 | # Search for relevant memories |
| #128 | memories = client.search(user_input, user_id=user_id) |
| #129 | memory_context = "\n".join(f"- {m['memory']}" for m in memories['results']) |
| #130 | |
| #131 | # Construct the prompt |
| #132 | prompt = f""" |
| #133 | You are a helpful personal assistant who helps users with their day-to-day activities and keeps track of everything. |
| #134 | |
| #135 | Your task is to: |
| #136 | 1. Analyze the given image (if present) and extract meaningful details to answer the user's question. |
| #137 | 2. Use your past memory of the user to personalize your answer. |
| #138 | 3. Combine the image content and memory to generate a helpful, context-aware response. |
| #139 | |
| #140 | Here is what I remember about the user: |
| #141 | {memory_context} |
| #142 | |
| #143 | User question: |
| #144 | {user_input} |
| #145 | """ |
| #146 | # Get response from agent |
| #147 | if image_path: |
| #148 | response = agent.run(prompt, images=[Image(filepath=Path(image_path))]) |
| #149 | else: |
| #150 | response = agent.run(prompt) |
| #151 | |
| #152 | # Store the interaction in memory |
| #153 | interaction_message = [{"role": "user", "content": f"User: {user_input}\nAssistant: {response.content}"}] |
| #154 | client.add(interaction_message, user_id=user_id) |
| #155 | return response.content |
| #156 | |
| #157 | return "No user input or image provided." |
| #158 | |
| #159 | |
| #160 | # Example Usage |
| #161 | if __name__ == "__main__": |
| #162 | response = chat_user( |
| #163 | "I like to travel and my favorite destination is London", |
| #164 | image_path="travel_items.jpeg", |
| #165 | user_id="alex" |
| #166 | ) |
| #167 | print(response) |
| #168 | ``` |
| #169 | |
| #170 | ## Key Features |
| #171 | |
| #172 | ### 1. Multimodal Memory Storage |
| #173 | |
| #174 | The integration supports storing both text and image data: |
| #175 | |
| #176 | - **Text Storage**: Conversation history is saved in a structured format |
| #177 | - **Image Analysis**: Agents can analyze images and store visual information |
| #178 | - **Combined Context**: Memory retrieval combines both text and visual data |
| #179 | |
| #180 | ### 2. Personalized Agent Responses |
| #181 | |
| #182 | Improve your agent's context awareness: |
| #183 | |
| #184 | - **Memory Retrieval**: Semantic search finds relevant past interactions |
| #185 | - **User Preferences**: Personalize responses based on stored user information |
| #186 | - **Continuity**: Maintain conversation threads across multiple sessions |
| #187 | |
| #188 | ### 3. Flexible Configuration |
| #189 | |
| #190 | Customize the integration to your needs: |
| #191 | |
| #192 | - **Use `Mem0Tools()`** for drop-in memory support |
| #193 | - **Use `MemoryClient` directly** for advanced control |
| #194 | - **User Identification**: Organize memories by user ID |
| #195 | - **Memory Search**: Configure search relevance and result count |
| #196 | - **Memory Formatting**: Support for various OpenAI message formats |
| #197 | |
| #198 | <CardGroup cols={2}> |
| #199 | <Card title="OpenAI Agents SDK" icon="cube" href="/integrations/openai-agents-sdk"> |
| #200 | Build agents with OpenAI SDK and Mem0 |
| #201 | </Card> |
| #202 | <Card title="Mastra Integration" icon="star" href="/integrations/mastra"> |
| #203 | Create intelligent agents with Mastra framework |
| #204 | </Card> |
| #205 | </CardGroup> |
| #206 | |
| #207 |