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
173 changes: 173 additions & 0 deletions src/oss/javascript/integrations/tools/iflow_search.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
title: "iFlow Search integration"
description: "Integrate with the iFlow Search tools using LangChain JavaScript."
---

[iFlow Search](https://platform.iflow.cn) is a search API that provides web search, image search, and URL fetch primitives. `@iflow-ai/search-langchain` is a community-maintained, third-party npm package that wraps those primitives as three LangChain JavaScript tools. It is **not part of LangChain core** and is currently in a pre-1.0 / prerelease state.

## Overview

### Integration details

| Class | Package | PY support | Version |
| :--- | :--- | :---: | :---: |
| `createIFlowWebSearchTool` / `createIFlowImageSearchTool` / `createIFlowWebFetchTool` / `createIFlowSearchTools` | [`@iflow-ai/search-langchain`](https://www.npmjs.com/package/@iflow-ai/search-langchain) (community, third-party) | ❌ | ![NPM - Version](https://img.shields.io/npm/v/@iflow-ai/search-langchain?style=flat-square&label=%20&) |

> The package is maintained outside LangChain core. See the source repository at [`zhengyanglsun/iflow-search-js`](https://github.com/zhengyanglsun/iflow-search-js) and the tracking issue [`langchain-ai/langchainjs#10931`](https://github.com/langchain-ai/langchainjs/issues/10931). Until a stable `0.1.0` ships, prefer the `@next` dist-tag.

### Tool features

| [Returns artifact](/oss/langchain/tools) | Native async | Return data | Pricing |
| :---: | :---: | :--- | :--- |
| ✅ (via `responseFormat: "content_and_artifact"`) | ✅ | Web results (titles, URLs, snippets); image results (image URLs, titles, source pages); URL fetch (title, URL, normalized content) | See [iFlow platform](https://platform.iflow.cn) |

## Setup

The integration lives in the `@iflow-ai/search-langchain` package, which depends on `@iflow-ai/search-core` and `@langchain/core`. Install all three explicitly:

<CodeGroup>
```bash npm
npm install @iflow-ai/search-langchain @iflow-ai/search-core @langchain/core
```
```bash yarn
yarn add @iflow-ai/search-langchain @iflow-ai/search-core @langchain/core
```
```bash pnpm
pnpm add @iflow-ai/search-langchain @iflow-ai/search-core @langchain/core
```
</CodeGroup>

To install the prerelease (`@next`) while the package is pre-1.0:

<CodeGroup>
```bash npm
npm install @iflow-ai/search-langchain@next @iflow-ai/search-core@next @langchain/core
```
```bash yarn
yarn add @iflow-ai/search-langchain@next @iflow-ai/search-core@next @langchain/core
```
```bash pnpm
pnpm add @iflow-ai/search-langchain@next @iflow-ai/search-core@next @langchain/core
```
</CodeGroup>

Peer dependencies declared by the package:

- `@langchain/core`: `^0.3.0 || ^1.0.0`
- `zod`: `^3.25.0 || ^4.0.0`

### Credentials

Set up an [iFlow API key](https://platform.iflow.cn) and pass it to the tool factories via an environment variable. Use a placeholder in source files; inject the real value at runtime through your shell, secret store, or `direnv` block.

```typescript
process.env.IFLOW_API_KEY = "YOUR_IFLOW_API_KEY";
```

Do not hard-code the key in source files that get committed.

#### Security boundary

`IFLOW_API_KEY` is read by the iFlow package only when you construct a tool, attached as the upstream `Authorization: Bearer …` header by the internal `@iflow-ai/search-core` client, and sent only to the iFlow Search API (`https://platform.iflow.cn`). The key is never written to disk, logged, or surfaced to the LangChain agent or any downstream tool consumer.

It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/) for observability:

```typescript
process.env.LANGSMITH_TRACING = "true";
process.env.LANGSMITH_API_KEY = "your-api-key";
```

## Instantiation

The package exports three individual tool factories and one convenience factory that builds all three at once. All four accept the same options object (`IFlowLangChainOptions`).

```typescript
import {
createIFlowWebSearchTool,
createIFlowImageSearchTool,
createIFlowWebFetchTool,
createIFlowSearchTools,
type IFlowLangChainOptions,
} from "@iflow-ai/search-langchain";

const options: IFlowLangChainOptions = {
apiKey: process.env.IFLOW_API_KEY!,
// baseUrl?: string; // override for testing / private deployments
// timeoutMs?: number; // per-request timeout
};

// Build one tool at a time:
const webSearch = createIFlowWebSearchTool(options);
const imageSearch = createIFlowImageSearchTool(options);
const webFetch = createIFlowWebFetchTool(options);

// Or build all three at once:
const tools = createIFlowSearchTools(options);
// tools[0] → iflow_web_search
// tools[1] → iflow_image_search
// tools[2] → iflow_web_fetch
```

Each factory returns a standard LangChain tool created via `tool()` from `@langchain/core/tools`, configured with `responseFormat: "content_and_artifact"`. The LLM sees a compact text summary; your application code sees the full normalized result on the `ToolMessage.artifact` field.

## Invocation

### Direct call

```typescript
const result = await webSearch.invoke({
query: "LangChain JavaScript",
count: 3,
});
console.log(result);
```

The web-search and image-search tools accept `{ query: string; count?: number }`. The web-fetch tool accepts `{ url: string }` and returns the normalized readable contents of a single page.

### Use with `createReactAgent`

```typescript
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import {
createIFlowSearchTools,
type IFlowLangChainOptions,
} from "@iflow-ai/search-langchain";

const options: IFlowLangChainOptions = {
apiKey: process.env.IFLOW_API_KEY!,
};

const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
const tools = createIFlowSearchTools(options); // all three tools

const agent = createReactAgent({ llm, tools });

const response = await agent.invoke({
messages: [
{
role: "user",
content:
"Find a recent article about LangGraph multi-agent patterns, then fetch the page and summarize the key ideas.",
},
],
});
```

## Tool names

The three tools are registered with stable names so prompts can reference them directly:

- `iflow_web_search` — web search; returns titles, URLs, and snippets.
- `iflow_image_search` — image search; returns image URLs, titles, and source pages.
- `iflow_web_fetch` — fetch the readable contents of a single URL.

Renaming any of these would be a breaking change for the package.

## Related

- [`@iflow-ai/search-langchain` on npm](https://www.npmjs.com/package/@iflow-ai/search-langchain)
- Source repository: [`zhengyanglsun/iflow-search-js`](https://github.com/zhengyanglsun/iflow-search-js)
- Tracking issue in LangChain JS: [`langchain-ai/langchainjs#10931`](https://github.com/langchain-ai/langchainjs/issues/10931)
- Tool [conceptual guide](/oss/langchain/tools)
- Tool [how-to guides](/oss/langchain/tools)
7 changes: 7 additions & 0 deletions src/oss/javascript/integrations/tools/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ The following platforms provide access to multiple tools and services through a
arrow="true"
cta="View guide"
/>
<Card
title="iFlow Search"
icon="link"
href="/oss/integrations/tools/iflow_search"
arrow="true"
cta="View guide"
/>
<Card
title="JigsawStack Tool"
icon="link"
Expand Down
Loading