Skip to content

feat: add PerplexitySearch tool node#6314

Open
jliounis wants to merge 1 commit intoFlowiseAI:mainfrom
jliounis:feat/perplexity-search-tool-node
Open

feat: add PerplexitySearch tool node#6314
jliounis wants to merge 1 commit intoFlowiseAI:mainfrom
jliounis:feat/perplexity-search-tool-node

Conversation

@jliounis
Copy link
Copy Markdown

Summary

Adds a new Perplexity Search tool node under packages/components/nodes/tools/PerplexitySearch/, mirroring the existing ExaSearch and TavilyAPI tool nodes.

The node wraps Perplexity's Search API (POST https://api.perplexity.ai/search) and exposes a query input plus optional configuration:

  • Max Results — number of results to return (default 5)
  • Search Domain Filter — comma-separated allow/deny list, supports -domain.com for negation
  • Search Recency Filterhour / day / week / month / year
  • Tool Description — overridable description fed to the LLM

Results are formatted as numbered text (title, URL, optional date, snippet), matching the agent-friendly output style of ExaSearch.

The node reuses the existing perplexityApi credential type already used by the ChatPerplexity chat model — no new credential file is required. Auth is sent as Authorization: Bearer <key>.

Refs #1860.

What was added

  • packages/components/nodes/tools/PerplexitySearch/PerplexitySearch.ts — node definition (label, inputs, credential, init).
  • packages/components/nodes/tools/PerplexitySearch/core.tsPerplexitySearchTool extending the project's DynamicStructuredTool, performing the fetch call.
  • packages/components/nodes/tools/PerplexitySearch/perplexity.svg — Perplexity brand mark (copied from the existing ChatPerplexity chat model node so the tool catalog stays visually consistent; design team can swap it later if desired).

How to use

  1. Add a Perplexity API credential under Credentials with your Perplexity API key.
  2. Drop the Perplexity Search tool onto a canvas, select the credential, and (optionally) tune Max Results, domain filter, or recency filter.
  3. Wire the tool into any agent / tool-using node.

Test plan

  • pnpm install && pnpm build from the repo root completes without errors.
  • The new node appears in the Tools category in the UI with the Perplexity icon.
  • With a valid perplexityApi credential, calling the tool from an agent returns ranked results from https://api.perplexity.ai/search.
  • Setting Search Domain Filter to e.g. nytimes.com,-pinterest.com and Search Recency Filter=week is reflected in the request body (search_domain_filter, search_recency_filter).
  • An invalid / missing API key surfaces a clear error.

Note: I was unable to run pnpm build in my sandbox due to a disk-space limit, so the change was validated by mirroring the structure of the existing ExaSearch, TavilyAPI, and Arxiv tool nodes that already compile in this repo. Please re-run the standard CI build to confirm.

Adds a new PerplexitySearch tool node to the Tools category, mirroring
the existing ExaSearch and TavilyAPI tool nodes. The node wraps
Perplexity's Search API (POST https://api.perplexity.ai/search) and
exposes query, max results, search domain filter, and search recency
filter inputs to the LLM.

Reuses the existing perplexityApi credential type already used by the
ChatPerplexity chat model.

Refs FlowiseAI#1860
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Perplexity Search tool, consisting of a UI node component, core logic for API interaction, and an associated icon. The reviewer suggested several improvements to align with project standards and security practices, specifically recommending the use of secureFetch to mitigate SSRF risks and refactoring the PerplexitySearchTool class to extend StructuredTool instead of DynamicStructuredTool to avoid unnecessary complexity.

Comment on lines +2 to +3
import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use secureFetch from the project's utilities instead of node-fetch directly. This ensures that the outgoing request adheres to the project's security policies, such as SSRF protection. Additionally, the tool should extend StructuredTool from @langchain/core/tools rather than DynamicStructuredTool from the OpenAPIToolkit. DynamicStructuredTool is a specialized class for the OpenAPI toolkit that includes complex logic for sandboxing and custom code execution which is not required for this implementation.

Suggested change
import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
import { secureFetch } from '../../../src/utils'
import { StructuredTool } from '@langchain/core/tools'

Comment on lines +29 to +51
export class PerplexitySearchTool extends DynamicStructuredTool {
apiKey: string
maxResults: number
searchDomainFilter?: string[]
searchRecencyFilter?: 'hour' | 'day' | 'week' | 'month' | 'year'

constructor(args: PerplexitySearchParameters) {
const schema = createPerplexitySearchSchema()

const toolInput = {
name: args.name || 'perplexity_search',
description: args.description || desc,
schema: schema,
baseUrl: '',
method: 'POST',
headers: {}
}
super(toolInput)
this.apiKey = args.apiKey
this.maxResults = args.maxResults ?? 5
this.searchDomainFilter = args.searchDomainFilter
this.searchRecencyFilter = args.searchRecencyFilter
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Refactor PerplexitySearchTool to extend StructuredTool and simplify the constructor. This avoids inheriting unused properties and methods from DynamicStructuredTool and aligns with standard tool implementations in the repository. The schema should be defined as a class property.

export class PerplexitySearchTool extends StructuredTool {
    apiKey: string
    maxResults: number
    searchDomainFilter?: string[]
    searchRecencyFilter?: 'hour' | 'day' | 'week' | 'month' | 'year'
    schema = createPerplexitySearchSchema()

    constructor(args: PerplexitySearchParameters) {
        super({
            name: args.name || 'perplexity_search',
            description: args.description || desc
        })
        this.apiKey = args.apiKey
        this.maxResults = args.maxResults ?? 5
        this.searchDomainFilter = args.searchDomainFilter
        this.searchRecencyFilter = args.searchRecencyFilter
    }

throw new Error('Perplexity API Key is required')
}

const response = await fetch('https://api.perplexity.ai/search', {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

Use secureFetch to perform the API request to ensure it is subject to the project's security controls.

Suggested change
const response = await fetch('https://api.perplexity.ai/search', {
const response = await secureFetch('https://api.perplexity.ai/search', {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants