Baidusearch Tools

Search Baidu in English and Chinese and return the top three results on a topic.

baidusearch_tools.py
"""
Baidusearch Tools
=============================

Demonstrates baidusearch tools.
"""

from agno.agent import Agent
from agno.tools.baidusearch import BaiduSearchTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


agent = Agent(
    tools=[BaiduSearchTools()],
    description="You are a search agent that helps users find the most relevant information using Baidu.",
    instructions=[
        "Given a topic by the user, respond with the 3 most relevant search results about that topic.",
        "Search for 5 results and select the top 3 unique items.",
        "Search in both English and Chinese.",
    ],
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What are the latest advancements in AI?", markdown=True)

The agent is instructed to issue English and Chinese queries and choose three results. The toolkit forwards only the query text and result count to the search library; its language argument does not enforce a language filter. Selection and deduplication are model behavior.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno baidusearch openai pycountry

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as baidusearch_tools.py, then run:

python baidusearch_tools.py

Full source: cookbook/91_tools/baidusearch_tools.py