Wordle Connection
I had not used pydantic before, at least not directly. I am sure projects and LLM SDKs were all using it under the hood. Building agents needed some structure. The common solution that I heard Furqan uses is Microsoft’s Autogen, but I noticed pydantic had just released their AI agent framework, pydantic-ai, and it caused a buzz in the community. But then the big question: try this agent to do what? I didn’t want to build the usual weather app or a chatbot.
Over the Thanksgiving holidays, I saw my extended family play NYT’s Connection game. Initially, I thought it could be fun to have an AI try to solve the connections game, but I found out quickly that AI is not good at that, just from some quick testing.
Going down the connection game path, I tried to play the game a few times and enjoyed it but was annoyed to find the websites that have the answers are riddled with ads and popups. I thought it would be fun to have a website that would have the answers, and AI can read and bring me the answers.
Philosophically, Agents should come to you!
Search and Return data in a structured format
We use the websearch to find the URLs, but the AI agent or the current state of LLMs can’t do that. I could have written a web scraper with Beautiful Soup in Python, but having written my share of automated tests and used Beautiful Soup, I didn’t want to deal with its fragility. I found browser-use, which is a Python library that uses Playwright to do web searches. I found it to be a good fit for the task. They have good documentation, and it was pretty easy to get it working.
browser_task = {system_prompt}
browser = Browser(
config=BrowserConfig(
chrome_instance_path=os.getenv("CHROME_BINARY_PATH", DEFAULT_MAC_CHROME),
)
)
# Setup Browser Agent for web interactions
browser_agent = BrowserAgent(
browser=browser,
task=browser_task,
llm=ChatOpenAI(model="gpt-4o-mini", api_key=OPEN_API_KEY),
)
return await browser_agent.run()
The script is pretty simple: it searches for the URLs and returns the data in a JSON structured format. The system prompt is too verbose to have it here, but its steps are to go to Google, search for URLs from reputable sources, and I give some domains that I know have the right answers updated daily like Mashable, etc., and then I asked it to return the answers in the JSON format below:
[
{"color": "red", "hint": "Hint 1", "category": "Category 1", "answer": "Answer 1"},
{"color": "blue", "hint": "Hint 2", "category": "Category 2", "answer": "Answer 2"},
{"color": "green", "hint": "Hint 3", "category": "Category 3", "answer": "Answer 3"},
{"color": "purple", "hint": "Hint 4", "category": "Category 4", "answer": "Answer 4"}
]
Read the data and return the answers in .md format
Next, I wanted this JSON to be written as an article. The next agent’s task is to read this JSON and write the article in .md format. This writer agent is the pydantic-ai agent. This is a straightforward implementation from the example in the pydantic-ai documentation.
# Setup Pydantic Agent for markdown article generation
pydantic_agent = PydanticAgent(
system_prompt=writer_system_prompt,
model=OpenAIModel(model_name="gpt-4o-mini", api_key=OPEN_API_KEY),
)
result = pydantic_agent.run_sync(
"Here is the JSON with hints, categories and answers for NYT Connections game:\n"
+ words
)
return result.data if hasattr(result, "data") else result
The output of this is now a markdown article.
Publish the website
I used Eleventy to build a static website for these articles. They have really good templates to get started with, and I hosted this website on Netlify.
Finally, I built a GitHub action to run the script and publish the website.
The script generates the article and then uses the following command to publish to Netlify daily:
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Install Node.js dependencies
working-directory: main
run: npm install
- name: Build and Deploy to Netlify
working-directory: main
env:
NETLIFY_AUTH_TOKEN: $
NETLIFY_SITE_ID: $
run: npm run publish:prod && netlify deploy --prod