From 65dab1baa73f710bd399f2ca8c7661e7cd6fb46d Mon Sep 17 00:00:00 2001 From: MervinPraison Date: Mon, 10 Mar 2025 06:02:45 +0000 Subject: [PATCH] Add Langchain external search tool examples for PraisonAI agents - Introduced example scripts for Brave Search, Google Trends, and SerpAPI - Demonstrated multi-agent workflows using external search tools - Added API key configuration instructions for each search tool - Included examples of research and content generation agents using search capabilities --- examples/tools/langchain/brave-search.py | 18 ++++++++++++++++++ examples/tools/langchain/google-trends.py | 18 ++++++++++++++++++ examples/tools/langchain/serp-api.py | 12 ++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 examples/tools/langchain/brave-search.py create mode 100644 examples/tools/langchain/google-trends.py create mode 100644 examples/tools/langchain/serp-api.py diff --git a/examples/tools/langchain/brave-search.py b/examples/tools/langchain/brave-search.py new file mode 100644 index 00000000..14d0fdb2 --- /dev/null +++ b/examples/tools/langchain/brave-search.py @@ -0,0 +1,18 @@ +# pip install langchain-community +# export BRAVE_SEARCH_API=your_api_key_here +# export OPENAI_API_KEY=your_api_key_here + +from praisonaiagents import Agent, PraisonAIAgents +from langchain_community.tools import BraveSearch +import os + +def search_brave(query: str): + """Searches using BraveSearch and returns results.""" + api_key = os.environ['BRAVE_SEARCH_API'] + tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={"count": 3}) + return tool.run(query) + +data_agent = Agent(instructions="Search about AI job trends in 2025", tools=[search_brave]) +editor_agent = Agent(instructions="Write a blog article") +agents = PraisonAIAgents(agents=[data_agent, editor_agent]) +agents.start() \ No newline at end of file diff --git a/examples/tools/langchain/google-trends.py b/examples/tools/langchain/google-trends.py new file mode 100644 index 00000000..32ba7ebd --- /dev/null +++ b/examples/tools/langchain/google-trends.py @@ -0,0 +1,18 @@ +# pip install langchain-community google-search-results +# export SERPAPI_API_KEY=your_api_key_here +# export OPENAI_API_KEY=your_api_key_here + +from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper +from praisonaiagents import Agent, PraisonAIAgents + +research_agent = Agent( + instructions="Research trending topics related to AI", + tools=[GoogleTrendsAPIWrapper] +) + +summarise_agent = Agent( + instructions="Summarise findings from the research agent", +) + +agents = PraisonAIAgents(agents=[research_agent, summarise_agent]) +agents.start() \ No newline at end of file diff --git a/examples/tools/langchain/serp-api.py b/examples/tools/langchain/serp-api.py new file mode 100644 index 00000000..230a2901 --- /dev/null +++ b/examples/tools/langchain/serp-api.py @@ -0,0 +1,12 @@ +# pip install langchain-community google-search-results +# export SERPAPI_API_KEY=your_api_key_here +# export OPENAI_API_KEY=your_api_key_here + +from praisonaiagents import Agent, PraisonAIAgents +from langchain_community.utilities import SerpAPIWrapper + +data_agent = Agent(instructions="Search about AI job trends in 2025", tools=[SerpAPIWrapper]) +editor_agent = Agent(instructions="Write a blog article") + +agents = PraisonAIAgents(agents=[data_agent, editor_agent]) +agents.start() \ No newline at end of file