langchain-clawifi 0.1.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.
- langchain_clawifi-0.1.0/.gitignore +8 -0
- langchain_clawifi-0.1.0/LICENSE +21 -0
- langchain_clawifi-0.1.0/PKG-INFO +137 -0
- langchain_clawifi-0.1.0/README.md +116 -0
- langchain_clawifi-0.1.0/langchain_clawifi/__init__.py +26 -0
- langchain_clawifi-0.1.0/langchain_clawifi/_keyless.py +636 -0
- langchain_clawifi-0.1.0/langchain_clawifi/py.typed +0 -0
- langchain_clawifi-0.1.0/langchain_clawifi/tools.py +415 -0
- langchain_clawifi-0.1.0/pyproject.toml +55 -0
- langchain_clawifi-0.1.0/tests/__init__.py +0 -0
- langchain_clawifi-0.1.0/tests/conftest.py +18 -0
- langchain_clawifi-0.1.0/tests/unit_tests/__init__.py +0 -0
- langchain_clawifi-0.1.0/tests/unit_tests/conftest.py +56 -0
- langchain_clawifi-0.1.0/tests/unit_tests/fake_mcp.py +167 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_keyless.py +176 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_review2_fixes.py +82 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_review3_fixes.py +136 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_review4_fixes.py +70 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_review5_fixes.py +291 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_review6_fixes.py +179 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_review_fixes.py +166 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_standard.py +37 -0
- langchain_clawifi-0.1.0/tests/unit_tests/test_tools.py +190 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ReARC Labs Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-clawifi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain tools for Clawifi web search and page reading.
|
|
5
|
+
Project-URL: Homepage, https://clawifi.dev
|
|
6
|
+
Project-URL: Documentation, https://clawifi.dev/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/ReARCLabs/clawifi-langchain
|
|
8
|
+
Project-URL: Issues, https://github.com/ReARCLabs/clawifi-langchain/issues
|
|
9
|
+
Author: ReARC Labs Inc.
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,clawifi,langchain,tools,web-search
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: <4.0,>=3.11
|
|
17
|
+
Requires-Dist: clawifi<0.5,>=0.4.5
|
|
18
|
+
Requires-Dist: httpx<1,>=0.27.2
|
|
19
|
+
Requires-Dist: langchain-core<2.0.0,>=1.4.7
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# langchain-clawifi
|
|
23
|
+
|
|
24
|
+
LangChain tools for [Clawifi](https://clawifi.dev): web search and page reading for agents.
|
|
25
|
+
|
|
26
|
+
- `ClawifiSearch` searches the web (`POST /search/free`) and returns title, URL and snippet for each result.
|
|
27
|
+
- `ClawifiFetch` reads a page or PDF (`POST /fetch`) and returns its main content as Markdown. Pass a `query` to get only the passages that answer it.
|
|
28
|
+
|
|
29
|
+
Both tools wrap the official [`clawifi`](https://pypi.org/project/clawifi/) Python SDK and support sync and async calls.
|
|
30
|
+
|
|
31
|
+
Source: <https://github.com/ReARCLabs/clawifi-langchain>
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -U langchain-clawifi
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Credentials
|
|
40
|
+
|
|
41
|
+
Set `CLAWIFI_API_KEY`, or pass `api_key=` to a tool. Keys come from [clawifi.dev](https://clawifi.dev/docs/authentication).
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export CLAWIFI_API_KEY="..."
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Without a key the tools still work, through the keyless trial below.
|
|
48
|
+
|
|
49
|
+
## Keyless trial
|
|
50
|
+
|
|
51
|
+
The Clawifi REST API needs a key. Without one, the tools call the trial tools of Clawifi's hosted MCP server instead ([Remote MCP](https://clawifi.dev/docs/remote-mcp)): `search_free` and `fetch_url` at `https://api.clawifi.dev/mcp`. The trial's limits, from the Clawifi docs:
|
|
52
|
+
|
|
53
|
+
- 12 calls a minute and 50 a day per address. On a shared host (serverless, CI) many apps can share one outbound address, so set `CLAWIFI_API_KEY` in production.
|
|
54
|
+
- Search returns at most 3 results, and domain and time filters are not applied.
|
|
55
|
+
- Fetched pages are cut at 20,000 characters; with `query`, up to 3 passages come back.
|
|
56
|
+
- Usually the day's limit comes back as HTTP 401 ("keyless limit reached") and the minute's limit as HTTP 429 with `Retry-After`.
|
|
57
|
+
|
|
58
|
+
A free account has 1,000 credits a month ([sign up](https://clawifi.dev/signup)). With a key, the tools use the REST API and your plan's limits.
|
|
59
|
+
|
|
60
|
+
`ClawifiSearch` returns the same shape with or without a key. Without a key it adds one field, `keyless_note`, which says which limits applied:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
{
|
|
64
|
+
"results": [{"rank": 1, "title": "...", "url": "https://...", "snippet": "..."}],
|
|
65
|
+
"keyless_note": "Keyless trial through Clawifi's hosted MCP server: at most 3 results, ...",
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`ClawifiFetch` returns the same fields with or without a key. The `render` option is not sent without a key.
|
|
70
|
+
|
|
71
|
+
## Use the tools directly
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from langchain_clawifi import ClawifiFetch, ClawifiSearch
|
|
75
|
+
|
|
76
|
+
search = ClawifiSearch(max_results=5)
|
|
77
|
+
out = search.invoke({"query": "what is the Model Context Protocol"})
|
|
78
|
+
# {"results": [{"rank": 1, "title": "...", "url": "https://...", "snippet": "..."}, ...]}
|
|
79
|
+
# Without a key, out also has "keyless_note".
|
|
80
|
+
|
|
81
|
+
fetch = ClawifiFetch(max_chars=8000)
|
|
82
|
+
page = fetch.invoke({"url": out["results"][0]["url"], "query": "who maintains it?"})
|
|
83
|
+
# {"url": "...", "title": "...", "content_status": "ok", "content": "..."}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Use them in an agent
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from langchain.agents import create_agent
|
|
90
|
+
from langchain_clawifi import ClawifiFetch, ClawifiSearch
|
|
91
|
+
|
|
92
|
+
agent = create_agent(
|
|
93
|
+
model="anthropic:claude-sonnet-5-5",
|
|
94
|
+
tools=[ClawifiSearch(), ClawifiFetch()],
|
|
95
|
+
)
|
|
96
|
+
agent.invoke({"messages": [{"role": "user", "content": "Summarize the latest MCP spec changes."}]})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Options
|
|
100
|
+
|
|
101
|
+
| Tool | Option | Default | Meaning |
|
|
102
|
+
| --- | --- | --- | --- |
|
|
103
|
+
| both | `api_key` | `CLAWIFI_API_KEY` | API key; optional |
|
|
104
|
+
| both | `api_base` | SDK default | Override the API URL |
|
|
105
|
+
| both | `client` / `async_client` | built on first call | Pass your own `clawifi.Clawifi` / `AsyncClawifi`; see Clients and sessions |
|
|
106
|
+
| `ClawifiSearch` | `max_results` | `5` | Results per call when the call does not set one |
|
|
107
|
+
| `ClawifiSearch` | `country`, `language` | none | Passed to the search |
|
|
108
|
+
| `ClawifiFetch` | `max_chars` | `20000` | Cut the returned Markdown to this length |
|
|
109
|
+
| `ClawifiFetch` | `render` | API default | `"never"`, `"auto"` or `"always"` |
|
|
110
|
+
|
|
111
|
+
Call arguments the model can set: `query`, `max_results`, `time_range` (`day`/`week`/`month`/`year`), `include_domains`, `exclude_domains` for search; `url`, `query` for fetch.
|
|
112
|
+
|
|
113
|
+
API errors, including keyless trial limits, are raised as `ToolException`. Set `handle_tool_error=True` on a tool to return the error text to the model instead.
|
|
114
|
+
|
|
115
|
+
### Clients and sessions
|
|
116
|
+
|
|
117
|
+
- **Path:** A key, or any client you pass, selects the REST API. The keyless trial is used only when there is neither. A key of only whitespace counts as no key, whether it is passed as an argument or set in `CLAWIFI_API_KEY`.
|
|
118
|
+
- **Sync and async:** With a key, a mode whose client you did not pass is built with that key. It uses the `api_base` of the client you did pass, unless you set `api_base` yourself. Without a key, pass both `client` and `async_client` if you call both modes; if you pass only one, calls in the other mode raise `ClawifiClientConfigError`.
|
|
119
|
+
- **Trial calls:** Clawifi's hosted MCP server is stateless, so each keyless call is a single `tools/call` request. If a server explicitly asks for initialization (JSON-RPC error -32002, or a "not initialized" / "missing session" / `Mcp-Session-Id` message), the call initializes once, retries, and then ends any session the server opened. A 404 after that fallback is not retried; the hosted server is stateless, so this does not come up there. The trial limits count tool calls. Use `CLAWIFI_API_KEY` in production.
|
|
120
|
+
- **Closing:** `close()` closes the sync HTTP client, and the next call builds a new one. `aclose()` has nothing to close. A transport you pass in is never closed.
|
|
121
|
+
|
|
122
|
+
## Costs
|
|
123
|
+
|
|
124
|
+
Each search or fetch call uses Clawifi credits; see [Pricing and credits](https://clawifi.dev/docs/pricing-and-credits).
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install -e . pytest pytest-asyncio "langchain-tests>=1.1.9,<2"
|
|
130
|
+
pytest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The unit tests mock every HTTP call and never reach the network.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# langchain-clawifi
|
|
2
|
+
|
|
3
|
+
LangChain tools for [Clawifi](https://clawifi.dev): web search and page reading for agents.
|
|
4
|
+
|
|
5
|
+
- `ClawifiSearch` searches the web (`POST /search/free`) and returns title, URL and snippet for each result.
|
|
6
|
+
- `ClawifiFetch` reads a page or PDF (`POST /fetch`) and returns its main content as Markdown. Pass a `query` to get only the passages that answer it.
|
|
7
|
+
|
|
8
|
+
Both tools wrap the official [`clawifi`](https://pypi.org/project/clawifi/) Python SDK and support sync and async calls.
|
|
9
|
+
|
|
10
|
+
Source: <https://github.com/ReARCLabs/clawifi-langchain>
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install -U langchain-clawifi
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Credentials
|
|
19
|
+
|
|
20
|
+
Set `CLAWIFI_API_KEY`, or pass `api_key=` to a tool. Keys come from [clawifi.dev](https://clawifi.dev/docs/authentication).
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export CLAWIFI_API_KEY="..."
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Without a key the tools still work, through the keyless trial below.
|
|
27
|
+
|
|
28
|
+
## Keyless trial
|
|
29
|
+
|
|
30
|
+
The Clawifi REST API needs a key. Without one, the tools call the trial tools of Clawifi's hosted MCP server instead ([Remote MCP](https://clawifi.dev/docs/remote-mcp)): `search_free` and `fetch_url` at `https://api.clawifi.dev/mcp`. The trial's limits, from the Clawifi docs:
|
|
31
|
+
|
|
32
|
+
- 12 calls a minute and 50 a day per address. On a shared host (serverless, CI) many apps can share one outbound address, so set `CLAWIFI_API_KEY` in production.
|
|
33
|
+
- Search returns at most 3 results, and domain and time filters are not applied.
|
|
34
|
+
- Fetched pages are cut at 20,000 characters; with `query`, up to 3 passages come back.
|
|
35
|
+
- Usually the day's limit comes back as HTTP 401 ("keyless limit reached") and the minute's limit as HTTP 429 with `Retry-After`.
|
|
36
|
+
|
|
37
|
+
A free account has 1,000 credits a month ([sign up](https://clawifi.dev/signup)). With a key, the tools use the REST API and your plan's limits.
|
|
38
|
+
|
|
39
|
+
`ClawifiSearch` returns the same shape with or without a key. Without a key it adds one field, `keyless_note`, which says which limits applied:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
{
|
|
43
|
+
"results": [{"rank": 1, "title": "...", "url": "https://...", "snippet": "..."}],
|
|
44
|
+
"keyless_note": "Keyless trial through Clawifi's hosted MCP server: at most 3 results, ...",
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`ClawifiFetch` returns the same fields with or without a key. The `render` option is not sent without a key.
|
|
49
|
+
|
|
50
|
+
## Use the tools directly
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from langchain_clawifi import ClawifiFetch, ClawifiSearch
|
|
54
|
+
|
|
55
|
+
search = ClawifiSearch(max_results=5)
|
|
56
|
+
out = search.invoke({"query": "what is the Model Context Protocol"})
|
|
57
|
+
# {"results": [{"rank": 1, "title": "...", "url": "https://...", "snippet": "..."}, ...]}
|
|
58
|
+
# Without a key, out also has "keyless_note".
|
|
59
|
+
|
|
60
|
+
fetch = ClawifiFetch(max_chars=8000)
|
|
61
|
+
page = fetch.invoke({"url": out["results"][0]["url"], "query": "who maintains it?"})
|
|
62
|
+
# {"url": "...", "title": "...", "content_status": "ok", "content": "..."}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Use them in an agent
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from langchain.agents import create_agent
|
|
69
|
+
from langchain_clawifi import ClawifiFetch, ClawifiSearch
|
|
70
|
+
|
|
71
|
+
agent = create_agent(
|
|
72
|
+
model="anthropic:claude-sonnet-5-5",
|
|
73
|
+
tools=[ClawifiSearch(), ClawifiFetch()],
|
|
74
|
+
)
|
|
75
|
+
agent.invoke({"messages": [{"role": "user", "content": "Summarize the latest MCP spec changes."}]})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Options
|
|
79
|
+
|
|
80
|
+
| Tool | Option | Default | Meaning |
|
|
81
|
+
| --- | --- | --- | --- |
|
|
82
|
+
| both | `api_key` | `CLAWIFI_API_KEY` | API key; optional |
|
|
83
|
+
| both | `api_base` | SDK default | Override the API URL |
|
|
84
|
+
| both | `client` / `async_client` | built on first call | Pass your own `clawifi.Clawifi` / `AsyncClawifi`; see Clients and sessions |
|
|
85
|
+
| `ClawifiSearch` | `max_results` | `5` | Results per call when the call does not set one |
|
|
86
|
+
| `ClawifiSearch` | `country`, `language` | none | Passed to the search |
|
|
87
|
+
| `ClawifiFetch` | `max_chars` | `20000` | Cut the returned Markdown to this length |
|
|
88
|
+
| `ClawifiFetch` | `render` | API default | `"never"`, `"auto"` or `"always"` |
|
|
89
|
+
|
|
90
|
+
Call arguments the model can set: `query`, `max_results`, `time_range` (`day`/`week`/`month`/`year`), `include_domains`, `exclude_domains` for search; `url`, `query` for fetch.
|
|
91
|
+
|
|
92
|
+
API errors, including keyless trial limits, are raised as `ToolException`. Set `handle_tool_error=True` on a tool to return the error text to the model instead.
|
|
93
|
+
|
|
94
|
+
### Clients and sessions
|
|
95
|
+
|
|
96
|
+
- **Path:** A key, or any client you pass, selects the REST API. The keyless trial is used only when there is neither. A key of only whitespace counts as no key, whether it is passed as an argument or set in `CLAWIFI_API_KEY`.
|
|
97
|
+
- **Sync and async:** With a key, a mode whose client you did not pass is built with that key. It uses the `api_base` of the client you did pass, unless you set `api_base` yourself. Without a key, pass both `client` and `async_client` if you call both modes; if you pass only one, calls in the other mode raise `ClawifiClientConfigError`.
|
|
98
|
+
- **Trial calls:** Clawifi's hosted MCP server is stateless, so each keyless call is a single `tools/call` request. If a server explicitly asks for initialization (JSON-RPC error -32002, or a "not initialized" / "missing session" / `Mcp-Session-Id` message), the call initializes once, retries, and then ends any session the server opened. A 404 after that fallback is not retried; the hosted server is stateless, so this does not come up there. The trial limits count tool calls. Use `CLAWIFI_API_KEY` in production.
|
|
99
|
+
- **Closing:** `close()` closes the sync HTTP client, and the next call builds a new one. `aclose()` has nothing to close. A transport you pass in is never closed.
|
|
100
|
+
|
|
101
|
+
## Costs
|
|
102
|
+
|
|
103
|
+
Each search or fetch call uses Clawifi credits; see [Pricing and credits](https://clawifi.dev/docs/pricing-and-credits).
|
|
104
|
+
|
|
105
|
+
## Development
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install -e . pytest pytest-asyncio "langchain-tests>=1.1.9,<2"
|
|
109
|
+
pytest
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The unit tests mock every HTTP call and never reach the network.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""LangChain integration for Clawifi: web search and page reading for agents."""
|
|
2
|
+
|
|
3
|
+
from importlib import metadata
|
|
4
|
+
|
|
5
|
+
from langchain_clawifi._keyless import ClawifiClientConfigError, ClawifiKeylessError
|
|
6
|
+
from langchain_clawifi.tools import (
|
|
7
|
+
ClawifiFetch,
|
|
8
|
+
ClawifiFetchInput,
|
|
9
|
+
ClawifiSearch,
|
|
10
|
+
ClawifiSearchInput,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
__version__ = metadata.version(__package__)
|
|
15
|
+
except metadata.PackageNotFoundError: # pragma: no cover
|
|
16
|
+
__version__ = ""
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ClawifiClientConfigError",
|
|
20
|
+
"ClawifiFetch",
|
|
21
|
+
"ClawifiKeylessError",
|
|
22
|
+
"ClawifiFetchInput",
|
|
23
|
+
"ClawifiSearch",
|
|
24
|
+
"ClawifiSearchInput",
|
|
25
|
+
"__version__",
|
|
26
|
+
]
|