Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/langchain-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: LangChain CI

on:
pull_request:
branches: [main]
paths:
- ".github/workflows/langchain-ci.yml"
- "langchain/**"
push:
branches: [main]
paths:
- ".github/workflows/langchain-ci.yml"
- "langchain/**"

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

defaults:
run:
working-directory: langchain

steps:
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
python-version: "3.12"

- run: python -m pip install --upgrade pip

- run: python -m pip install -e . -r requirements-dev.txt

- run: make lint

- run: make test

- run: python -m build
34 changes: 34 additions & 0 deletions .github/workflows/langchain-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: LangChain Publish

on:
push:
tags:
- "langchain-v*"

permissions:
contents: read
id-token: write

jobs:
publish:
if: startsWith(github.ref, 'refs/tags/langchain-v')
runs-on: ubuntu-latest

defaults:
run:
working-directory: langchain

steps:
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
python-version: "3.12"

- run: python -m pip install --upgrade pip build

- run: python -m build

- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: langchain/dist
12 changes: 12 additions & 0 deletions langchain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.egg-info/
*.egg
dist/
build/
__pycache__/
*.pyc
*.pyo
.env
.claude/
.mypy_cache/
.ruff_cache/
.pytest_cache/
21 changes: 21 additions & 0 deletions langchain/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 TinyFish

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions langchain/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: all format lint test integration_test check_imports clean

all: format lint test

TEST_FILE ?= tests/unit_tests/
integration_test: TEST_FILE = tests/integration_tests/

format:
ruff format langchain_tinyfish tests
ruff check --fix langchain_tinyfish tests

lint:
ruff check langchain_tinyfish tests
mypy langchain_tinyfish

test integration_test:
pytest $(TEST_FILE) -v

check_imports: $(shell find langchain_tinyfish -name '*.py')
python scripts/check_imports.py $^

clean:
rm -rf build dist *.egg-info .pytest_cache .mypy_cache .ruff_cache
find . -type d -name __pycache__ -exec rm -rf {} +
166 changes: 166 additions & 0 deletions langchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# TinyFish Web Agent for LangChain

![Powered by TinyFish](https://img.shields.io/badge/Powered%20by-TinyFish-blue)

This package provides a LangChain Tool to run the TinyFish Web Agent directly within your LangChain Agents and Workflows.

TinyFish is a platform for executing complex, goal-oriented tasks on the live web. Unlike traditional scrapers or local browser automation, TinyFish uses a fleet of remote, AI-powered web agents that can navigate complex sites, handle anti-bot protection, and return clean, structured JSON data.

## Installation

```bash
pip install langchain-tinyfish
```

## Configuration

1. Get your TinyFish API key from [agent.tinyfish.ai/api-keys](https://agent.tinyfish.ai/api-keys).
2. Set it as an environment variable:

```bash
export TINYFISH_API_KEY="YOUR_API_KEY"
```

## Quick Start

Here is a simple example of how to use the TinyFish Web Agent to extract the current stock price of NVIDIA from Yahoo Finance.

```python
from langchain_tinyfish import TinyFishWebAutomation

tool = TinyFishWebAutomation()

result = tool.invoke({
"url": "https://finance.yahoo.com/quote/NVDA/",
"goal": "Extract the current stock price of NVIDIA",
})

print(result)
# Output: {"stock_price": 950.02}
```

### Search, Fetch, and Browser Sessions

The package also exposes SDK-backed tools for TinyFish Search, Fetch, and Browser sessions:

```python
from langchain_tinyfish import (
TinyFishBrowserSession,
TinyFishFetch,
TinyFishSearch,
)

search = TinyFishSearch()
fetch = TinyFishFetch()
browser = TinyFishBrowserSession()

search_results = search.invoke({"query": "TinyFish Web Agent docs"})
page_content = fetch.invoke({"urls": ["https://docs.tinyfish.ai"], "format": "markdown"})
session = browser.invoke({"url": "https://example.com"})
```

### With a LangChain Agent

```python
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_tinyfish import TinyFishFetch, TinyFishSearch, TinyFishWebAutomation

llm = ChatOpenAI(model="gpt-4o")
tools = [
TinyFishWebAutomation(),
TinyFishSearch(),
TinyFishFetch(),
]
agent = create_react_agent(llm, tools)

result = agent.invoke({
"messages": [("user", "Go to scrapeme.live/shop and extract the first 5 product names and prices")]
})

for message in result["messages"]:
print(message.content)
```

### Stealth Mode + Proxy

For sites with bot protection (Cloudflare, CAPTCHAs, etc.):

```python
from langchain_tinyfish import TinyFishAPIWrapper, TinyFishWebAutomation

tool = TinyFishWebAutomation(
api_wrapper=TinyFishAPIWrapper(
browser_profile="stealth",
proxy_enabled=True,
proxy_country_code="US", # Also: GB, CA, DE, FR, JP, AU
)
)
```

### Async Usage

```python
import asyncio
from langchain_tinyfish import TinyFishWebAutomation

async def main():
tool = TinyFishWebAutomation()
result = await tool.ainvoke({
"url": "https://example.com",
"goal": "Extract the page title",
})
print(result)

asyncio.run(main())
```

## Use Cases

- **AI Agent Enablement:** Give your AI agent the ability to perform deep research on the web.
- **Workflow Automation:** Monitor a competitor's pricing page and get a Slack notification when it changes.
- **Data Extraction:** Extract job postings, product details, or contact information into a structured format.

## Configuration Options

All parameters are set on the `TinyFishAPIWrapper`:

| Parameter | Default | Description |
|-----------|---------|-------------|
| `api_key` | `$TINYFISH_API_KEY` | Your TinyFish API key |
| `browser_profile` | `"lite"` | `"lite"` (fast) or `"stealth"` (anti-detection) |
| `proxy_enabled` | `False` | Enable proxy routing |
| `proxy_country_code` | `"US"` | Proxy country: US, GB, CA, DE, FR, JP, AU |
| `timeout` | `300` | Request timeout in seconds |

```python
from langchain_tinyfish import TinyFishAPIWrapper, TinyFishWebAutomation

wrapper = TinyFishAPIWrapper(
api_key="sk-mino-...",
browser_profile="stealth",
timeout=600,
)
tool = TinyFishWebAutomation(api_wrapper=wrapper)
```

## Development

```bash
# Install package + dev dependencies
pip install -e .
pip install -r requirements-dev.txt

# Run unit tests
make test

# Run linter
make lint

# Run integration tests (requires TINYFISH_API_KEY)
make integration_test
```

## Support

If you have any questions or need help, please reach out to [support@tinyfish.ai](mailto:support@tinyfish.ai) or join our [Discord community](https://discord.gg/agentql).
33 changes: 33 additions & 0 deletions langchain/langchain_tinyfish/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""LangChain integration for TinyFish Web Agent."""

from importlib import metadata

from langchain_tinyfish._api_wrapper import TinyFishAPIWrapper
from langchain_tinyfish.tool import (
TinyFishBrowserSession,
TinyFishBrowserSessionInput,
TinyFishFetch,
TinyFishFetchInput,
TinyFishInput,
TinyFishSearch,
TinyFishSearchInput,
TinyFishWebAutomation,
)

try:
__version__: str = metadata.version(__package__ or __name__)
except metadata.PackageNotFoundError:
__version__ = ""

__all__ = [
"TinyFishAPIWrapper",
"TinyFishBrowserSession",
"TinyFishBrowserSessionInput",
"TinyFishFetch",
"TinyFishFetchInput",
"TinyFishInput",
"TinyFishSearch",
"TinyFishSearchInput",
"TinyFishWebAutomation",
"__version__",
]
Loading