Skip to content

feat: add PerplexitySearch tool node#6314

Open
jliounis wants to merge 6 commits into
FlowiseAI:mainfrom
jliounis:feat/perplexity-search-tool-node
Open

feat: add PerplexitySearch tool node#6314
jliounis wants to merge 6 commits into
FlowiseAI:mainfrom
jliounis:feat/perplexity-search-tool-node

Conversation

@jliounis

@jliounis jliounis commented Apr 29, 2026

Copy link
Copy Markdown

Summary

Adds a new Perplexity Search tool node under packages/components/nodes/tools/PerplexitySearch/

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)

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.

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

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

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.

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 thread packages/components/nodes/tools/PerplexitySearch/core.ts Outdated
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
    }

Comment thread packages/components/nodes/tools/PerplexitySearch/core.ts Outdated
jliounis and others added 4 commits May 5, 2026 17:14
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@jliounis

Copy link
Copy Markdown
Author

All three gemini-code-assist review comments have been addressed in commit f9fca91:

  • Comment #3163171719 (use secureFetch + StructuredTool): node-fetch replaced with secureFetch from ../../../src/httpSecurity (consistent with Jira/core.ts, MCP/core.ts); DynamicStructuredTool replaced with StructuredTool from @langchain/core/tools.
  • Comment #3163171742 (refactor to extend StructuredTool with schema as class property): PerplexitySearchTool now extends StructuredTool directly with schema defined as a class property and a clean constructor.
  • Comment #3163171755 (use secureFetch for API call): The _call method now uses secureFetch for the POST to https://api.perplexity.ai/search.

No additional changes were needed — the current HEAD already reflects all requested fixes.

@jliounis

Copy link
Copy Markdown
Author

Re-verified all flagged review comments — already addressed in current HEAD f9fca91. Specifically:

  • Comment #3163171719 (use secureFetch + StructuredTool import): HEAD line 2 imports secureFetch from '../../../src/httpSecurity'; line 3 imports StructuredTool from '@langchain/core/tools'. node-fetch is gone. ✓
  • Comment #3163171742 (refactor PerplexitySearchTool to extend StructuredTool with schema as class property): HEAD PerplexitySearchTool extends StructuredTool directly with schema = createPerplexitySearchSchema() as a class property and a clean constructor. ✓
  • Comment #3163171755 (use secureFetch for the API POST): HEAD _call method uses secureFetch('https://api.perplexity.ai/search', ...) — no direct fetch or node-fetch call. ✓

No new fixes were needed — all three gemini-code-assist suggestions are reflected in the current branch HEAD.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Thank you for the update, jliounis. I have reviewed the changes in the current HEAD (f9fca91) and can confirm that all previous review comments have been successfully addressed:

  • secureFetch & StructuredTool usage: node-fetch has been removed, and the implementation correctly utilizes secureFetch from ../../../src/httpSecurity and StructuredTool from @langchain/core/tools.
  • PerplexitySearchTool refactor: The tool now correctly extends StructuredTool with the schema defined as a class property, and the constructor is clean and well-structured.
  • API call security: The _call method is now using secureFetch for the POST request to the Perplexity API, ensuring consistent security practices across the codebase.

Everything looks good. Thank you for your diligence in verifying these fixes.

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