Integrations
LangChain
Web search as a LangChain tool, and Lineage as a document compressor that keeps only the passages that answer the question.
1 min read ยท Updated 14 Sept 2026
On this page
Retrieval chains stuff whole documents into the prompt. That is slow and costly, and a chunk cut from its page loses who and when it was about. Flux gives your agent live search and trims what it retrieves to the passages that matter, with the names and dates written back in.
Search toolGive your agent live web results it can quote and cite.Lineage compressorCut retrieved documents down to the passages that answer the question.
Build it
Install
Shellpip install langchain langchain-openai requestsexport FLUX_API_KEY="<your key>"Give your agent web search
Your model plans and answers. Flux is the tool it calls for anything current.
Pythonimport osimport requestsFLUX = "https://fluxsearch.io/api/v1"HEADERS = {"Authorization": f"Bearer {os.environ['FLUX_API_KEY']}"}from langchain.agents import create_agentfrom langchain_core.tools import tool@tooldef web_search(query: str) -> str: """Search the live web. Returns passages with provenance and their source URLs.""" response = requests.post( f"{FLUX}/search", headers=HEADERS, json={"query": query, "max_results": 5, "enrich": 3}, timeout=120, ) response.raise_for_status() passages = [ f"{passage['enriched_text']} ({result['url']})" for result in response.json()["results"] for passage in (result["lineage"] or {}).get("results", []) ] return "\n\n".join(passages) or "No passages found."agent = create_agent("openai:gpt-5-mini", tools=[web_search])result = agent.invoke({"messages": [{"role": "user", "content": "Who runs Barclays?"}]})print(result["messages"][-1].content)Trim retrieved documents
Wrap Lineage as a
BaseDocumentCompressor. Each document comes back as the passages that answer the query.Pythonimport osimport requestsFLUX = "https://fluxsearch.io/api/v1"HEADERS = {"Authorization": f"Bearer {os.environ['FLUX_API_KEY']}"}from langchain_core.documents import Documentfrom langchain_core.documents.compressor import BaseDocumentCompressorclass FluxLineage(BaseDocumentCompressor): def compress_documents(self, documents, query, callbacks=None): kept = [] for doc in documents: response = requests.post( f"{FLUX}/provenance", headers=HEADERS, json={"text": doc.page_content, "query": query}, timeout=120, ) response.raise_for_status() for passage in response.json()["results"]: metadata = {**doc.metadata, "score": passage["score"]} kept.append(Document(page_content=passage["enriched_text"], metadata=metadata)) return keptdocs = FluxLineage().compress_documents(retrieved_docs, "who is the chief executive")
Call Flux as a chat model
For a direct answer with no agent, ChatOpenAI works against Flux with a new base URL.
Python
import osfrom langchain_openai import ChatOpenAIflux = ChatOpenAI( model="flux-search-1", base_url="https://fluxsearch.io/api/v1", api_key=os.environ["FLUX_API_KEY"],)print(flux.invoke("Who is the chief executive of Barclays?").content)Next steps
LlamaIndexWeb search as a LlamaIndex tool, and Lineage as a node postprocessor that trims retrieved nodes to the passages that answer the query.OpenAI SDKLive web answers with citations and provenance from the OpenAI SDK you already use. Change the base URL and keep your code.API referenceBrowse every endpoint and see exactly what each one returns.