Skip to main content

langchain-agentfetch

Drop-in LangChain Tool wrappers for AgentFetch — token-budgeted web fetch for AI agents.

License: MIT PyPI

Stop building your own web fetch / token-truncation / cache layer for every LangChain agent. AgentFetch handles routing (Trafilatura → Jina → FireCrawl → PDF), caching (6h Redis), and token budgeting in one tool.

Install

pip install langchain-agentfetch

Quick start

Get a free API key (500 fetches/mo, no credit card) at agentfetch.dev.

import os
from langchain_agentfetch import AgentFetchTool

os.environ["AGENTFETCH_API_KEY"] = "af_xxx"

tool = AgentFetchTool()
result = tool.invoke({"url": "https://news.ycombinator.com", "max_tokens": 2000})
print(result)

All four tools

Tool When to use
AgentFetchTool (fetch_url) You have a specific URL to fetch
EstimateTokensTool You want to know if a URL fits your context window before fetching
FetchMultipleTool You have multiple URLs (search results, link lists)
SearchAndFetchTool You have a research question, not specific URLs

Use the toolkit (recommended for agents)

from langchain.agents import create_agent
from langchain_agentfetch import AgentFetchToolkit

toolkit = AgentFetchToolkit(api_key="af_xxx")
tools = toolkit.get_tools()

agent = create_agent(
    model="openai:gpt-4o-mini",
    tools=tools,
    system_prompt=(
        "You are a research assistant. Estimate tokens before fetching long URLs."
    ),
)

agent.invoke({
    "messages": [{"role": "user", "content": "What's on Hacker News now?"}]
})

The agent will:

  1. Use agentfetch_search_and_fetch or agentfetch_fetch_url to get the page
  2. Get clean Markdown back, already token-truncated
  3. Reason over it without blowing the context window

Configuration

Env var Default Notes
AGENTFETCH_API_KEY required Get one free at agentfetch.dev
AGENTFETCH_BASE_URL https://api.agentfetch.dev Override only if self-hosting

You can also pass api_key= and base_url= directly to any Tool / Toolkit constructor.

Why a token-aware fetch tool

LangChain's default tools (like requests_get) return raw HTML/JSON with no truncation, no awareness of your context budget, and no caching. That works at toy scale; it falls over the moment your agent fetches a 50KB news article into a 4K context window.

AgentFetch was built for that case:

  • Pre-fetch token estimation so the agent can skip a URL it can't afford
  • Server-side max_tokens truncation before the response leaves the API
  • 6-hour cache for repeat fetches (~$0.0001 each)
  • Auto-routing so the agent doesn't pick between Jina, FireCrawl, and pypdf manually

Pricing

Same pay-per-call pricing as the AgentFetch API: from $0.001/fetch, 500 free on signup. No subscription required. See agentfetch.dev/pricing.

License

MIT.

Metadata

Release files for langchain-agentfetch 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-agentfetch 0.1.1
File Size Uploaded Provenance Actions
langchain_agentfetch-0.1.1.tar.gz 8.8 kB Without provenance Details for langchain_agentfetch-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-agentfetch 0.1.1
File Interpreter ABI Platform Actions
langchain_agentfetch-0.1.1-py3-none-any.whl Python 3 none any Details for langchain_agentfetch-0.1.1-py3-none-any.whl

Total release size: 18.0 kB

Release files / langchain_agentfetch-0.1.1.tar.gz

Download URL langchain_agentfetch-0.1.1.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
eb9e684549f1322bbf3b0ac8ca537b4cc7e2eeb6dc11c5f8f312cc22f2d31114
BLAKE2b-256 checksum
How to use checksums
96a83c0dda6e177158ba28a395974f5c8b54a81799f01c556881210e35789ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release files / langchain_agentfetch-0.1.1-py3-none-any.whl

Download URL langchain_agentfetch-0.1.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d26e148833aa1a20574ddb02db7845de71d4878bb82fd221ee3c16b8eed7e072
BLAKE2b-256 checksum
How to use checksums
ec74769fd1b59c5da8b8ed6da0315fd81379fc11a0c57060a33b2a4d452cec7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Security for langchain-agentfetch 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page