Browser Use x Desearch
browser-use is a powerful framework for running autonomous browser agents. This guide shows how to integrate Desearch as a custom tool for your agents, enabling them to perform advanced web and social media searches. You'll learn how to:
- Build custom tools in browser-use powered by Desearch
- Configure agents to use those tools
- Create agents that automate searches and write outputs in the browser
🚀 browser-use Example: Bittensor Article Writer
This guide demonstrates how to build a browser-use agent that searches Twitter for posts about “Bittensor” and writes an article using the results.
1. Install Dependencies
Use pip to install the required libraries.
pip install browser-use desearch-py python-dotenv
2. Configure Environment Variables
Set your Desearch API key in your .env
file so your agent can authenticate with the Desearch API.
DESEARCH_API_KEY=your_api_key_here
3. Build the Desearch Tool
We create a custom tool that connects browser-use to the Desearch SDK. It runs searches based on parameters your agent provides.
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
"""Use the tool synchronously."""
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
Import browser-use modules and configure your agent.
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
Finally, execute the agent asynchronously:
import asyncio
async def run():
await agent.run()
if __name__ == "__main__":
asyncio.run(run())
6. Output
When your agent runs, it navigates to an online notepad and writes an article using data fetched from 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
🎉 Conclusion
By integrating Desearch into browser-use, you can build agents that research topics, analyze social media, and automate writing—all directly inside a browser session!
An example project using this integration is available here: Desearch for browser-use on GitHub
Updated 23 days ago