Skip to main content

langchain-octen

PyPI version License: MIT

LangChain integration for Octen Web Search. Use Octen's fast, real-time web search inside LangChain agents and chains.

Tool class Tool name Use it for
OctenSearchResults octen_search One focused web lookup
OctenBroadSearch octen_broad_search Multi-part questions, comparisons, surveys (fans out into sub-queries)
OctenNewsSearch octen_news_search Recent news, with articles grouped into storylines
OctenBusinessSearch octen_business_search Company and person cards (financials, key people, career history)
OctenPulseSearch octen_pulse_search The URL of a docs page or site you could almost name
OctenPlaceSearch octen_place_search Real-world places, near a point or in a city

Installation

pip install langchain-octen

Setup

Get an API key from octen.ai and set it as an environment variable:

export OCTEN_API_KEY="your-api-key"

Or pass it directly when creating the tool:

from langchain_octen import OctenSearchResults

tool = OctenSearchResults(octen_api_key="your-api-key")

Web search (OctenSearchResults)

from langchain_octen import OctenSearchResults

tool = OctenSearchResults(max_results=5)
results = tool.invoke({"query": "latest AI research papers"})
for r in results:
    print(r["title"], r["url"])

With Domain Filtering

# Only include results from specific domains
results = tool.invoke({
    "query": "machine learning",
    "include_domains": ["arxiv.org", "papers.nips.cc"],
})

# Exclude results from specific domains
results = tool.invoke({
    "query": "Python tutorial",
    "exclude_domains": ["youtube.com", "reddit.com"],
})

In a LangChain Agent

from langchain_octen import OctenSearchResults
from langgraph.prebuilt import create_react_agent

tool = OctenSearchResults(max_results=5)
agent = create_react_agent(llm, [tool])
response = agent.invoke({"messages": [("user", "What happened in AI today?")]})

Async Support

import asyncio
from langchain_octen import OctenSearchResults

tool = OctenSearchResults(max_results=3)

async def main():
    results = await tool.ainvoke({"query": "Python 3.13 new features"})
    print(results)

asyncio.run(main())

Advanced Options

from langchain_octen import OctenSearchResults

# Time-filtered search
tool = OctenSearchResults(
    max_results=5,
    time_basis="published",
    start_time="2025-01-01",
    end_time="2026-03-30",
)
results = tool.invoke({"query": "Python release notes"})

# Search with highlighted snippets
tool = OctenSearchResults(
    max_results=5,
    highlight_enabled=True,
    highlight_max_tokens=200,
)
results = tool.invoke({"query": "LangChain tutorial"})

# Search with full page content
tool = OctenSearchResults(
    max_results=3,
    full_content_enabled=True,
    full_content_max_tokens=1000,
)
results = tool.invoke({"query": "Python documentation"})

Vertical search tools

OctenBroadSearch, OctenNewsSearch, OctenBusinessSearch, OctenPulseSearch and OctenPlaceSearch share one design:

  • The model only controls the query and search filters; you control the billing-related options and limits (result counts, highlight / full content, Broad max_queries, ...) when you construct the tool. Options you leave unset are not sent, so the server defaults apply. Broad Search is billed per sub-query: max_queries is an upper bound, and how many sub-queries a question actually produces depends on the query.

  • Every call returns a dict:

    {
        "data": {...},          # the response's data, unchanged (results, places, entities, ...)
        "request_id": "...",    # quote it when contacting support
        "warning": "...",       # only present when the API attached a non-empty warning
    }
    
  • Errors are split by who can fix them.

    • Raised to your code: authentication failure (octen.OctenAuthenticationError, 401), no access or insufficient balance (octen.OctenAPIError with status 403) and other 4xx responses. Some agent runtimes catch exceptions raised by tools, so each of these is also logged at ERROR level to the langchain_octen logger.
    • Constructor options are checked when the tool is built: an out-of-range value (count=1000), a misspelt option name (max_querys=3) or a timeout that is not a positive finite number raises ValueError naming it.
    • Handed to the model as the tool result (a ToolException with handle_tool_error=True): rate limits (429), server errors (5xx), 400/408/422 responses, 2xx responses carrying an error envelope or a malformed body, timeouts and connection errors. For a timeout or connection error that may have happened after the request was sent, a 502 or 504 (a gateway can return these after the backend served the call), or a failed 2xx response, the message also tells the model the call may already have been billed and should not be retried automatically.
    • Invalid model arguments (an unknown time_range, a misspelt argument name such as include_domain, half a coordinate pair, a radius without a point, values out of range) are rejected before any request is made, and the model gets a message naming the argument.
  • Every tool takes octen_api_key (falls back to OCTEN_API_KEY; missing key raises ValueError at construction) and timeout (seconds).

from langchain_octen import (
    OctenBroadSearch,
    OctenBusinessSearch,
    OctenNewsSearch,
    OctenPlaceSearch,
    OctenPulseSearch,
)
from langgraph.prebuilt import create_react_agent

tools = [
    OctenNewsSearch(count=5),
    OctenBusinessSearch(entities={"count": 2}),
    OctenPlaceSearch(places={"count": 5}),
]
agent = create_react_agent(llm, tools)

Broad Search (OctenBroadSearch)

Expands one question into several sub-queries, searches them concurrently, and returns the results grouped per sub-query (data.queries, data.search_results; not deduplicated).

Model arguments Constructor options
query, include_domains, exclude_domains, time_range, language count (per sub-query, 1-100), max_queries (1-30), highlight, full_content, timeout
tool = OctenBroadSearch(max_queries=5, count=3)
result = tool.invoke({"query": "compare managed Postgres providers on price and limits"})
for group in result["data"]["search_results"]:
    print(group["query"], len(group["results"]))

News Search (OctenNewsSearch)

Recent articles plus data.subjects: storylines with a summary and the time span they cover. Domain filters narrow the ranked articles only, not the storylines.

Model arguments Constructor options
query, include_domains, exclude_domains, time_range, language count (1-100), subjects (e.g. {"enable": True, "count": 2, "max_sub_news": 5}), highlight, full_content, timeout
tool = OctenNewsSearch(count=5)
result = tool.invoke({"query": "EU AI Act enforcement", "time_range": "week"})
for storyline in result["data"].get("subjects", []):
    print(storyline["name"], storyline.get("summary"))

Business Search (OctenBusinessSearch)

Company and person cards in data.entities (profile, financial and stock metrics, key people, career history, recent announcements) plus the ranked sources in data.results. The domain, time and language filters narrow the ranked sources only, never the cards.

Model arguments Constructor options
query, include_domains, exclude_domains, time_range, language count (1-100), entities (e.g. {"count": 2, "max_news": 5}), highlight, full_content, timeout
tool = OctenBusinessSearch(entities={"count": 2})
result = tool.invoke({"query": "compare Stripe and Adyen"})
for entity in result["data"].get("entities", []):
    print(entity["name"])

Pulse Search (OctenPulseSearch)

Predicts the URL a query most likely means, in about 10ms: official docs, API references, help centres, sites you could almost name. It takes no filters and sees no fresh content. In lite mode (the server default) URLs come back without a scheme, e.g. github.com/docs.

Model arguments Constructor options
query count (1-10), mode ("lite" or "standard"), highlight, full_content (both only in standard), timeout
tool = OctenPulseSearch(count=3)
result = tool.invoke({"query": "uv documentation"})
print([r["url"] for r in result["data"]["results"]])

Place Search (OctenPlaceSearch)

Real-world places as cards in data.places: name, category, address, coordinates, phone, website, opening hours, status, rating and review count. With latitude and longitude each card carries its distance in metres. When the place engine does not answer in time the result carries "warning": "places_unavailable".

Model arguments Constructor options
query, latitude + longitude (both or neither), radius (1-50000 m, needs a point), user_location (city, region, country, timezone) places (e.g. {"count": 5, "max_reviews": 0}), web_search (e.g. {"enable": True, "count": 3}; off by default), timeout
tool = OctenPlaceSearch(places={"count": 5})
result = tool.invoke(
    {"query": "coffee shops", "latitude": 35.6812, "longitude": 139.7671, "radius": 1000}
)
for place in result["data"].get("places", []):
    print(place["name"], place.get("distance"))

The tool sets user_location.type to "approximate" itself.

Retries

The tools create their octen clients with retry_after_send=False: a request that times out or loses its connection after it may already have reached the server is not retried, because the first attempt may already have been served and billed. Failures known to happen before sending are still retried, and so are 408, 429, 500, 502, 503 and 504 responses. Those status-code retries can still be charged twice: a gateway may return 502 or 504 after the backend has finished. If you also call the API with your own octen.Octen / octen.AsyncOcten client, consider passing retry_after_send=False there too.

Configuration

Constructor options of OctenSearchResults:

Parameter Type Default Description
octen_api_key str env OCTEN_API_KEY Octen API key
max_results int 5 Number of results (1-100)
search_type str None Deprecated and ignored (emits FutureWarning); the API no longer accepts it
include_domains list[str] None Restrict to these domains
exclude_domains list[str] None Exclude these domains
include_text list[str] None Text that must appear in results
exclude_text list[str] None Text to exclude from results
time_basis str None auto, published, or crawled
start_time str None Start time (ISO 8601)
end_time str None End time (ISO 8601)
format str None text or markdown
safesearch str None off or strict
highlight_enabled bool None Return highlighted snippets
highlight_max_tokens int None Max tokens for highlights
full_content_enabled bool None Return full page content
full_content_max_tokens int None Max tokens for full content
timeout float None Request timeout in seconds

Development

# Install dependencies
poetry install --with test,dev

# Run unit tests (no API key needed)
make test

# Run live tests against the API (billed; requires OCTEN_API_KEY, sets OCTEN_LIVE=1)
export OCTEN_API_KEY="your-api-key"
make integration_tests

# Run all tests with coverage
poetry run pytest tests/ --cov=langchain_octen --cov-report=term-missing

# Lint and format
make lint
make format

License

MIT

Metadata

Release files for langchain-octen 0.2.0

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-octen 0.2.0
File Size Uploaded Provenance Actions
langchain_octen-0.2.0.tar.gz 20.4 kB Without provenance Details for langchain_octen-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-octen 0.2.0
File Interpreter ABI Platform Actions
langchain_octen-0.2.0-py3-none-any.whl Python 3 none any Details for langchain_octen-0.2.0-py3-none-any.whl

Total release size: 40.5 kB

Release files / langchain_octen-0.2.0.tar.gz

Download URL langchain_octen-0.2.0.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b24fc2c1fafc0130866d17a8ec9ec1306ea91d2e204fe9f0b0337ca11685d3a4
BLAKE2b-256 checksum
How to use checksums
dce55cb0ad67ac0871540cabe062cd39676a99362d34d8262c3842d8cbea0efa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / langchain_octen-0.2.0-py3-none-any.whl

Download URL langchain_octen-0.2.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc08b8c56edafe37cba836be651399ff256506724e0ad0541646bc1586177996
BLAKE2b-256 checksum
How to use checksums
6ab42ed3f484bb19296820971c3d4a10f93e73595ef8c4db5b0dcaf8d08bc64d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for langchain-octen 0.2.0

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.

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