Imagine an AI not just answering your questions but rolling up its sleeves to dig through websites and documents, finding and extracting exactly what you need. That's the magic of agents: they don't just process data—they actively reason, adapt, and deliver.
This post is about building a recipe scraping agent using OpenAI Swarm, a minimalist framework that strips away complexity in favor of speed and customization. While it lacked the polish and utilities of tools like Crew AI, Swarm provided the flexibility to craft a solution that met my needs.
Creating an agent with OpenAI Swarm
OpenAI Swarm is a barebones orchestration framework designed to keep things simple. Instead of overwhelming you with features like Crew AI or LangChain, it focuses on doing one thing well: chaining lightweight AI tasks with ease.
First Step: Creating a Google Search Tool
Swarm's minimalist approach means starting from scratch, so the first task was building a Google Search tool to find recipes. Using Google's Custom Search API involved signing up via GCP, configuring a project, and grabbing the SERP ID.
Second Step: A Barebones Scraping Tool
Scraping is a nuanced topic, but for this project, I relied on a simple BeautifulSoup function to extract webpage text. This text was then passed to the next step: the JSON formatter.
Final Step: JSON Formatting with GPT-4
One of the most powerful applications of LLMs is generating structured JSON outputs, as shown in the code block above. By asking an LLM to parse data into a standardized format, we can transform messy input into something usable - in this case, turning raw recipe text into clean, structured JSON.
Agent in Action
Here's a real example of what our agent produces when extracting a recipe for Spaghetti Aglio e Olio. Notice how the output is perfectly structured, making it ideal for database storage or API consumption:
This structured output demonstrates the agent's ability to not just scrape content, but transform it into a standardized format that's ready for immediate use in applications. Each ingredient is properly quantified, instructions are clearly numbered, and all metadata is consistently formatted.
Evaluating the Effectiveness of AI Agents
While building an agent can be a simple task, ensuring it performs reliably and delivers value consistently is a critical step. A recipe scraping agent, like any AI-driven solution, must be evaluated on key metrics to ensure it meets the intended objectives.
Why Evaluation Matters
Agents operate in dynamic environments where data is often messy, incomplete, or inconsistent. Without proper evaluation, even the most sophisticated agent can produce results that are irrelevant or inaccurate. For business applications, this could mean wasted resources, or missed insights.
Key Metrics for Agent Evaluation
- Accuracy: Does the agent return recipes relevant to the search query? Are the scraped ingredients and instructions correct?
- Completeness: Is the agent capturing all the necessary data (e.g., full recipes, nutritional info)?
- Efficiency: How quickly does the agent complete its task, and is the process scalable for larger datasets?
- Robustness: How well does the agent handle edge cases, such as poorly structured websites or unexpected inputs?
- Data Usability: Is the output standardized and easy to integrate into downstream applications?
Expanding on Agent Evaluation
In a previous post, "Evaluating Webpage Fact Extraction with Braintrust: Part 1", I explored how to measure the accuracy and utility of extracted information from webpages. The same principles apply here: evaluation is not a one-off task but an iterative process of refining prompts, improving scraping techniques, and ensuring outputs continuously meet expectations.
Conclusion
Creating a recipe scraping agent with OpenAI Swarm showcased not just technical execution but the broader potential of AI agents. The Search-Scrape-Extract flow is a powerful, and repeatable architecture that can be applied across use cases to unlock valuable but inaccessible data.
For businesses, the value proposition is clear: agents bridge the gap between human-readable information and machine-actionable insights. As more data sources become available to agents, the ability to quickly process, standardize, and utilize this data will become a competitive differentiator.