Building an AI Wikipedia Racer with Hyperbrowser
In this cookbook, we'll create an AI agent that can play the Wikipedia racing game autonomously. Wikipedia racing challenges players to navigate from one Wikipedia article to another using only internal links - no search, no back button, just strategic link navigation.
What makes this example fascinating is that successful Wikipedia racing requires:
- Strategic thinking to plot a path between seemingly unrelated topics
- Understanding of conceptual connections between different knowledge domains
- Ability to scan pages quickly for relevant links
- Decision-making about which paths might lead to the target fastest
Using Hyperbrowser's browser use agent, we'll create an AI that can tackle this challenge entirely on its own - demonstrating how AI can navigate complex information spaces using the same interfaces humans use.
Prerequisites
Before starting, you'll need:
- A Hyperbrowser API key (sign up at hyperbrowser.ai if you don't have one)
- Python 3.9+ installed
- The dotenv package for loading environment variables
Store your API key in a .env file in the same directory as this notebook:
HYPERBROWSER_API_KEY=your_hyperbrowser_key_here
Step 1: Import Libraries and Initialize Hyperbrowser
We start by importing the necessary packages and initializing our environment. The key components we'll use:
AsyncHyperbrowser
: For asynchronous communication with the Hyperbrowser APIStartBrowserUseTaskParams
: For configuring the autonomous browsing taskIPython.display
: For rendering the results in the notebook
The dotenv library helps us securely load our API key from the environment file.
import osfrom dotenv import load_dotenvfrom hyperbrowser import AsyncHyperbrowserfrom hyperbrowser.models import StartBrowserUseTaskParamsfrom IPython.display import Markdown, displayload_dotenv()
Step 2: Create a Hyperbrowser Client
Next, we initialize our Hyperbrowser client with the API key we loaded from the environment. This client will handle all communication with Hyperbrowser's services.
hb = AsyncHyperbrowser(api_key=os.getenv("HYPERBROWSER_API_KEY"))
Step 3: Define the Wikipedia Racer Function
Now we define the core function of our application - the Wikipedia racer. This function leverages Hyperbrowser's browser_use agent to autonomously play the Wikipedia game.
The browser_use agent works by:
- Receiving a task described in natural language
- Breaking the task down into a series of browser actions
- Executing those actions while adapting to what it encounters
- Recording its thought process and results
We've configured the agent with a maximum of 20 steps, which should be sufficient for most Wikipedia races while preventing it from getting stuck in endless loops. The task description explicitly requests that the agent track its thought process, not cheat by searching, and report the path it took.
async def wikipedia_racer():resp = await hb.agents.browser_use.start_and_wait(StartBrowserUseTaskParams(task="Go to the https://www.thewikigame.com/ and perform the wikipedia race. Keep a track of your thought process and do not try to cheat by searching. Return to me the the start and end points, and the steps you took to get to the end page.",max_steps=20,))if resp.data is not None:return resp.data.final_resultreturn None
Step 4: Run the Wikipedia Race and Display Results
Finally, we'll execute our function to have the AI agent play the Wikipedia racing game. Behind the scenes, the agent will:
- Navigate to the Wiki Game website
- Identify the starting and target articles for the current challenge
- Develop a strategy to reach the target
- Navigate through Wikipedia articles by selecting links it believes will lead toward the target
- Track its progress and reasoning
- Return a summary of its path from start to finish
The agent must rely on the same interface any human player would use, making this a remarkable demonstration of how AI can engage with complex reasoning tasks in the wild.
response = await wikipedia_racer()if response is not None:display(Markdown(response))else:print("No response from the agent")
How AI Plays the Wikipedia Game
What makes this example particularly interesting is observing how the AI approaches the Wikipedia race. The agent needs to:
-
Develop a high-level strategy: Rather than clicking randomly, effective play requires identifying conceptual bridges between the start and target articles
-
Predict downstream connections: The agent must evaluate links not just for their immediate relevance, but for what further connections they might enable
-
Balance exploration vs. exploitation: Sometimes moving through seemingly unrelated topics is necessary to reach broader hub articles that connect to the target
-
Learn from dead ends: If a path doesn't seem to be working, the agent needs to backtrack and try alternative routes
Unlike traditional web scraping or automation, this task demands genuine reasoning about knowledge graphs and conceptual relationships between topics - a form of meta-knowledge about how Wikipedia's content is structured and connected.
Conclusion
In this cookbook, we've built an AI agent capable of autonomously playing the Wikipedia racing game. This demonstrates how Hyperbrowser's browser_use agent can engage with websites exactly as humans do - understanding context, making strategic decisions, and adapting to what it encounters.
What's particularly notable is that the agent's success in this task requires genuine reasoning about relationships between knowledge domains and strategic navigation through an information space. This represents a fascinating glimpse into how AI can engage with the web not just as a source of data, but as an interactive environment that requires planning and strategic thinking.