Browser Use x Desearch

    Browser Use x Desearch

    browser-use runs autonomous browser agents. This page adds Desearch as a custom tool so those agents can search the web and social media.

    browser-use Example: Bittensor Article Writer

    The agent searches Twitter for posts about "Bittensor" and writes an article from the results.


    1. Install Dependencies

    bash
    pip install browser-use desearch-py python-dotenv

    2. Configure Environment Variables

    Set your Desearch API key in your .env file:

    DESEARCH_API_KEY=your_api_key_here

    3. Build the Desearch Tool

    Create a custom tool that connects browser-use to the Desearch SDK:

    python
    from browser_use import Controller, ActionResult from desearch_py import Desearch from pydantic import BaseModel, Field import os controller = Controller() class BasicTwitterSearchToolInput(BaseModel): query: str = Field(description="The Twitter search query.") @controller.action( "Use the Basic Twitter Search tool to perform a search.", param_model=BasicTwitterSearchToolInput, ) def run_basic_twitter_search(params: BasicTwitterSearchToolInput) -> str: query = params.query api_key = os.getenv("DESEARCH_API_KEY") if not api_key: raise ValueError("DESEARCH_API_KEY environment variable not set.") desearch = Desearch(api_key=api_key) try: result = desearch.basic_twitter_search(query=query) return ActionResult(extracted_content=result.__str__()) except Exception as e: return f"An error occurred while calling Desearch: {str(e)}"

    4. Create the Agent

    python
    from browser_use import Agent from browser_use.llm import ChatOpenAI from dotenv import load_dotenv load_dotenv() task = ( "Go to https://www.onlinenotepad.io/ " "and write an article about 'Bittensor' using tweets found via the search tool." ) agent = Agent( task=task, llm=ChatOpenAI(model="gpt-4o"), use_vision=False, max_failures=2, controller=controller, max_actions_per_step=1, )

    5. Run the Agent

    python
    import asyncio async def run(): await agent.run() if __name__ == "__main__": asyncio.run(run())

    6. Output

    The agent navigates to an online notepad and writes an article from the data fetched via Desearch. For example:

    Article Title: Bittensor and Its Growing Impact on AI Bittensor is creating buzz on Twitter as a decentralized network for machine learning. Users discuss how it rewards contributors and builds an open AI ecosystem. Several tweets highlight its innovative economic incentives and potential to democratize AI research. As interest grows, Bittensor is gaining more traction among developers and AI enthusiasts looking for decentralized alternatives to traditional cloud providers. Stay tuned for more insights on how Bittensor might shape the future of decentralized intelligence!

    Further Reading