wigolo-crewai 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wigolo_crewai-0.2.0/.gitignore +65 -0
- wigolo_crewai-0.2.0/PKG-INFO +102 -0
- wigolo_crewai-0.2.0/README.md +72 -0
- wigolo_crewai-0.2.0/pyproject.toml +47 -0
- wigolo_crewai-0.2.0/tests/__init__.py +0 -0
- wigolo_crewai-0.2.0/tests/conftest.py +57 -0
- wigolo_crewai-0.2.0/tests/test_core.py +127 -0
- wigolo_crewai-0.2.0/tests/test_tools.py +74 -0
- wigolo_crewai-0.2.0/wigolo_crewai/__init__.py +79 -0
- wigolo_crewai-0.2.0/wigolo_crewai/_core.py +182 -0
- wigolo_crewai-0.2.0/wigolo_crewai/tools.py +134 -0
- wigolo_crewai-0.2.0/wigolo_crewai/types.py +122 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
# Build & runtime
|
|
3
|
+
node_modules/
|
|
4
|
+
dist/
|
|
5
|
+
*.tgz
|
|
6
|
+
|
|
7
|
+
# Single-file binary build (build:binary) — artifacts never committed
|
|
8
|
+
packaging/binary/dist/
|
|
9
|
+
/pkg.build.json
|
|
10
|
+
|
|
11
|
+
# Database files
|
|
12
|
+
*.db
|
|
13
|
+
*.db-journal
|
|
14
|
+
*.db-wal
|
|
15
|
+
|
|
16
|
+
# wigolo data
|
|
17
|
+
.wigolo/
|
|
18
|
+
|
|
19
|
+
# Secrets
|
|
20
|
+
.env
|
|
21
|
+
|
|
22
|
+
# Test coverage
|
|
23
|
+
coverage/
|
|
24
|
+
|
|
25
|
+
# Benchmark output (generated)
|
|
26
|
+
benchmarks/extraction/output/
|
|
27
|
+
benchmarks/extraction/.compare-cache/
|
|
28
|
+
|
|
29
|
+
# Git worktrees
|
|
30
|
+
.worktrees/
|
|
31
|
+
|
|
32
|
+
# OS
|
|
33
|
+
.DS_Store
|
|
34
|
+
Thumbs.db
|
|
35
|
+
|
|
36
|
+
# IDE
|
|
37
|
+
.idea/
|
|
38
|
+
.vscode/
|
|
39
|
+
*.swp
|
|
40
|
+
*.swo
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
CLAUDE.md
|
|
44
|
+
docs/
|
|
45
|
+
|
|
46
|
+
# IDE / tool configs
|
|
47
|
+
.claude/
|
|
48
|
+
.cursor/
|
|
49
|
+
.github/copilot-instructions.md
|
|
50
|
+
|
|
51
|
+
# Python bytecode
|
|
52
|
+
__pycache__/
|
|
53
|
+
*.pyc
|
|
54
|
+
|
|
55
|
+
# Private strategy doc (never commit)
|
|
56
|
+
competitive-blueprint.md
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# local demo tooling (VHS tapes + build scripts), not shipped
|
|
60
|
+
.demo/
|
|
61
|
+
|
|
62
|
+
# SDK dev artifacts (each SDK also ships its own .gitignore)
|
|
63
|
+
.venv/
|
|
64
|
+
.pytest_cache/
|
|
65
|
+
*.egg-info
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wigolo-crewai
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: CrewAI integration for wigolo — local-first web intelligence tools
|
|
5
|
+
Project-URL: Homepage, https://github.com/KnockOutEZ/wigolo
|
|
6
|
+
Project-URL: Repository, https://github.com/KnockOutEZ/wigolo/tree/main/packages/wigolo-crewai
|
|
7
|
+
Project-URL: Issues, https://github.com/KnockOutEZ/wigolo/issues
|
|
8
|
+
Author: KnockOutEZ
|
|
9
|
+
License-Expression: AGPL-3.0-only
|
|
10
|
+
Keywords: agent-tools,crewai,mcp,research,web-search
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: Other/Proprietary License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: pydantic>=2.0.0
|
|
22
|
+
Requires-Dist: wigolo>=0.1.0
|
|
23
|
+
Provides-Extra: crewai
|
|
24
|
+
Requires-Dist: crewai>=0.70.0; extra == 'crewai'
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-mock>=3.14; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# wigolo-crewai
|
|
32
|
+
|
|
33
|
+
CrewAI tools for [wigolo](https://github.com/KnockOutEZ/wigolo) — local-first web
|
|
34
|
+
intelligence for your crews. Give agents web search, page fetch, multi-step
|
|
35
|
+
research, site crawl, and structured extraction, with results returned as JSON
|
|
36
|
+
your agents can reason over.
|
|
37
|
+
|
|
38
|
+
Thin wrapper over the wigolo Python SDK: no API keys required for the core
|
|
39
|
+
tools, and a zero-setup embedded daemon starts automatically.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install wigolo-crewai[crewai]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This pulls in the `wigolo` SDK. `crewai` is an optional extra so the core
|
|
48
|
+
helpers can be imported without it.
|
|
49
|
+
|
|
50
|
+
## Quickstart
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from crewai import Agent
|
|
54
|
+
from wigolo_crewai import wigolo_tools
|
|
55
|
+
|
|
56
|
+
# Spawns a local wigolo daemon by default (local=True). Point at a running
|
|
57
|
+
# server instead with wigolo_tools(base_url="http://127.0.0.1:8787", token="...").
|
|
58
|
+
tools = wigolo_tools()
|
|
59
|
+
|
|
60
|
+
researcher = Agent(
|
|
61
|
+
role="Web Researcher",
|
|
62
|
+
goal="Find and summarize current information from the web",
|
|
63
|
+
backstory="You dig through the web and return well-sourced findings.",
|
|
64
|
+
tools=tools,
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
You can also add individual tools:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from wigolo_crewai import WigoloSearchTool, WigoloResearchTool, build_client
|
|
72
|
+
|
|
73
|
+
client = build_client(local=True)
|
|
74
|
+
agent_tools = [WigoloSearchTool(client=client), WigoloResearchTool(client=client)]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Tools
|
|
78
|
+
|
|
79
|
+
| Tool | Class | What it does |
|
|
80
|
+
|------|-------|--------------|
|
|
81
|
+
| `wigolo_search` | `WigoloSearchTool` | Search the web; ML-reranked results with extracted content |
|
|
82
|
+
| `wigolo_fetch` | `WigoloFetchTool` | Fetch a page as clean markdown (JS rendering optional) |
|
|
83
|
+
| `wigolo_research` | `WigoloResearchTool` | Multi-step research brief: topics, findings, cross-references, gaps |
|
|
84
|
+
| `wigolo_crawl` | `WigoloCrawlTool` | Crawl a site (sitemap / breadth-first / depth-first / map) |
|
|
85
|
+
| `wigolo_extract` | `WigoloExtractTool` | Structured extraction: tables, metadata, key-values, schema fields |
|
|
86
|
+
|
|
87
|
+
Every tool returns a JSON string; wigolo errors are returned as a clean
|
|
88
|
+
`{"error": "..."}` string rather than raised into the agent loop.
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
`wigolo_tools(base_url=None, token=None, local=True)`:
|
|
93
|
+
|
|
94
|
+
- `local=True` (default) — spawn an embedded local daemon, zero setup.
|
|
95
|
+
- `base_url` / `token` — target a running wigolo server (set `local=False`).
|
|
96
|
+
|
|
97
|
+
Environment variables `WIGOLO_BASE_URL`, `WIGOLO_API_TOKEN`, and `WIGOLO_LOCAL`
|
|
98
|
+
are honored by the underlying SDK when the corresponding argument is left unset.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
GNU AGPL-3.0-only — see the root LICENSE.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# wigolo-crewai
|
|
2
|
+
|
|
3
|
+
CrewAI tools for [wigolo](https://github.com/KnockOutEZ/wigolo) — local-first web
|
|
4
|
+
intelligence for your crews. Give agents web search, page fetch, multi-step
|
|
5
|
+
research, site crawl, and structured extraction, with results returned as JSON
|
|
6
|
+
your agents can reason over.
|
|
7
|
+
|
|
8
|
+
Thin wrapper over the wigolo Python SDK: no API keys required for the core
|
|
9
|
+
tools, and a zero-setup embedded daemon starts automatically.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install wigolo-crewai[crewai]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This pulls in the `wigolo` SDK. `crewai` is an optional extra so the core
|
|
18
|
+
helpers can be imported without it.
|
|
19
|
+
|
|
20
|
+
## Quickstart
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from crewai import Agent
|
|
24
|
+
from wigolo_crewai import wigolo_tools
|
|
25
|
+
|
|
26
|
+
# Spawns a local wigolo daemon by default (local=True). Point at a running
|
|
27
|
+
# server instead with wigolo_tools(base_url="http://127.0.0.1:8787", token="...").
|
|
28
|
+
tools = wigolo_tools()
|
|
29
|
+
|
|
30
|
+
researcher = Agent(
|
|
31
|
+
role="Web Researcher",
|
|
32
|
+
goal="Find and summarize current information from the web",
|
|
33
|
+
backstory="You dig through the web and return well-sourced findings.",
|
|
34
|
+
tools=tools,
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
You can also add individual tools:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from wigolo_crewai import WigoloSearchTool, WigoloResearchTool, build_client
|
|
42
|
+
|
|
43
|
+
client = build_client(local=True)
|
|
44
|
+
agent_tools = [WigoloSearchTool(client=client), WigoloResearchTool(client=client)]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Tools
|
|
48
|
+
|
|
49
|
+
| Tool | Class | What it does |
|
|
50
|
+
|------|-------|--------------|
|
|
51
|
+
| `wigolo_search` | `WigoloSearchTool` | Search the web; ML-reranked results with extracted content |
|
|
52
|
+
| `wigolo_fetch` | `WigoloFetchTool` | Fetch a page as clean markdown (JS rendering optional) |
|
|
53
|
+
| `wigolo_research` | `WigoloResearchTool` | Multi-step research brief: topics, findings, cross-references, gaps |
|
|
54
|
+
| `wigolo_crawl` | `WigoloCrawlTool` | Crawl a site (sitemap / breadth-first / depth-first / map) |
|
|
55
|
+
| `wigolo_extract` | `WigoloExtractTool` | Structured extraction: tables, metadata, key-values, schema fields |
|
|
56
|
+
|
|
57
|
+
Every tool returns a JSON string; wigolo errors are returned as a clean
|
|
58
|
+
`{"error": "..."}` string rather than raised into the agent loop.
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
`wigolo_tools(base_url=None, token=None, local=True)`:
|
|
63
|
+
|
|
64
|
+
- `local=True` (default) — spawn an embedded local daemon, zero setup.
|
|
65
|
+
- `base_url` / `token` — target a running wigolo server (set `local=False`).
|
|
66
|
+
|
|
67
|
+
Environment variables `WIGOLO_BASE_URL`, `WIGOLO_API_TOKEN`, and `WIGOLO_LOCAL`
|
|
68
|
+
are honored by the underlying SDK when the corresponding argument is left unset.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
GNU AGPL-3.0-only — see the root LICENSE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wigolo-crewai"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "CrewAI integration for wigolo — local-first web intelligence tools"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "AGPL-3.0-only"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "KnockOutEZ" }]
|
|
13
|
+
keywords = ["crewai", "mcp", "web-search", "agent-tools", "research"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: Other/Proprietary License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"wigolo>=0.1.0",
|
|
27
|
+
"pydantic>=2.0.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
crewai = [
|
|
32
|
+
"crewai>=0.70.0",
|
|
33
|
+
]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=8.0",
|
|
36
|
+
"pytest-asyncio>=0.24",
|
|
37
|
+
"pytest-mock>=3.14",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/KnockOutEZ/wigolo"
|
|
42
|
+
Repository = "https://github.com/KnockOutEZ/wigolo/tree/main/packages/wigolo-crewai"
|
|
43
|
+
Issues = "https://github.com/KnockOutEZ/wigolo/issues"
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
asyncio_mode = "auto"
|
|
47
|
+
testpaths = ["tests"]
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Shared test fixtures for wigolo-crewai.
|
|
2
|
+
|
|
3
|
+
The wigolo Python SDK is not installed in this workspace, so we make it
|
|
4
|
+
importable from the in-repo source tree. This lets ``import wigolo`` (and the
|
|
5
|
+
``WigoloError`` type the core maps) resolve without a system-pip install.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from unittest.mock import MagicMock
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
# packages/wigolo-crewai/tests/conftest.py -> repo root is three parents up.
|
|
17
|
+
_REPO_ROOT = Path(__file__).resolve().parents[3]
|
|
18
|
+
_SDK_SRC = _REPO_ROOT / "sdks" / "python" / "src"
|
|
19
|
+
if _SDK_SRC.is_dir():
|
|
20
|
+
sys.path.insert(0, str(_SDK_SRC))
|
|
21
|
+
|
|
22
|
+
# Make the package itself importable without an editable install.
|
|
23
|
+
_PKG_ROOT = Path(__file__).resolve().parents[1]
|
|
24
|
+
if str(_PKG_ROOT) not in sys.path:
|
|
25
|
+
sys.path.insert(0, str(_PKG_ROOT))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def mock_client() -> MagicMock:
|
|
30
|
+
"""A MagicMock standing in for a wigolo.Client with canned tool results."""
|
|
31
|
+
client = MagicMock()
|
|
32
|
+
client.search.return_value = {
|
|
33
|
+
"results": [
|
|
34
|
+
{"title": "Test", "url": "https://example.com", "relevance_score": 0.9}
|
|
35
|
+
],
|
|
36
|
+
"query": "test",
|
|
37
|
+
"engines_used": ["duckduckgo"],
|
|
38
|
+
"total_time_ms": 12,
|
|
39
|
+
}
|
|
40
|
+
client.fetch.return_value = {
|
|
41
|
+
"url": "https://example.com",
|
|
42
|
+
"title": "Example",
|
|
43
|
+
"markdown": "# Example\ncontent",
|
|
44
|
+
"cached": False,
|
|
45
|
+
}
|
|
46
|
+
client.research.return_value = {
|
|
47
|
+
"brief": {"topics": ["a"], "highlights": ["h"], "key_findings": ["k"]}
|
|
48
|
+
}
|
|
49
|
+
client.crawl.return_value = {
|
|
50
|
+
"pages": [{"url": "https://example.com/a", "title": "A"}],
|
|
51
|
+
"count": 1,
|
|
52
|
+
}
|
|
53
|
+
client.extract.return_value = {
|
|
54
|
+
"url": "https://example.com",
|
|
55
|
+
"tables": [{"rows": [["x", "y"]]}],
|
|
56
|
+
}
|
|
57
|
+
return client
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Unit tests for the crewai-free core. No crewai import here."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from wigolo import WigoloAPIError
|
|
10
|
+
|
|
11
|
+
from wigolo_crewai import _core
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# --- argument mapping: the SDK method is called with the mapped kwargs -------
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_run_search_maps_args_and_returns_json(mock_client):
|
|
18
|
+
out = _core.run_search(
|
|
19
|
+
mock_client,
|
|
20
|
+
"python asyncio",
|
|
21
|
+
max_results=3,
|
|
22
|
+
include_domains=["docs.python.org"],
|
|
23
|
+
category="docs",
|
|
24
|
+
)
|
|
25
|
+
mock_client.search.assert_called_once()
|
|
26
|
+
_, kwargs = mock_client.search.call_args
|
|
27
|
+
assert kwargs["query"] == "python asyncio"
|
|
28
|
+
assert kwargs["max_results"] == 3
|
|
29
|
+
assert kwargs["include_domains"] == ["docs.python.org"]
|
|
30
|
+
assert kwargs["category"] == "docs"
|
|
31
|
+
# WHY: the tool contract is a JSON *string* so CrewAI can hand it to the LLM.
|
|
32
|
+
parsed = json.loads(out)
|
|
33
|
+
assert parsed["query"] == "test"
|
|
34
|
+
assert parsed["results"][0]["url"] == "https://example.com"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_run_search_drops_none_so_sdk_defaults_apply(mock_client):
|
|
38
|
+
_core.run_search(mock_client, "q")
|
|
39
|
+
_, kwargs = mock_client.search.call_args
|
|
40
|
+
# WHY: passing time_range=None would override the server default; it must be dropped.
|
|
41
|
+
assert "time_range" not in kwargs
|
|
42
|
+
assert "include_domains" not in kwargs
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_run_fetch_maps_args(mock_client):
|
|
46
|
+
out = _core.run_fetch(
|
|
47
|
+
mock_client, "https://example.com", render_js=True, section="Install"
|
|
48
|
+
)
|
|
49
|
+
_, kwargs = mock_client.fetch.call_args
|
|
50
|
+
assert kwargs["url"] == "https://example.com"
|
|
51
|
+
assert kwargs["render_js"] is True
|
|
52
|
+
assert kwargs["section"] == "Install"
|
|
53
|
+
assert json.loads(out)["title"] == "Example"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_run_research_maps_args(mock_client):
|
|
57
|
+
out = _core.run_research(
|
|
58
|
+
mock_client, "compare X vs Y", depth="comprehensive", max_sources=8
|
|
59
|
+
)
|
|
60
|
+
_, kwargs = mock_client.research.call_args
|
|
61
|
+
assert kwargs["question"] == "compare X vs Y"
|
|
62
|
+
assert kwargs["depth"] == "comprehensive"
|
|
63
|
+
assert kwargs["max_sources"] == 8
|
|
64
|
+
assert "brief" in json.loads(out)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_run_crawl_maps_args(mock_client):
|
|
68
|
+
out = _core.run_crawl(
|
|
69
|
+
mock_client, "https://docs.site", strategy="sitemap", max_pages=50
|
|
70
|
+
)
|
|
71
|
+
_, kwargs = mock_client.crawl.call_args
|
|
72
|
+
assert kwargs["url"] == "https://docs.site"
|
|
73
|
+
assert kwargs["strategy"] == "sitemap"
|
|
74
|
+
assert kwargs["max_pages"] == 50
|
|
75
|
+
assert json.loads(out)["count"] == 1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_run_extract_maps_args(mock_client):
|
|
79
|
+
out = _core.run_extract(
|
|
80
|
+
mock_client, "https://example.com", mode="tables"
|
|
81
|
+
)
|
|
82
|
+
_, kwargs = mock_client.extract.call_args
|
|
83
|
+
assert kwargs["url"] == "https://example.com"
|
|
84
|
+
assert kwargs["mode"] == "tables"
|
|
85
|
+
assert "tables" in json.loads(out)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# --- error mapping: WigoloError becomes a clean string, not an exception -----
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@pytest.mark.parametrize(
|
|
92
|
+
"runner, method, args",
|
|
93
|
+
[
|
|
94
|
+
(_core.run_search, "search", ("q",)),
|
|
95
|
+
(_core.run_fetch, "fetch", ("https://x",)),
|
|
96
|
+
(_core.run_research, "research", ("q",)),
|
|
97
|
+
(_core.run_crawl, "crawl", ("https://x",)),
|
|
98
|
+
(_core.run_extract, "extract", ("https://x",)),
|
|
99
|
+
],
|
|
100
|
+
)
|
|
101
|
+
def test_wigolo_error_becomes_clean_json_string(mock_client, runner, method, args):
|
|
102
|
+
getattr(mock_client, method).side_effect = WigoloAPIError(
|
|
103
|
+
"boom", status=500
|
|
104
|
+
)
|
|
105
|
+
# WHY: an LLM tool must never raise into the agent loop; it returns an error string.
|
|
106
|
+
out = runner(mock_client, *args)
|
|
107
|
+
parsed = json.loads(out)
|
|
108
|
+
assert "error" in parsed
|
|
109
|
+
assert method in parsed["error"]
|
|
110
|
+
# WHY: don't leak internals/stack traces to the model.
|
|
111
|
+
assert "Traceback" not in out
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_build_client_constructs_wigolo_client(monkeypatch):
|
|
115
|
+
captured = {}
|
|
116
|
+
|
|
117
|
+
class FakeClient:
|
|
118
|
+
def __init__(self, **kw):
|
|
119
|
+
captured.update(kw)
|
|
120
|
+
|
|
121
|
+
monkeypatch.setattr(_core, "Client", FakeClient)
|
|
122
|
+
_core.build_client(base_url="http://127.0.0.1:9999", token="t", local=False)
|
|
123
|
+
assert captured == {
|
|
124
|
+
"base_url": "http://127.0.0.1:9999",
|
|
125
|
+
"token": "t",
|
|
126
|
+
"local": False,
|
|
127
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""CrewAI adapter tests.
|
|
2
|
+
|
|
3
|
+
Gated on crewai being installed. This is a legitimate dependency gate, NOT a
|
|
4
|
+
silent skip of core logic — all real behaviour is covered in test_core.py.
|
|
5
|
+
When crewai is absent these skip with a visible reason.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from unittest.mock import MagicMock
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
crewai = pytest.importorskip("crewai", reason="crewai not installed")
|
|
16
|
+
|
|
17
|
+
from wigolo_crewai import tools # noqa: E402
|
|
18
|
+
from wigolo_crewai.types import ( # noqa: E402
|
|
19
|
+
CrawlInput,
|
|
20
|
+
ExtractInput,
|
|
21
|
+
FetchInput,
|
|
22
|
+
ResearchInput,
|
|
23
|
+
SearchInput,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
_TOOL_CASES = [
|
|
27
|
+
(tools.WigoloSearchTool, "wigolo_search", SearchInput),
|
|
28
|
+
(tools.WigoloFetchTool, "wigolo_fetch", FetchInput),
|
|
29
|
+
(tools.WigoloResearchTool, "wigolo_research", ResearchInput),
|
|
30
|
+
(tools.WigoloCrawlTool, "wigolo_crawl", CrawlInput),
|
|
31
|
+
(tools.WigoloExtractTool, "wigolo_extract", ExtractInput),
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.parametrize("cls, name, schema", _TOOL_CASES)
|
|
36
|
+
def test_tool_instantiates_with_expected_metadata(cls, name, schema, mock_client):
|
|
37
|
+
tool = cls(client=mock_client)
|
|
38
|
+
assert tool.name == name
|
|
39
|
+
assert tool.description
|
|
40
|
+
assert tool.args_schema is schema
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_search_tool_delegates_to_core(mock_client):
|
|
44
|
+
tool = tools.WigoloSearchTool(client=mock_client)
|
|
45
|
+
out = tool._run(query="python", max_results=3)
|
|
46
|
+
mock_client.search.assert_called_once()
|
|
47
|
+
_, kwargs = mock_client.search.call_args
|
|
48
|
+
assert kwargs["query"] == "python"
|
|
49
|
+
assert kwargs["max_results"] == 3
|
|
50
|
+
assert json.loads(out)["query"] == "test"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_fetch_tool_delegates_to_core(mock_client):
|
|
54
|
+
tool = tools.WigoloFetchTool(client=mock_client)
|
|
55
|
+
tool._run(url="https://example.com", render_js=True)
|
|
56
|
+
_, kwargs = mock_client.fetch.call_args
|
|
57
|
+
assert kwargs["url"] == "https://example.com"
|
|
58
|
+
assert kwargs["render_js"] is True
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_wigolo_tools_factory_returns_five_sharing_one_client(monkeypatch):
|
|
62
|
+
sentinel = MagicMock()
|
|
63
|
+
monkeypatch.setattr(tools._core, "build_client", lambda **kw: sentinel)
|
|
64
|
+
built = tools.wigolo_tools(local=True)
|
|
65
|
+
assert len(built) == 5
|
|
66
|
+
assert {t.name for t in built} == {
|
|
67
|
+
"wigolo_search",
|
|
68
|
+
"wigolo_fetch",
|
|
69
|
+
"wigolo_research",
|
|
70
|
+
"wigolo_crawl",
|
|
71
|
+
"wigolo_extract",
|
|
72
|
+
}
|
|
73
|
+
# WHY: all five must share the single constructed client (one daemon).
|
|
74
|
+
assert all(t.client is sentinel for t in built)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""CrewAI integration for wigolo — local-first web intelligence tools.
|
|
2
|
+
|
|
3
|
+
The core run functions (:mod:`wigolo_crewai._core`) and input schemas
|
|
4
|
+
(:mod:`wigolo_crewai.types`) import cleanly without crewai. The CrewAI tool
|
|
5
|
+
classes and the ``wigolo_tools`` factory are imported lazily, so a consumer
|
|
6
|
+
without crewai installed only hits an ImportError when they actually touch a
|
|
7
|
+
tool — not on ``import wigolo_crewai``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from typing import TYPE_CHECKING, Any
|
|
13
|
+
|
|
14
|
+
from wigolo_crewai._core import (
|
|
15
|
+
build_client,
|
|
16
|
+
run_crawl,
|
|
17
|
+
run_extract,
|
|
18
|
+
run_fetch,
|
|
19
|
+
run_research,
|
|
20
|
+
run_search,
|
|
21
|
+
)
|
|
22
|
+
from wigolo_crewai.types import (
|
|
23
|
+
CrawlInput,
|
|
24
|
+
ExtractInput,
|
|
25
|
+
FetchInput,
|
|
26
|
+
ResearchInput,
|
|
27
|
+
SearchInput,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING: # pragma: no cover - typing only
|
|
31
|
+
from wigolo_crewai.tools import (
|
|
32
|
+
WigoloCrawlTool,
|
|
33
|
+
WigoloExtractTool,
|
|
34
|
+
WigoloFetchTool,
|
|
35
|
+
WigoloResearchTool,
|
|
36
|
+
WigoloSearchTool,
|
|
37
|
+
wigolo_tools,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
_LAZY_TOOL_ATTRS = {
|
|
41
|
+
"WigoloSearchTool",
|
|
42
|
+
"WigoloFetchTool",
|
|
43
|
+
"WigoloResearchTool",
|
|
44
|
+
"WigoloCrawlTool",
|
|
45
|
+
"WigoloExtractTool",
|
|
46
|
+
"wigolo_tools",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
# crewai-free core
|
|
51
|
+
"build_client",
|
|
52
|
+
"run_search",
|
|
53
|
+
"run_fetch",
|
|
54
|
+
"run_research",
|
|
55
|
+
"run_crawl",
|
|
56
|
+
"run_extract",
|
|
57
|
+
# input schemas
|
|
58
|
+
"SearchInput",
|
|
59
|
+
"FetchInput",
|
|
60
|
+
"ResearchInput",
|
|
61
|
+
"CrawlInput",
|
|
62
|
+
"ExtractInput",
|
|
63
|
+
# crewai tools (lazy)
|
|
64
|
+
"WigoloSearchTool",
|
|
65
|
+
"WigoloFetchTool",
|
|
66
|
+
"WigoloResearchTool",
|
|
67
|
+
"WigoloCrawlTool",
|
|
68
|
+
"WigoloExtractTool",
|
|
69
|
+
"wigolo_tools",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def __getattr__(name: str) -> Any:
|
|
74
|
+
"""Lazily import crewai-backed tool classes on first access."""
|
|
75
|
+
if name in _LAZY_TOOL_ATTRS:
|
|
76
|
+
from wigolo_crewai import tools
|
|
77
|
+
|
|
78
|
+
return getattr(tools, name)
|
|
79
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""CrewAI-free core logic for wigolo-crewai.
|
|
2
|
+
|
|
3
|
+
This module holds all of the real behaviour — building a wigolo client and the
|
|
4
|
+
per-tool run functions that map arguments onto the SDK, shape the result into a
|
|
5
|
+
JSON string, and turn wigolo errors into clean error strings. It deliberately
|
|
6
|
+
does NOT import crewai, so it is fully unit-testable without that dependency.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
from typing import Any, Optional
|
|
13
|
+
|
|
14
|
+
from wigolo import Client, WigoloError
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def build_client(
|
|
18
|
+
base_url: Optional[str] = None,
|
|
19
|
+
token: Optional[str] = None,
|
|
20
|
+
local: bool = True,
|
|
21
|
+
) -> Client:
|
|
22
|
+
"""Construct a wigolo ``Client``.
|
|
23
|
+
|
|
24
|
+
Defaults to ``local=True`` so a zero-setup embedded daemon is spawned when
|
|
25
|
+
no server is configured. Pass ``base_url``/``token`` to target a running
|
|
26
|
+
server instead, or ``local=False`` to require one.
|
|
27
|
+
"""
|
|
28
|
+
return Client(base_url=base_url, token=token, local=local)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _drop_none(mapping: dict[str, Any]) -> dict[str, Any]:
|
|
32
|
+
"""Strip ``None`` values so SDK defaults apply for unset arguments."""
|
|
33
|
+
return {k: v for k, v in mapping.items() if v is not None}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _to_json(result: Any) -> str:
|
|
37
|
+
"""Serialize a tool result dict to a compact JSON string."""
|
|
38
|
+
return json.dumps(result, default=str, ensure_ascii=False)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _error(tool: str, exc: Exception) -> str:
|
|
42
|
+
"""Map a wigolo error into a clean JSON error string (no stack trace)."""
|
|
43
|
+
return json.dumps({"error": f"wigolo {tool} failed: {exc}"}, ensure_ascii=False)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def run_search(
|
|
47
|
+
client: Client,
|
|
48
|
+
query: str,
|
|
49
|
+
*,
|
|
50
|
+
max_results: int = 5,
|
|
51
|
+
include_content: bool = True,
|
|
52
|
+
time_range: Optional[str] = None,
|
|
53
|
+
include_domains: Optional[list[str]] = None,
|
|
54
|
+
exclude_domains: Optional[list[str]] = None,
|
|
55
|
+
category: Optional[str] = None,
|
|
56
|
+
**kwargs: Any,
|
|
57
|
+
) -> str:
|
|
58
|
+
"""Search the web and return results as a JSON string."""
|
|
59
|
+
params = _drop_none(
|
|
60
|
+
{
|
|
61
|
+
"query": query,
|
|
62
|
+
"max_results": max_results,
|
|
63
|
+
"include_content": include_content,
|
|
64
|
+
"time_range": time_range,
|
|
65
|
+
"include_domains": include_domains,
|
|
66
|
+
"exclude_domains": exclude_domains,
|
|
67
|
+
"category": category,
|
|
68
|
+
**kwargs,
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
try:
|
|
72
|
+
return _to_json(client.search(**params))
|
|
73
|
+
except WigoloError as exc:
|
|
74
|
+
return _error("search", exc)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def run_fetch(
|
|
78
|
+
client: Client,
|
|
79
|
+
url: str,
|
|
80
|
+
*,
|
|
81
|
+
render_js: bool = False,
|
|
82
|
+
section: Optional[str] = None,
|
|
83
|
+
max_chars: Optional[int] = None,
|
|
84
|
+
use_auth: bool = False,
|
|
85
|
+
**kwargs: Any,
|
|
86
|
+
) -> str:
|
|
87
|
+
"""Fetch a single page and return its content as a JSON string."""
|
|
88
|
+
params = _drop_none(
|
|
89
|
+
{
|
|
90
|
+
"url": url,
|
|
91
|
+
"render_js": render_js,
|
|
92
|
+
"section": section,
|
|
93
|
+
"max_chars": max_chars,
|
|
94
|
+
"use_auth": use_auth,
|
|
95
|
+
**kwargs,
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
try:
|
|
99
|
+
return _to_json(client.fetch(**params))
|
|
100
|
+
except WigoloError as exc:
|
|
101
|
+
return _error("fetch", exc)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def run_research(
|
|
105
|
+
client: Client,
|
|
106
|
+
question: str,
|
|
107
|
+
*,
|
|
108
|
+
depth: str = "standard",
|
|
109
|
+
max_sources: Optional[int] = None,
|
|
110
|
+
include_domains: Optional[list[str]] = None,
|
|
111
|
+
exclude_domains: Optional[list[str]] = None,
|
|
112
|
+
**kwargs: Any,
|
|
113
|
+
) -> str:
|
|
114
|
+
"""Run multi-step research and return the brief as a JSON string."""
|
|
115
|
+
params = _drop_none(
|
|
116
|
+
{
|
|
117
|
+
"question": question,
|
|
118
|
+
"depth": depth,
|
|
119
|
+
"max_sources": max_sources,
|
|
120
|
+
"include_domains": include_domains,
|
|
121
|
+
"exclude_domains": exclude_domains,
|
|
122
|
+
**kwargs,
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
try:
|
|
126
|
+
return _to_json(client.research(**params))
|
|
127
|
+
except WigoloError as exc:
|
|
128
|
+
return _error("research", exc)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def run_crawl(
|
|
132
|
+
client: Client,
|
|
133
|
+
url: str,
|
|
134
|
+
*,
|
|
135
|
+
strategy: str = "bfs",
|
|
136
|
+
max_depth: Optional[int] = None,
|
|
137
|
+
max_pages: Optional[int] = None,
|
|
138
|
+
include_patterns: Optional[list[str]] = None,
|
|
139
|
+
exclude_patterns: Optional[list[str]] = None,
|
|
140
|
+
**kwargs: Any,
|
|
141
|
+
) -> str:
|
|
142
|
+
"""Crawl a site and return the pages/urls as a JSON string."""
|
|
143
|
+
params = _drop_none(
|
|
144
|
+
{
|
|
145
|
+
"url": url,
|
|
146
|
+
"strategy": strategy,
|
|
147
|
+
"max_depth": max_depth,
|
|
148
|
+
"max_pages": max_pages,
|
|
149
|
+
"include_patterns": include_patterns,
|
|
150
|
+
"exclude_patterns": exclude_patterns,
|
|
151
|
+
**kwargs,
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
try:
|
|
155
|
+
return _to_json(client.crawl(**params))
|
|
156
|
+
except WigoloError as exc:
|
|
157
|
+
return _error("crawl", exc)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def run_extract(
|
|
161
|
+
client: Client,
|
|
162
|
+
url: str,
|
|
163
|
+
*,
|
|
164
|
+
mode: str = "structured",
|
|
165
|
+
schema: Optional[Any] = None,
|
|
166
|
+
css_selector: Optional[str] = None,
|
|
167
|
+
**kwargs: Any,
|
|
168
|
+
) -> str:
|
|
169
|
+
"""Extract structured data from a page and return it as a JSON string."""
|
|
170
|
+
params = _drop_none(
|
|
171
|
+
{
|
|
172
|
+
"url": url,
|
|
173
|
+
"mode": mode,
|
|
174
|
+
"schema": schema,
|
|
175
|
+
"css_selector": css_selector,
|
|
176
|
+
**kwargs,
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
try:
|
|
180
|
+
return _to_json(client.extract(**params))
|
|
181
|
+
except WigoloError as exc:
|
|
182
|
+
return _error("extract", exc)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""CrewAI tool adapters for wigolo.
|
|
2
|
+
|
|
3
|
+
Thin ``BaseTool`` subclasses that delegate all real work to :mod:`wigolo_crewai._core`.
|
|
4
|
+
Importing this module requires crewai; the core logic in ``_core`` does not.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, Optional, Type
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from crewai.tools import BaseTool
|
|
13
|
+
except ImportError as exc: # pragma: no cover - exercised only without crewai
|
|
14
|
+
raise ImportError(
|
|
15
|
+
"crewai is required to use wigolo_crewai tools. Install it with "
|
|
16
|
+
"`pip install wigolo-crewai[crewai]` or `pip install crewai`."
|
|
17
|
+
) from exc
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
20
|
+
|
|
21
|
+
from wigolo import Client
|
|
22
|
+
|
|
23
|
+
from wigolo_crewai import _core
|
|
24
|
+
from wigolo_crewai.types import (
|
|
25
|
+
CrawlInput,
|
|
26
|
+
ExtractInput,
|
|
27
|
+
FetchInput,
|
|
28
|
+
ResearchInput,
|
|
29
|
+
SearchInput,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class _WigoloBaseTool(BaseTool):
|
|
34
|
+
"""Shared config: every tool carries a wigolo ``Client``."""
|
|
35
|
+
|
|
36
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
37
|
+
|
|
38
|
+
client: Any = Field(default=None, description="wigolo Client instance")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class WigoloSearchTool(_WigoloBaseTool):
|
|
42
|
+
"""Search the web for information on any topic."""
|
|
43
|
+
|
|
44
|
+
name: str = "wigolo_search"
|
|
45
|
+
description: str = (
|
|
46
|
+
"Search the web for information on any topic. Returns titles, URLs, "
|
|
47
|
+
"relevance scores, and extracted content as JSON. Supports domain "
|
|
48
|
+
"filtering, time ranges, and content categories. Use a keyword-based "
|
|
49
|
+
"'query'."
|
|
50
|
+
)
|
|
51
|
+
args_schema: Type[BaseModel] = SearchInput
|
|
52
|
+
|
|
53
|
+
def _run(self, **kwargs: Any) -> str:
|
|
54
|
+
return _core.run_search(self.client, **kwargs)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class WigoloFetchTool(_WigoloBaseTool):
|
|
58
|
+
"""Fetch a specific web page as clean markdown."""
|
|
59
|
+
|
|
60
|
+
name: str = "wigolo_fetch"
|
|
61
|
+
description: str = (
|
|
62
|
+
"Fetch a specific web page and return its content as clean markdown "
|
|
63
|
+
"plus metadata, as JSON. Supports JavaScript rendering via the browser "
|
|
64
|
+
"engine, section extraction, and authenticated browsing. Requires a 'url'."
|
|
65
|
+
)
|
|
66
|
+
args_schema: Type[BaseModel] = FetchInput
|
|
67
|
+
|
|
68
|
+
def _run(self, **kwargs: Any) -> str:
|
|
69
|
+
return _core.run_fetch(self.client, **kwargs)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class WigoloResearchTool(_WigoloBaseTool):
|
|
73
|
+
"""Run multi-step research and return a structured brief."""
|
|
74
|
+
|
|
75
|
+
name: str = "wigolo_research"
|
|
76
|
+
description: str = (
|
|
77
|
+
"Investigate a question across multiple sources and return a structured "
|
|
78
|
+
"research brief as JSON, with topics, highlights, key findings, "
|
|
79
|
+
"cross-references, and coverage gaps. Requires a 'question'."
|
|
80
|
+
)
|
|
81
|
+
args_schema: Type[BaseModel] = ResearchInput
|
|
82
|
+
|
|
83
|
+
def _run(self, **kwargs: Any) -> str:
|
|
84
|
+
return _core.run_research(self.client, **kwargs)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class WigoloCrawlTool(_WigoloBaseTool):
|
|
88
|
+
"""Crawl a site from a seed URL."""
|
|
89
|
+
|
|
90
|
+
name: str = "wigolo_crawl"
|
|
91
|
+
description: str = (
|
|
92
|
+
"Crawl a website from a seed URL and return the visited pages (or URL "
|
|
93
|
+
"map) as JSON. Supports sitemap, breadth-first, depth-first, and map "
|
|
94
|
+
"strategies with depth, page, and pattern limits. Requires a 'url'."
|
|
95
|
+
)
|
|
96
|
+
args_schema: Type[BaseModel] = CrawlInput
|
|
97
|
+
|
|
98
|
+
def _run(self, **kwargs: Any) -> str:
|
|
99
|
+
return _core.run_crawl(self.client, **kwargs)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class WigoloExtractTool(_WigoloBaseTool):
|
|
103
|
+
"""Extract structured data from a page."""
|
|
104
|
+
|
|
105
|
+
name: str = "wigolo_extract"
|
|
106
|
+
description: str = (
|
|
107
|
+
"Extract structured data from a web page as JSON — tables, definition "
|
|
108
|
+
"lists, key-value pairs, metadata, or schema-shaped fields. Supports "
|
|
109
|
+
"structured, schema, tables, metadata, and selector modes. Requires a 'url'."
|
|
110
|
+
)
|
|
111
|
+
args_schema: Type[BaseModel] = ExtractInput
|
|
112
|
+
|
|
113
|
+
def _run(self, **kwargs: Any) -> str:
|
|
114
|
+
return _core.run_extract(self.client, **kwargs)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def wigolo_tools(
|
|
118
|
+
base_url: Optional[str] = None,
|
|
119
|
+
token: Optional[str] = None,
|
|
120
|
+
local: bool = True,
|
|
121
|
+
) -> list[BaseTool]:
|
|
122
|
+
"""Build all five wigolo tools sharing one wigolo ``Client``.
|
|
123
|
+
|
|
124
|
+
By default spawns a zero-setup local daemon (``local=True``). Pass
|
|
125
|
+
``base_url``/``token`` to target a running wigolo server instead.
|
|
126
|
+
"""
|
|
127
|
+
client: Client = _core.build_client(base_url=base_url, token=token, local=local)
|
|
128
|
+
return [
|
|
129
|
+
WigoloSearchTool(client=client),
|
|
130
|
+
WigoloFetchTool(client=client),
|
|
131
|
+
WigoloResearchTool(client=client),
|
|
132
|
+
WigoloCrawlTool(client=client),
|
|
133
|
+
WigoloExtractTool(client=client),
|
|
134
|
+
]
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Pydantic input schemas for the wigolo-crewai tools.
|
|
2
|
+
|
|
3
|
+
These are the ``args_schema`` models CrewAI uses to validate tool inputs.
|
|
4
|
+
They intentionally expose the common, high-signal parameters of each wigolo
|
|
5
|
+
tool; the full parameter surface remains reachable through the SDK directly.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any, Optional
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, Field
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SearchInput(BaseModel):
|
|
16
|
+
"""Input schema for the wigolo search tool."""
|
|
17
|
+
|
|
18
|
+
query: str = Field(description="Keyword-based search query")
|
|
19
|
+
max_results: int = Field(
|
|
20
|
+
default=5, ge=1, le=20, description="Maximum number of results to return"
|
|
21
|
+
)
|
|
22
|
+
include_content: bool = Field(
|
|
23
|
+
default=True, description="Fetch full extracted content for the results"
|
|
24
|
+
)
|
|
25
|
+
time_range: Optional[str] = Field(
|
|
26
|
+
default=None,
|
|
27
|
+
pattern=r"^(day|week|month|year)$",
|
|
28
|
+
description="Restrict results to a recent time window",
|
|
29
|
+
)
|
|
30
|
+
include_domains: Optional[list[str]] = Field(
|
|
31
|
+
default=None, description="Only return results from these domains"
|
|
32
|
+
)
|
|
33
|
+
exclude_domains: Optional[list[str]] = Field(
|
|
34
|
+
default=None, description="Never return results from these domains"
|
|
35
|
+
)
|
|
36
|
+
category: Optional[str] = Field(
|
|
37
|
+
default=None,
|
|
38
|
+
pattern=r"^(general|news|code|docs|papers|images)$",
|
|
39
|
+
description="Search category hint",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class FetchInput(BaseModel):
|
|
44
|
+
"""Input schema for the wigolo fetch tool."""
|
|
45
|
+
|
|
46
|
+
url: str = Field(description="URL of the page to fetch")
|
|
47
|
+
render_js: bool = Field(
|
|
48
|
+
default=False, description="Render JavaScript with the browser engine"
|
|
49
|
+
)
|
|
50
|
+
section: Optional[str] = Field(
|
|
51
|
+
default=None, description="Extract a specific section by heading text"
|
|
52
|
+
)
|
|
53
|
+
max_chars: Optional[int] = Field(
|
|
54
|
+
default=None, ge=0, description="Maximum characters of content to return"
|
|
55
|
+
)
|
|
56
|
+
use_auth: bool = Field(
|
|
57
|
+
default=False, description="Use stored authenticated browser session"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ResearchInput(BaseModel):
|
|
62
|
+
"""Input schema for the wigolo research tool."""
|
|
63
|
+
|
|
64
|
+
question: str = Field(description="The research question to investigate")
|
|
65
|
+
depth: str = Field(
|
|
66
|
+
default="standard",
|
|
67
|
+
pattern=r"^(quick|standard|comprehensive)$",
|
|
68
|
+
description="Research depth",
|
|
69
|
+
)
|
|
70
|
+
max_sources: Optional[int] = Field(
|
|
71
|
+
default=None, ge=1, description="Maximum number of sources to consult"
|
|
72
|
+
)
|
|
73
|
+
include_domains: Optional[list[str]] = Field(
|
|
74
|
+
default=None, description="Only consult these domains"
|
|
75
|
+
)
|
|
76
|
+
exclude_domains: Optional[list[str]] = Field(
|
|
77
|
+
default=None, description="Never consult these domains"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class CrawlInput(BaseModel):
|
|
82
|
+
"""Input schema for the wigolo crawl tool."""
|
|
83
|
+
|
|
84
|
+
url: str = Field(description="Seed URL to start crawling from")
|
|
85
|
+
strategy: str = Field(
|
|
86
|
+
default="bfs",
|
|
87
|
+
pattern=r"^(sitemap|bfs|dfs|map)$",
|
|
88
|
+
description="Crawl strategy",
|
|
89
|
+
)
|
|
90
|
+
max_depth: Optional[int] = Field(
|
|
91
|
+
default=None, ge=0, description="Maximum link depth to follow"
|
|
92
|
+
)
|
|
93
|
+
max_pages: Optional[int] = Field(
|
|
94
|
+
default=None, ge=1, description="Maximum number of pages to visit"
|
|
95
|
+
)
|
|
96
|
+
include_patterns: Optional[list[str]] = Field(
|
|
97
|
+
default=None, description="Only crawl URLs matching these patterns"
|
|
98
|
+
)
|
|
99
|
+
exclude_patterns: Optional[list[str]] = Field(
|
|
100
|
+
default=None, description="Skip URLs matching these patterns"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ExtractInput(BaseModel):
|
|
105
|
+
"""Input schema for the wigolo extract tool.
|
|
106
|
+
|
|
107
|
+
The ``schema`` field intentionally uses the wigolo SDK's parameter name;
|
|
108
|
+
it emits a benign Pydantic warning about shadowing ``BaseModel.schema``.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
url: str = Field(description="URL to extract structured data from")
|
|
112
|
+
mode: str = Field(
|
|
113
|
+
default="structured",
|
|
114
|
+
pattern=r"^(structured|schema|tables|metadata|selector)$",
|
|
115
|
+
description="Extraction mode",
|
|
116
|
+
)
|
|
117
|
+
schema: Optional[Any] = Field(
|
|
118
|
+
default=None, description="JSON Schema for schema-mode extraction"
|
|
119
|
+
)
|
|
120
|
+
css_selector: Optional[str] = Field(
|
|
121
|
+
default=None, description="CSS selector for selector-mode extraction"
|
|
122
|
+
)
|