packages
@loop-engine/adapter-perplexity
Overview
@loop-engine/adapter-perplexity wraps the Perplexity Sonar chat API as a Loop Engine ToolAdapter. Sonar adds grounded web retrieval with cited sources. You use it for Loop steps that need real-time, verifiable information — regulatory lookups, compliance research, supplier or market news. It is not a general-purpose generation adapter; for broad LLM actor flows, use Anthropic or OpenAI actor adapters.
Installation
1npm install @loop-engine/adapter-perplexityConfiguration
1import { PerplexityAdapter } from "@loop-engine/adapter-perplexity";2 3const adapter = new PerplexityAdapter({4 apiKey: process.env.PERPLEXITY_API_KEY,5 defaultModel: "sonar-pro", "cmt">// sonar | sonar-pro | sonar-reasoning | sonar-reasoning-pro6 defaultSearchRecency: "month", "cmt">// day | week | month7 timeout: 30_000,8 retries: 3,9});Basic usage
1import { PerplexityAdapter } from "@loop-engine/adapter-perplexity";2import type { AdapterInput } from "@loop-engine/core";3 4const adapter = new PerplexityAdapter({ apiKey: process.env.PERPLEXITY_API_KEY! });5 6const input: AdapterInput = {7 prompt:8 "What are the HIPAA breach notification requirements for PHI accessed outside approved hours?",9 model: "sonar-pro",10 metadata: {11 returnCitations: true,12 searchDomainFilter: ["hhs.gov", "nist.gov"],13 searchRecencyFilter: "month",14 },15};16 17const result = await adapter.invoke(input);18 19console.log(result.text); "cmt">// Sonar answer text20console.log(result.citations); "cmt">// { url, title, snippet }[]Citation handling
Citations are a first-class output on SonarResult. Each entry includes url, title, and snippet (for example derived from search metadata).
1const result = await adapter.invoke({2 prompt: "Summarize recent FDA guidance on AI/ML SaMD change control.",3 metadata: { returnCitations: true, searchRecencyFilter: "month" },4});5 6for (const citation of result.citations) {7 console.log(citation.url);8 console.log(citation.title);9}