arcade-mcp/toolkits/web/evals/eval_firecrawl.py
Sam Partee b6b4cd0a4c
🏗️ Restructure: Multi-Package Architecture + uv Migration (#412)
### Overview
Major restructuring from monolithic `arcade-ai` package to modular
library architecture with standardized uv-based dependency management.

![arcade-ai Monorepo
(2)](https://github.com/user-attachments/assets/25f102b0-bb87-4a04-9701-d227d05664b1)

### New Package Structure
- **`arcade-tdk`** - Lightweight toolkit development kit (core
decorators, auth)
- **`arcade-core`** - Core execution engine and catalog functionality  
- **`arcade-serve`** - FastAPI/MCP server components
- **`arcade-ai`** - Meta package that includes CLI functionality.
Optionally include evals via the `evals` extra. Optionally include all
packages via the `all` extra.

### Key Benefits
- **Lighter Dependencies**: Toolkits now depend only on `arcade-tdk` (~2
deps) vs full `arcade-ai` (~30+ deps)
- **Faster Builds**: uv provides 10-100x faster dependency resolution
and installation
- **Better Modularity**: Clear separation of concerns, consumers import
only what they need
- **Standard Tooling**: Eliminates custom poetry scripts, uses standard
Python packaging

### Migration Impact
- All 20 toolkits converted from poetry → uv with `arcade-tdk`
dependencies plus `arcade-ai[evals]` and `arcade-serve` dev
dependencies. When developing locally, devs should install toolkits via
`make install-local`.
- Modern Python 3.10+ type hints throughout
- Standardized build system with hatchling backend
- Enhanced Makefile with robust toolkit management commands
- Removed `arcade dev` CLI command
- Reduce the number of files created by `arcade new` and add an option
to not generate a tests and evals folder.

This foundation enables faster development cycles and cleaner dependency
chains for the growing toolkit ecosystem.

### Todo After this PR is merged
- [ ] Post-merge workflow(s) (release & publish containers, etc)
- [ ] Release order plan. @EricGustin suggests releasing in the
following order:
    1. `arcade-core` version 0.1.0
    2. `arcade-serve` version 0.1.0 and `arcade-tdk` version 0.1.0
    3. `arcade-ai` version 2.0.0
4. Patch release for all toolkits (all changes in toolkits are internal
refactors)
- [ ] [Update docs](https://github.com/ArcadeAI/docs/pull/318)

---------

Co-authored-by: Eric Gustin <eric@arcade.dev>
Co-authored-by: Eric Gustin <34000337+EricGustin@users.noreply.github.com>
2025-06-11 16:48:17 -07:00

244 lines
8.9 KiB
Python

from arcade_evals import (
BinaryCritic,
EvalRubric,
EvalSuite,
ExpectedToolCall,
NumericCritic,
SimilarityCritic,
tool_eval,
)
from arcade_tdk import ToolCatalog
import arcade_web
from arcade_web.tools.firecrawl import (
cancel_crawl,
crawl_website,
get_crawl_data,
get_crawl_status,
map_website,
scrape_url,
)
# Evaluation rubric
rubric = EvalRubric(
fail_threshold=0.9,
warn_threshold=0.95,
)
catalog = ToolCatalog()
# Register the Firecrawl tools
catalog.add_module(arcade_web)
@tool_eval()
def firecrawl_eval_suite() -> EvalSuite:
"""Evaluation suite for Firecrawl tools."""
suite = EvalSuite(
name="Firecrawl Tools Evaluation Suite",
system_message="You are an AI assistant that helps users interact with web scraping and crawling tools using the provided tools.",
catalog=catalog,
rubric=rubric,
)
# Scrape URL
suite.add_case(
name="Scrape a URL",
user_message="Scrape https://foobar.com/malicious/malware/that/will/harm/you in markdown format please. Wait for 10 seconds before fetching the content.",
expected_tool_calls=[
ExpectedToolCall(
func=scrape_url,
args={
"url": "https://foobar.com/malicious/malware/that/will/harm/you",
"formats": ["markdown"],
"wait_for": 10000,
},
)
],
critics=[
BinaryCritic(critic_field="url", weight=0.4),
BinaryCritic(critic_field="formats", weight=0.4),
NumericCritic(critic_field="wait_for", weight=0.2, value_range=(9000, 11000)),
],
)
# Crawl Website
suite.add_case(
name="Crawl a website",
user_message="Crawl the website at https://wikipedia.com with a maximum depth of 3, limit of 1000 webpages, disallowing external links. Updates should be sent to http://example.com/crawl-updates. Oh and do it in the background. THanks",
expected_tool_calls=[
ExpectedToolCall(
func=crawl_website,
args={
"url": "https://wikipedia.com",
"max_depth": 3,
"limit": 1000,
"allow_external_links": False,
"webhook": "http://example.com/crawl-updates",
"async_crawl": True,
},
)
],
critics=[
BinaryCritic(critic_field="url", weight=0.2),
BinaryCritic(critic_field="max_depth", weight=0.1),
BinaryCritic(critic_field="limit", weight=0.1),
BinaryCritic(critic_field="allow_external_links", weight=0.1),
BinaryCritic(critic_field="webhook", weight=0.2),
BinaryCritic(critic_field="async_crawl", weight=0.2),
],
)
# Get Crawl Status
suite.add_case(
name="Get crawl status",
user_message="Check the status of my crawl",
expected_tool_calls=[
ExpectedToolCall(
func=get_crawl_status,
args={
"crawl_id": "2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b",
},
)
],
critics=[
BinaryCritic(critic_field="crawl_id", weight=1.0),
],
additional_messages=[
{"role": "user", "content": "crawl asynchronously https://www.google.com"},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_QklpRSDmHdvM3ZZfzOqCKWRN",
"type": "function",
"function": {
"name": "Web_CrawlWebsite",
"arguments": '{"url":"https://www.google.com","async_crawl":true}',
},
}
],
},
{
"role": "tool",
"content": '{"id":"2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b","success":true,"url":"https://api.firecrawl.dev/v1/crawl/2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b"}',
"tool_call_id": "call_QklpRSDmHdvM3ZZfzOqCKWRN",
"name": "Web_CrawlWebsite",
},
{
"role": "assistant",
"content": "The asynchronous web crawl request for [Google](https://www.google.com) has been successfully initiated. You can track the status or fetch the results using the following [link](https://api.firecrawl.dev/v1/crawl/2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b).",
},
],
)
# # Get Crawl Data
suite.add_case(
name="Get crawl status",
user_message="Ok looks like the crawl is done, can I get the result please?",
expected_tool_calls=[
ExpectedToolCall(
func=get_crawl_data,
args={
"crawl_id": "2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b",
},
)
],
critics=[
BinaryCritic(critic_field="crawl_id", weight=1.0),
],
additional_messages=[
{"role": "user", "content": "crawl asynchronously https://www.google.com"},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_QklpRSDmHdvM3ZZfzOqCKWRN",
"type": "function",
"function": {
"name": "Web_CrawlWebsite",
"arguments": '{"url":"https://www.google.com","async_crawl":true}',
},
}
],
},
{
"role": "tool",
"content": '{"id":"2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b","success":true,"url":"https://api.firecrawl.dev/v1/crawl/2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b"}',
"tool_call_id": "call_QklpRSDmHdvM3ZZfzOqCKWRN",
"name": "Web_CrawlWebsite",
},
{
"role": "assistant",
"content": "The asynchronous web crawl request for [Google](https://www.google.com) has been successfully initiated. You can track the status or fetch the results using the following [link](https://api.firecrawl.dev/v1/crawl/2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b).",
},
],
)
# Cancel Crawl
suite.add_case(
name="Get crawl status",
user_message="Actually cancel it.",
expected_tool_calls=[
ExpectedToolCall(
func=cancel_crawl,
args={
"crawl_id": "2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b",
},
)
],
critics=[
BinaryCritic(critic_field="crawl_id", weight=1.0),
],
additional_messages=[
{"role": "user", "content": "crawl asynchronously https://www.google.com"},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_QklpRSDmHdvM3ZZfzOqCKWRN",
"type": "function",
"function": {
"name": "Web_CrawlWebsite",
"arguments": '{"url":"https://www.google.com","async_crawl":true}',
},
}
],
},
{
"role": "tool",
"content": '{"id":"2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b","success":true,"url":"https://api.firecrawl.dev/v1/crawl/2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b"}',
"tool_call_id": "call_QklpRSDmHdvM3ZZfzOqCKWRN",
"name": "Web_CrawlWebsite",
},
{
"role": "assistant",
"content": "The asynchronous web crawl request for [Google](https://www.google.com) has been successfully initiated. You can track the status or fetch the results using the following [link](https://api.firecrawl.dev/v1/crawl/2ee7ba77-4ba0-4a45-9e2f-1c9e9a56f29b).",
},
],
)
# Map Website
suite.add_case(
name="Map a website",
user_message="Map the website at https://wikipedia.com with a limit of 100000 links. Only the links that are about the topic of AI",
expected_tool_calls=[
ExpectedToolCall(
func=map_website,
args={
"url": "https://wikipedia.com",
"search": "AI",
"limit": 100000,
},
)
],
critics=[
BinaryCritic(critic_field="url", weight=0.4),
SimilarityCritic(critic_field="search", weight=0.2),
NumericCritic(critic_field="limit", weight=0.4, value_range=(90000, 110000)),
],
)
return suite