Skip to content
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

Add Langchain external search tool examples for PraisonAI agents #407

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

MervinPraison
Copy link
Owner

  • 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

- 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
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces example scripts for integrating PraisonAI agents with external search tools from Langchain. It demonstrates how to use Brave Search, Google Trends, and SerpAPI within multi-agent workflows. The examples include instructions for configuring API keys and showcase research and content generation agents leveraging search capabilities.

Highlights

  • New Examples: Added example scripts for Brave Search, Google Trends, and SerpAPI integrations with PraisonAI agents.
  • Multi-Agent Workflows: Demonstrated multi-agent workflows utilizing external search tools for research and content generation.
  • API Key Configuration: Included instructions for configuring API keys for each search tool to enable the examples.

Changelog

Click here to see the changelog
  • examples/tools/langchain/brave-search.py
    • Created a new script demonstrating Brave Search integration.
    • Implemented a search_brave function to query Brave Search with a specified API key.
    • Configured a data agent to search for AI job trends and an editor agent to write a blog article.
    • Lines 1-3: Added installation and environment variable setup instructions.
    • Lines 5-7: Imported necessary modules from praisonaiagents and langchain_community.
    • Lines 9-13: Defined the search_brave function to perform the search.
    • Lines 15-18: Created data and editor agents and started the PraisonAIAgents workflow.
  • examples/tools/langchain/google-trends.py
    • Created a new script demonstrating Google Trends integration.
    • Utilized GoogleTrendsAPIWrapper from langchain_community to research trending AI topics.
    • Configured a research agent to find trending topics and a summarise agent to summarise the findings.
    • Lines 1-3: Added installation and environment variable setup instructions.
    • Lines 5-6: Imported necessary modules from langchain_community and praisonaiagents.
    • Lines 8-11: Created a research agent with instructions to research trending AI topics.
    • Lines 13-15: Created a summarise agent with instructions to summarise the research findings.
    • Lines 17-18: Started the PraisonAIAgents workflow with the research and summarise agents.
  • examples/tools/langchain/serp-api.py
    • Created a new script demonstrating SerpAPI integration.
    • Utilized SerpAPIWrapper from langchain_community to search for AI job trends.
    • Configured a data agent to search for AI job trends and an editor agent to write a blog article.
    • Lines 1-3: Added installation and environment variable setup instructions.
    • Lines 5-6: Imported necessary modules from praisonaiagents and langchain_community.
    • Lines 8-9: Created data and editor agents.
    • Lines 11-12: Started the PraisonAIAgents workflow with the data and editor agents.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Did you know?

The term 'API' was first used in the context of computing in the 1960s, long before the internet became widespread.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@MervinPraison MervinPraison merged commit f3035db into main Mar 10, 2025
4 of 6 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces example scripts for integrating Langchain external search tools (Brave Search, Google Trends, and SerpAPI) with PraisonAI agents. The examples demonstrate multi-agent workflows using these tools and provide instructions for API key configuration. Overall, this is a valuable addition to the project, providing users with practical examples of how to leverage external search capabilities within PraisonAI agents.

Summary of Findings

  • Missing Error Handling: The search_brave function in brave-search.py lacks error handling for the os.environ['BRAVE_SEARCH_API'] call. If the environment variable is not set, the program will crash. This should be addressed to improve the robustness of the example.
  • Inconsistent Tool Usage: In google-trends.py, GoogleTrendsAPIWrapper is passed directly as a tool, while in brave-search.py and serp-api.py, a function wrapping the tool is used. This inconsistency should be addressed for clarity and maintainability.
  • Missing API Key Instructions: The google-trends.py example is missing instructions on how to obtain the SERPAPI_API_KEY, which is necessary for the script to function correctly. This should be added to ensure users can easily run the example.

Merge Readiness

The pull request introduces valuable examples for integrating Langchain external search tools with PraisonAI agents. However, there are a few issues that need to be addressed before merging. Specifically, the missing error handling in brave-search.py and the inconsistent tool usage across the examples should be fixed. Additionally, the missing API key instructions in google-trends.py should be added. I am unable to approve this pull request, and recommend that it not be merged until these issues are addressed (at a minimum), and that others review and approve this code before merging.

Comment on lines +11 to +13
api_key = os.environ['BRAVE_SEARCH_API']
tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={"count": 3})
return tool.run(query)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Consider adding error handling to check if the BRAVE_SEARCH_API environment variable is set. If it's not set, the program will crash. You can use os.getenv with a default value or raise an exception with a helpful message.

Suggested change
api_key = os.environ['BRAVE_SEARCH_API']
tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={"count": 3})
return tool.run(query)
api_key = os.getenv('BRAVE_SEARCH_API')
if not api_key:
raise ValueError("BRAVE_SEARCH_API environment variable not set.")
tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={"count": 3})

Comment on lines +1 to +3
# pip install langchain-community google-search-results
# export SERPAPI_API_KEY=your_api_key_here
# export OPENAI_API_KEY=your_api_key_here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's good to include the installation and environment variable setup instructions, but it's missing instructions on how to obtain the SERPAPI_API_KEY.

Suggested change
# pip install langchain-community google-search-results
# export SERPAPI_API_KEY=your_api_key_here
# export OPENAI_API_KEY=your_api_key_here
# pip install langchain-community google-search-results
# export SERPAPI_API_KEY=your_api_key_here # Get your API key from https://serpapi.com/
# export OPENAI_API_KEY=your_api_key_here

Comment on lines +8 to +10
research_agent = Agent(
instructions="Research trending topics related to AI",
tools=[GoogleTrendsAPIWrapper]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the other examples (brave-search.py and serp-api.py), consider wrapping GoogleTrendsAPIWrapper in a function.

Suggested change
research_agent = Agent(
instructions="Research trending topics related to AI",
tools=[GoogleTrendsAPIWrapper]
def google_trends_search(query: str):
"""Searches Google Trends and returns results."""
tool = GoogleTrendsAPIWrapper()
return tool.run(query)
research_agent = Agent(
instructions="Research trending topics related to AI",
tools=[google_trends_search]
)

Copy link

netlify bot commented Mar 10, 2025

Deploy Preview for praisonai canceled.

Name Link
🔨 Latest commit 65dab1b
🔍 Latest deploy log https://app.netlify.com/sites/praisonai/deploys/67ce8098b2fdab000806319e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant