|
| 1 | +""" |
| 2 | +👩💻 Mem0 MCP - Personalized Code Reviewer |
| 3 | +
|
| 4 | +This example demonstrates how to use Agno's MCP integration together with Mem0, to build a personalized code reviewer. |
| 5 | +
|
| 6 | +- Run your Mem0 MCP server. Full instructions: https://github.com/mem0ai/mem0-mcp |
| 7 | +- Run: `pip install agno mcp-sdk` to install the dependencies |
| 8 | +""" |
| 9 | + |
| 10 | +import asyncio |
| 11 | +from textwrap import dedent |
| 12 | + |
| 13 | +from agno.agent import Agent |
| 14 | +from agno.models.openai import OpenAIChat |
| 15 | +from agno.tools.mcp import MCPTools |
| 16 | + |
| 17 | +mcp_server_url = "http://localhost:8080/sse" |
| 18 | + |
| 19 | + |
| 20 | +async def run_agent(message: str) -> None: |
| 21 | + async with MCPTools(url=mcp_server_url, transport="sse") as mcp_tools: |
| 22 | + agent = Agent( |
| 23 | + tools=[mcp_tools], |
| 24 | + model=OpenAIChat(id="o4-mini"), |
| 25 | + instructions=dedent( |
| 26 | + """ |
| 27 | + You are a professional code reviewer. You help users keep their code clean and on line with their preferences. |
| 28 | + You have access to some tools to keep track of coding preferences you need to enforce when reviewing code. |
| 29 | + You will be given a code snippet and you need to review it and provide feedback on it. |
| 30 | + """ |
| 31 | + ), |
| 32 | + ) |
| 33 | + await agent.aprint_response(message, stream=True) |
| 34 | + |
| 35 | + |
| 36 | +if __name__ == "__main__": |
| 37 | + # The agent will use mem0 memory to keep track of the user's preferences. |
| 38 | + asyncio.run( |
| 39 | + run_agent( |
| 40 | + "When possible, use the walrus operator to make the code more readable." |
| 41 | + ) |
| 42 | + ) |
| 43 | + # The agent will review your code and propose improvements based on your preferences. |
| 44 | + asyncio.run( |
| 45 | + run_agent( |
| 46 | + dedent( |
| 47 | + """ |
| 48 | +Please, review this Python snippet: |
| 49 | +
|
| 50 | +```python |
| 51 | +def process_data(data): |
| 52 | + length = len(data) |
| 53 | + if length > 10: |
| 54 | + print(f"Processing {length} items") |
| 55 | + return data[:10] |
| 56 | + return data |
| 57 | +
|
| 58 | +# Example usage |
| 59 | +items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] |
| 60 | +result = process_data(items) |
| 61 | +``` |
| 62 | +""" |
| 63 | + ) |
| 64 | + ) |
| 65 | + ) |
0 commit comments