Skip to content

About

LangChain tools for Clawifi: web search and page reading for AI agents (langchain-clawifi)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

langchain-clawifi

LangChain tools for Clawifi: web search and page reading for agents.

  • ClawifiSearch searches the web (POST /search/free) and returns title, URL and snippet for each result.
  • 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.

Both tools wrap the official clawifi Python SDK and support sync and async calls.

Source: https://github.com/ReARCLabs/clawifi-langchain

Install

pip install -U langchain-clawifi

Credentials

Set CLAWIFI_API_KEY, or pass api_key= to a tool. Keys come from clawifi.dev.

export CLAWIFI_API_KEY="..."

Without a key the tools still work, through the keyless trial below.

Keyless trial

The Clawifi REST API needs a key. Without one, the tools call the trial tools of Clawifi's hosted MCP server instead (Remote MCP): search_free and fetch_url at https://api.clawifi.dev/mcp. The trial's limits, from the Clawifi docs:

  • 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.
  • Search returns at most 3 results, and domain and time filters are not applied.
  • Fetched pages are cut at 20,000 characters; with query, up to 3 passages come back.
  • Usually the day's limit comes back as HTTP 401 ("keyless limit reached") and the minute's limit as HTTP 429 with Retry-After.

A free account has 1,000 credits a month (sign up). With a key, the tools use the REST API and your plan's limits.

ClawifiSearch returns the same shape with or without a key. Without a key it adds one field, keyless_note, which says which limits applied:

{
    "results": [{"rank": 1, "title": "...", "url": "https://...", "snippet": "..."}],
    "keyless_note": "Keyless trial through Clawifi's hosted MCP server: at most 3 results, ...",
}

ClawifiFetch returns the same fields with or without a key. The render option is not sent without a key.

Use the tools directly

from langchain_clawifi import ClawifiFetch, ClawifiSearch

search = ClawifiSearch(max_results=5)
out = search.invoke({"query": "what is the Model Context Protocol"})
# {"results": [{"rank": 1, "title": "...", "url": "https://...", "snippet": "..."}, ...]}
# Without a key, out also has "keyless_note".

fetch = ClawifiFetch(max_chars=8000)
page = fetch.invoke({"url": out["results"][0]["url"], "query": "who maintains it?"})
# {"url": "...", "title": "...", "content_status": "ok", "content": "..."}

Use them in an agent

from langchain.agents import create_agent
from langchain_clawifi import ClawifiFetch, ClawifiSearch

agent = create_agent(
    model="anthropic:claude-sonnet-5-5",
    tools=[ClawifiSearch(), ClawifiFetch()],
)
agent.invoke({"messages": [{"role": "user", "content": "Summarize the latest MCP spec changes."}]})

Options

Tool Option Default Meaning
both api_key CLAWIFI_API_KEY API key; optional
both api_base SDK default Override the API URL
both client / async_client built on first call Pass your own clawifi.Clawifi / AsyncClawifi; see Clients and sessions
ClawifiSearch max_results 5 Results per call when the call does not set one
ClawifiSearch country, language none Passed to the search
ClawifiFetch max_chars 20000 Cut the returned Markdown to this length
ClawifiFetch render API default "never", "auto" or "always"

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.

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.

Clients and sessions

  • 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.
  • 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.
  • 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.
  • 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.

Costs

Each search or fetch call uses Clawifi credits; see Pricing and credits.

Development

pip install -e . pytest pytest-asyncio "langchain-tests>=1.1.9,<2"
pytest

The unit tests mock every HTTP call and never reach the network.

License

MIT

About

LangChain tools for Clawifi: web search and page reading for AI agents (langchain-clawifi)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages