-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add WhatsApp and Perplexity MCP Integrations #443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
| <Steps> | ||
| <Step title="Set API Key"> | ||
| Set your Perplexity API key as an environment variable in your terminal: | ||
| ```bash | ||
| export PERPLEXITY_API_KEY=your_perplexity_api_key_here | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Create a file"> | ||
| 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) | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Install Dependencies"> | ||
| Make sure you have the required packages installed: | ||
| ```bash | ||
| pip install "praisonaiagents[llm]" | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Run the Agent"> | ||
| Execute your script: | ||
| ```bash | ||
| python perplexity_search.py | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - Perplexity API key | ||
| </Note> | ||
|
|
||
| ## Features | ||
|
|
||
| <CardGroup cols={2}> | ||
| <Card title="Web Search" icon="globe"> | ||
| Search the web for real-time information using Perplexity's powerful search API. | ||
| </Card> | ||
| <Card title="Sonar Model" icon="radar"> | ||
| Utilize Perplexity's Sonar model for high-quality search results. | ||
| </Card> | ||
| <Card title="MCP Integration" icon="plug"> | ||
| Seamless integration with Model Context Protocol. | ||
| </Card> | ||
| <Card title="Environment Variables" icon="key"> | ||
| Securely pass API keys using environment variables. | ||
| </Card> | ||
| </CardGroup> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
| <Steps> | ||
| <Step title="Set Up WhatsApp MCP Server"> | ||
| 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 | ||
| ``` | ||
| </Step> | ||
| <Step title="Create a file"> | ||
| 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
|
|
||
| whatsapp_agent.start("Send Hello to Mervin Praison") | ||
| ``` | ||
|
|
||
| Note: Replace `/path/to/whatsapp-mcp` with the actual path to your WhatsApp MCP server. | ||
| </Step> | ||
|
|
||
| <Step title="Install Dependencies"> | ||
| Make sure you have the required packages installed: | ||
| ```bash | ||
| pip install "praisonaiagents[llm]" mcp gradio | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ``` | ||
| </Step> | ||
| <Step title="Export API Key"> | ||
| ```bash | ||
| export OPENAI_API_KEY="your_api_key" | ||
| ``` | ||
| </Step> | ||
|
|
||
| <Step title="Run the Agent"> | ||
| Execute your script: | ||
| ```bash | ||
| python whatsapp_message.py | ||
| ``` | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Note> | ||
| **Requirements** | ||
| - Python 3.10 or higher | ||
| - WhatsApp MCP server set up and configured | ||
| </Note> | ||
|
|
||
| ## 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 | ||
|
|
||
| <CardGroup cols={2}> | ||
| <Card title="WhatsApp Messaging" icon="message"> | ||
| Send messages to WhatsApp contacts directly from your AI agent. | ||
| </Card> | ||
| <Card title="Multi-Agent Support" icon="users"> | ||
| Combine WhatsApp with other MCP tools for complex workflows. | ||
| </Card> | ||
| <Card title="Multiple LLM Options" icon="brain"> | ||
| Use with OpenAI, Groq, Ollama, or other supported LLMs. | ||
| </Card> | ||
| <Card title="Gradio UI" icon="window"> | ||
| Create user-friendly interfaces for your WhatsApp integrations. | ||
| </Card> | ||
| </CardGroup> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -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") | ||||||||
| ) | ||||||||
|
Comment on lines
+6
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is hardcoded. It would be better to use an environment variable or a relative path to make the example more portable. Consider using
Suggested change
|
||||||||
|
|
||||||||
| whatsapp_agent.start("Send Hello to Mervin Praison") | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -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") | ||||||||
| ) | ||||||||
|
Comment on lines
+6
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is hardcoded. It would be better to use an environment variable or a relative path to make the example more portable. Consider using
Suggested change
|
||||||||
|
|
||||||||
| whatsapp_agent.start("Send Hello to Mervin Praison") | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -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") | ||||||||
| ) | ||||||||
|
Comment on lines
+12
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is hardcoded. It would be better to use an environment variable or a relative path to make the example more portable. Consider using
Suggested change
|
||||||||
|
|
||||||||
| agents = Agents(agents=[airbnb_agent, whatsapp_agent]) | ||||||||
|
|
||||||||
| agents.start() | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -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") | ||||||||
| ) | ||||||||
|
Comment on lines
+6
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is hardcoded. It would be better to use an environment variable or a relative path to make the example more portable. Consider using
Suggested change
|
||||||||
|
|
||||||||
| whatsapp_agent.start("Send Hello to Mervin Praison. Use send_message tool, recipient and message are the required parameters.") | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example lacks error handling. Add a try-except block to catch potential exceptions, such as
os.getenvreturningNoneor the Perplexity API being unavailable. This will make the example more robust and user-friendly.