INTEGRATIONS · LANGCHAIN

LangChain search tool integration

Integrate Annolux bilingual search API into LangChain Python and TypeScript agents: source-attributed citations and fetched_at timestamps.

Python integration

Wrap the standard Annolux REST endpoint with LangChain @tool decorator. Every result arrives with URL, rank, clean snippet, and fetched_at timestamp.

import os
import requests
from langchain_core.tools import tool

@tool
def annolux_search(query: str, limit: int = 10) -> str:
    """Search Annolux curated English and Chinese index with explicit fetched_at timestamps."""
    api_key = os.environ.get("ANNOLUX_API_KEY", "")
    res = requests.post(
        "https://api.annolux.com/api/v1/search",
        headers={"Authorization": f"Bearer {api_key}"},
        json={"query": query, "limit": limit, "deduplicate": True},
        timeout=30,
    )
    if not res.ok:
        return f"Search error: {res.status_code}"
    return res.text

TypeScript integration

For Node.js and TypeScript LangChain workflows, define a tool with @langchain/core and Zod schema validation.

import { tool } from "@langchain/core/tools";
import { z } from "zod";

export const annoluxSearchTool = tool(
  async ({ query, limit = 10 }) => {
    const res = await fetch("https://api.annolux.com/api/v1/search", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${process.env.ANNOLUX_API_KEY}`
      },
      body: JSON.stringify({ query, limit, deduplicate: true })
    });
    return await res.text();
  },
  {
    name: "annolux_search",
    description: "Search Annolux curated English and Chinese index.",
    schema: z.object({
      query: z.string().describe("Search query"),
      limit: z.number().optional().default(10)
    })
  }
);

Using search in agent workflows

Bind the tool to your LangGraph agent or create_react_agent. When the model invokes the tool, it receives structured provenance so downstream citations avoid hallucinated dates.

Boundaries and credits

Search queries a curated bilingual index. Exactly 1 credit per successful 2xx query; errors and timeouts cost zero. New accounts receive 1,000 free permanent credits.