From 083411bfc6e87b637b4498c72c385b8cf66c2479 Mon Sep 17 00:00:00 2001 From: MervinPraison Date: Wed, 2 Apr 2025 09:54:02 +0100 Subject: [PATCH] Add WhatsApp and Perplexity MCP Integrations - Included new MCP tools for WhatsApp and Perplexity in `mint.json` for enhanced functionality. - Updated installation instructions in `openrouter.mdx` and `xai.mdx` to specify the correct package format. - Added detailed documentation for WhatsApp and Perplexity integrations, including setup steps and example scripts. - Incremented version number to 0.0.72 in `pyproject.toml` and `uv.lock` to reflect recent changes. --- docs/mcp/openrouter.mdx | 2 +- docs/mcp/perplexity.mdx | 91 +++++++++++ docs/mcp/whatsapp.mdx | 185 +++++++++++++++++++++++ docs/mcp/xai.mdx | 2 +- docs/mint.json | 2 + examples/mcp/perplexity-mcp.py | 14 ++ examples/mcp/whatapp-groq-mcp.py | 9 ++ examples/mcp/whatapp-mcp.py | 9 ++ examples/mcp/whatapp-multi-agents-mcp.py | 17 +++ examples/mcp/whatapp-ollama-mcp.py | 9 ++ examples/mcp/whatsapp-mcp-ui.py | 31 ++++ src/praisonai-agents/pyproject.toml | 11 +- src/praisonai-agents/uv.lock | 10 +- 13 files changed, 385 insertions(+), 7 deletions(-) create mode 100644 docs/mcp/perplexity.mdx create mode 100644 docs/mcp/whatsapp.mdx create mode 100644 examples/mcp/perplexity-mcp.py create mode 100644 examples/mcp/whatapp-groq-mcp.py create mode 100644 examples/mcp/whatapp-mcp.py create mode 100644 examples/mcp/whatapp-multi-agents-mcp.py create mode 100644 examples/mcp/whatapp-ollama-mcp.py create mode 100644 examples/mcp/whatsapp-mcp-ui.py diff --git a/docs/mcp/openrouter.mdx b/docs/mcp/openrouter.mdx index 4ee37a27a..8fe060eac 100644 --- a/docs/mcp/openrouter.mdx +++ b/docs/mcp/openrouter.mdx @@ -48,7 +48,7 @@ flowchart LR Make sure you have Node.js installed, as the MCP server requires it: ```bash - pip install praisonaiagents + pip install "praisonaiagents[llm]" ``` diff --git a/docs/mcp/perplexity.mdx b/docs/mcp/perplexity.mdx new file mode 100644 index 000000000..de0e051ef --- /dev/null +++ b/docs/mcp/perplexity.mdx @@ -0,0 +1,91 @@ +--- +title: "Perplexity MCP Integration" +sidebarTitle: "Perplexity" +description: "Guide for integrating Perplexity search with PraisonAI agents using MCP" +icon: "magnifying-glass" +--- + +## Add Perplexity Search Tool to AI Agent + +```mermaid +flowchart LR + In[In] --> Agent[AI Agent] + Agent --> Tool[Perplexity MCP] + Tool --> Agent + Agent --> Out[Out] + + style In fill:#8B0000,color:#fff + style Agent fill:#2E8B57,color:#fff + style Tool fill:#4B0082,color:#fff + style Out fill:#8B0000,color:#fff +``` + +## Quick Start + + + + Set your Perplexity API key as an environment variable in your terminal: + ```bash + export PERPLEXITY_API_KEY=your_perplexity_api_key_here + ``` + + + + Create a new file `perplexity_search.py` with the following code: + ```python + from praisonaiagents import Agent, MCP + import os + + # Get API key from environment variable + api_key = os.getenv("PERPLEXITY_API_KEY") + + agent = Agent( + instructions="You are a helpful assistant that can search the web for information. Use the available tools when relevant to answer user questions.", + llm="gpt-4o-mini", + tools=MCP("uvx perplexity-mcp", + env={"PERPLEXITY_API_KEY": api_key, "PERPLEXITY_MODEL": "sonar" }) + ) + + result = agent.start("What is the latest news on AI?, Pass only the query parameter to the tool") + + print(result) + ``` + + + + Make sure you have the required packages installed: + ```bash + pip install "praisonaiagents[llm]" + ``` + + + + Execute your script: + ```bash + python perplexity_search.py + ``` + + + + + **Requirements** + - Python 3.10 or higher + - Perplexity API key + + +## Features + + + + Search the web for real-time information using Perplexity's powerful search API. + + + Utilize Perplexity's Sonar model for high-quality search results. + + + Seamless integration with Model Context Protocol. + + + Securely pass API keys using environment variables. + + diff --git a/docs/mcp/whatsapp.mdx b/docs/mcp/whatsapp.mdx new file mode 100644 index 000000000..246a13339 --- /dev/null +++ b/docs/mcp/whatsapp.mdx @@ -0,0 +1,185 @@ +--- +title: "WhatsApp MCP Integration" +sidebarTitle: "WhatsApp" +description: "Guide for integrating WhatsApp messaging with PraisonAI agents using MCP" +icon: "whatsapp" +--- + +## Add WhatsApp Tool to AI Agent + +```mermaid +flowchart LR + In[In] --> Agent[AI Agent] + Agent --> Tool[WhatsApp MCP] + Tool --> Agent + Agent --> Out[Out] + + style In fill:#8B0000,color:#fff + style Agent fill:#2E8B57,color:#fff + style Tool fill:#25D366,color:#fff + style Out fill:#8B0000,color:#fff +``` + +## Quick Start + + + + Clone and set up the WhatsApp MCP server: + ```bash + git clone https://github.com/lharries/whatsapp-mcp.git + cd whatsapp-mcp + cd whatsapp-bridge + go run main.go + ``` + + + Create a new file `whatsapp_message.py` with the following code: + ```python + from praisonaiagents import Agent, MCP + + whatsapp_agent = Agent( + instructions="Whatsapp Agent", + llm="gpt-4o-mini", + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") + ) + + whatsapp_agent.start("Send Hello to Mervin Praison") + ``` + + Note: Replace `/path/to/whatsapp-mcp` with the actual path to your WhatsApp MCP server. + + + + Make sure you have the required packages installed: + ```bash + pip install "praisonaiagents[llm]" mcp gradio + ``` + + + ```bash + export OPENAI_API_KEY="your_api_key" + ``` + + + + Execute your script: + ```bash + python whatsapp_message.py + ``` + + + + + **Requirements** + - Python 3.10 or higher + - WhatsApp MCP server set up and configured + + +## Multi-Agent Integration + +You can also combine WhatsApp with other MCP tools, such as Airbnb search: + +```python +from praisonaiagents import Agent, Agents, MCP + +airbnb_agent = Agent( + instructions="""Search for Apartments in Paris for 2 nights on Airbnb. 04/28 - 04/30 for 2 adults""", + llm="gpt-4o-mini", + tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") +) + +whatsapp_agent = Agent( + instructions="""Send AirBnb Search Result to 'Mervin Praison'""", + llm="gpt-4o-mini", + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +agents = Agents(agents=[airbnb_agent, whatsapp_agent]) + +agents.start() +``` + +## Alternative LLM Integrations + +### Using Groq with WhatsApp + +```python +from praisonaiagents import Agent, MCP + +whatsapp_agent = Agent( + instructions="Whatsapp Agent", + llm="groq/llama-3.2-90b-vision-preview", + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +whatsapp_agent.start("Send Hello to Mervin Praison") +``` + +### Using Ollama with WhatsApp + +```python +from praisonaiagents import Agent, MCP + +whatsapp_agent = Agent( + instructions="Whatsapp Agent", + llm="ollama/llama3.2", + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +whatsapp_agent.start("Send Hello to Mervin Praison. Use send_message tool, recipient and message are the required parameters.") +``` + +## Gradio UI Integration + +Create a Gradio UI for your WhatsApp and Airbnb integration: + +```python +from praisonaiagents import Agent, Agents, MCP +import gradio as gr + +def search_airbnb(query): + airbnb_agent = Agent( + instructions=query+" on Airbnb", + llm="gpt-4o-mini", + tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") + ) + + whatsapp_agent = Agent( + instructions="""Send AirBnb Search Result to 'Mervin Praison'. Don't include Phone Number in Response, but include the AirBnb Search Result""", + llm="gpt-4o-mini", + tools=MCP("python /path/to/whatsapp-mcp/whatsapp-mcp-server/main.py") + ) + + agents = Agents(agents=[airbnb_agent, whatsapp_agent]) + + result = agents.start() + return f"## Airbnb Search Results\n\n{result}" + +demo = gr.Interface( + fn=search_airbnb, + inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."), + outputs=gr.Markdown(), + title="WhatsApp MCP Agent", + description="Enter your booking requirements below:" +) + +if __name__ == "__main__": + demo.launch() +``` + +## Features + + + + Send messages to WhatsApp contacts directly from your AI agent. + + + Combine WhatsApp with other MCP tools for complex workflows. + + + Use with OpenAI, Groq, Ollama, or other supported LLMs. + + + Create user-friendly interfaces for your WhatsApp integrations. + + diff --git a/docs/mcp/xai.mdx b/docs/mcp/xai.mdx index 1f4dbd5ba..07e27bd30 100644 --- a/docs/mcp/xai.mdx +++ b/docs/mcp/xai.mdx @@ -48,7 +48,7 @@ flowchart LR Make sure you have Node.js installed, as the MCP server requires it: ```bash - pip install praisonaiagents + pip install "praisonaiagents[llm]" ``` diff --git a/docs/mint.json b/docs/mint.json index e3f5aebd8..973b46c99 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -246,6 +246,8 @@ "mcp/anthropic", "mcp/gemini", "mcp/mistral", + "mcp/whatsapp", + "mcp/perplexity", "mcp/ollama-python", "mcp/bravesearch", "mcp/custom", diff --git a/examples/mcp/perplexity-mcp.py b/examples/mcp/perplexity-mcp.py new file mode 100644 index 000000000..5457f460d --- /dev/null +++ b/examples/mcp/perplexity-mcp.py @@ -0,0 +1,14 @@ +from praisonaiagents import Agent, MCP +import os + +api_key = os.getenv("PERPLEXITY_API_KEY") + +agent = Agent( + instructions="You are a helpful assistant that can search the web for information. Use the available tools when relevant to answer user questions.", + llm="gpt-4o-mini", + tools=MCP("uvx perplexity-mcp", + env={"PERPLEXITY_API_KEY": api_key, "PERPLEXITY_MODEL": "sonar" }) +) +result = agent.start("What is the latest news on AI?, Pass only the query parameter to the tool") + +print(result) \ No newline at end of file diff --git a/examples/mcp/whatapp-groq-mcp.py b/examples/mcp/whatapp-groq-mcp.py new file mode 100644 index 000000000..6b8a0162b --- /dev/null +++ b/examples/mcp/whatapp-groq-mcp.py @@ -0,0 +1,9 @@ +from praisonaiagents import Agent, MCP + +whatsapp_agent = Agent( + instructions="Whatsapp Agent", + llm="groq/llama-3.2-90b-vision-preview", + tools=MCP("python /Users/praison/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +whatsapp_agent.start("Send Hello to Mervin Praison") \ No newline at end of file diff --git a/examples/mcp/whatapp-mcp.py b/examples/mcp/whatapp-mcp.py new file mode 100644 index 000000000..e687bd954 --- /dev/null +++ b/examples/mcp/whatapp-mcp.py @@ -0,0 +1,9 @@ +from praisonaiagents import Agent, MCP + +whatsapp_agent = Agent( + instructions="Whatsapp Agent", + llm="gpt-4o-mini", + tools=MCP("python /Users/praison/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +whatsapp_agent.start("Send Hello to Mervin Praison") \ No newline at end of file diff --git a/examples/mcp/whatapp-multi-agents-mcp.py b/examples/mcp/whatapp-multi-agents-mcp.py new file mode 100644 index 000000000..4acbb1279 --- /dev/null +++ b/examples/mcp/whatapp-multi-agents-mcp.py @@ -0,0 +1,17 @@ +from praisonaiagents import Agent, Agents, MCP + +airbnb_agent = Agent( + instructions="""Search for Apartments in Paris for 2 nights on Airbnb. 04/28 - 04/30 for 2 adults""", + llm="gpt-4o-mini", + tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") +) + +whatsapp_agent = Agent( + instructions="""Send AirBnb Search Result to 'Mervin Praison'""", + llm="gpt-4o-mini", + tools=MCP("python /Users/praison/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +agents = Agents(agents=[airbnb_agent, whatsapp_agent]) + +agents.start() \ No newline at end of file diff --git a/examples/mcp/whatapp-ollama-mcp.py b/examples/mcp/whatapp-ollama-mcp.py new file mode 100644 index 000000000..600fe92b0 --- /dev/null +++ b/examples/mcp/whatapp-ollama-mcp.py @@ -0,0 +1,9 @@ +from praisonaiagents import Agent, MCP + +whatsapp_agent = Agent( + instructions="Whatsapp Agent", + llm="ollama/llama3.2", + tools=MCP("python /Users/praison/whatsapp-mcp/whatsapp-mcp-server/main.py") +) + +whatsapp_agent.start("Send Hello to Mervin Praison. Use send_message tool, recipient and message are the required parameters.") \ No newline at end of file diff --git a/examples/mcp/whatsapp-mcp-ui.py b/examples/mcp/whatsapp-mcp-ui.py new file mode 100644 index 000000000..21670d8be --- /dev/null +++ b/examples/mcp/whatsapp-mcp-ui.py @@ -0,0 +1,31 @@ +from praisonaiagents import Agent, Agents, MCP +import gradio as gr + +def search_airbnb(query): + airbnb_agent = Agent( + instructions=query+" on Airbnb", + llm="gpt-4o-mini", + tools=MCP("npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt") + ) + + whatsapp_agent = Agent( + instructions="""Send AirBnb Search Result to 'Mervin Praison'. Don't include Phone Number in Response, but include the AirBnb Search Result""", + llm="gpt-4o-mini", + tools=MCP("python /Users/praison/whatsapp-mcp/whatsapp-mcp-server/main.py") + ) + + agents = Agents(agents=[airbnb_agent, whatsapp_agent]) + + result = agents.start() + return f"## Airbnb Search Results\n\n{result}" + +demo = gr.Interface( + fn=search_airbnb, + inputs=gr.Textbox(placeholder="I want to book an apartment in Paris for 2 nights..."), + outputs=gr.Markdown(), + title="WhatsApp MCP Agent", + description="Enter your booking requirements below:" +) + +if __name__ == "__main__": + demo.launch() \ No newline at end of file diff --git a/src/praisonai-agents/pyproject.toml b/src/praisonai-agents/pyproject.toml index 8173dd24b..f30b01c9a 100644 --- a/src/praisonai-agents/pyproject.toml +++ b/src/praisonai-agents/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "praisonaiagents" -version = "0.0.71" +version = "0.0.72" description = "Praison AI agents for completing complex tasks with Self Reflection Agents" authors = [ { name="Mervin Praison" } @@ -13,10 +13,14 @@ dependencies = [ "pydantic", "rich", "openai", - "mcp==1.6.0" + "mcp>=1.6.0" ] [project.optional-dependencies] +mcp = [ + "mcp>=1.6.0" +] + memory = [ "chromadb>=0.5.23" ] @@ -38,5 +42,6 @@ llm = [ all = [ "praisonaiagents[memory]", "praisonaiagents[knowledge]", - "praisonaiagents[llm]" + "praisonaiagents[llm]", + "praisonaiagents[mcp]" ] \ No newline at end of file diff --git a/src/praisonai-agents/uv.lock b/src/praisonai-agents/uv.lock index c648fd728..7e09a110b 100644 --- a/src/praisonai-agents/uv.lock +++ b/src/praisonai-agents/uv.lock @@ -1896,7 +1896,7 @@ wheels = [ [[package]] name = "praisonaiagents" -version = "0.0.71" +version = "0.0.72" source = { editable = "." } dependencies = [ { name = "mcp" }, @@ -1911,6 +1911,7 @@ all = [ { name = "chromadb" }, { name = "litellm" }, { name = "markitdown" }, + { name = "mcp" }, { name = "mem0ai" }, { name = "pydantic" }, ] @@ -1924,6 +1925,9 @@ llm = [ { name = "litellm" }, { name = "pydantic" }, ] +mcp = [ + { name = "mcp" }, +] memory = [ { name = "chromadb" }, ] @@ -1935,11 +1939,13 @@ requires-dist = [ { name = "chromadb", marker = "extra == 'memory'", specifier = ">=0.5.23" }, { name = "litellm", marker = "extra == 'llm'", specifier = ">=1.50.0" }, { name = "markitdown", marker = "extra == 'knowledge'" }, - { name = "mcp", specifier = "==1.6.0" }, + { name = "mcp", specifier = ">=1.6.0" }, + { name = "mcp", marker = "extra == 'mcp'", specifier = ">=1.6.0" }, { name = "mem0ai", marker = "extra == 'knowledge'", specifier = ">=0.1.0" }, { name = "openai" }, { name = "praisonaiagents", extras = ["knowledge"], marker = "extra == 'all'" }, { name = "praisonaiagents", extras = ["llm"], marker = "extra == 'all'" }, + { name = "praisonaiagents", extras = ["mcp"], marker = "extra == 'all'" }, { name = "praisonaiagents", extras = ["memory"], marker = "extra == 'all'" }, { name = "pydantic" }, { name = "pydantic", marker = "extra == 'llm'", specifier = ">=2.4.2" },