Perplexity Extension I want to add an extension to allow me to run web serches using…
- User
Perplexity Extension
I want to add an extension to allow me to run web serches using perplexity API. I want to be able to do my research and then outside of the context window of my main pi thread, them build a recap I can add to my main pi thread context.
How would you go about building that? What information do you need?
Assistant
I'll start by reading the pi extension docs and examples to understand how extensions work.
Assistant
Let me look at the most relevant examples for this use case — research outside context then bring back a recap.
Assistant
- User
- I'm on perplexifty pro plan so I want to leverage the pro models
- PERPLEXITY_API_KEY - I added it to my environment
- I want both
For the research, I think there is also an aspect about having a UI that allows me to do the research (back and forth with perplexity API). For example, I can leverage perplexity research model but the key thing for me is to be able to shape the recap I want injected in my context
Assistant
Good — the interactive shaping part is the interesting twist. That's a custom TUI component via
ctx.ui.custom(). Let me read the custom UI docs and a couple of interactive examples so I design the panel correctly.Assistant
Now let me look at the TUI docs and a couple of interactive custom-component examples to design the research panel correctly.
Assistant
- User
- Yes, use the current pi model
- Default to sonar-pro and make deep research a togglable
- Sounds good
- (a) sounds good
Assistant
Let me verify the Perplexity API shape and check the TUI components I'll need (Input, scrollable container, Markdown streaming).
Assistant
I have everything I need. Let me build the extension.
Assistant
Now the research panel TUI component:
Assistant
Themeis exported from@earendil-works/pi-coding-agent. Let me clean up the panel — fix thedone/focus handling and remove the CURSOR_MARKER hack.Assistant
Now the main
index.tsthat registers the tool and the/researchcommand:Assistant
Let me fix the prefill hack and the
StringEnumargument, and add aprefillmethod to the panel.Assistant
Now let me typecheck the extension against the installed pi packages using the pi TypeScript setup.
Assistant
Let me verify the extension loads cleanly by running pi's model list (which loads extensions without starting a session):
Assistant
Two fixes: truncate the divider line to width, and handle Ctrl+C (since the focused component owns it).
Assistant
Now let me re-verify the extension still loads cleanly and write the README.
Assistant
Loads cleanly. Now let me verify the command and tool are actually registered by checking pi's command list via a quick RPC/json probe.
Assistant
Let me clean up an unused import in index.ts and write the README.
Assistant
Final load check after the import cleanup:
Assistant
Built and loading cleanly. Here's the summary.
- User
Oh add the extension in /Users/sofianebebert/workspace/sof-pi/extensions instead of ~/.pi/agent/extensions/
Assistant
The project's
pi.extensionsconfig only globs./extensions/*.ts(single files, non-recursive), so a subdirectory won't be picked up automatically. I'll move the files and add the directory to the config.Assistant
Now add the directory to the
pi.extensionsconfig so it's discovered:Assistant
Moved. The extension now lives at
/Users/sofianebebert/workspace/sof-pi/extensions/perplexity/(project-local, version-controlled with your sof-pi package), and I added./extensions/perplexity/index.tsto thepi.extensionsarray inpackage.jsonsince the existing./extensions/*.tsglob doesn't recurse into subdirectories. Loads cleanly (pi --list-modelsexit 0, no errors).Note: as a project-local extension it loads only for trusted projects (pi's trust model), which is the right default for repo-controlled code. Run
/researchto try it.- User
I tried the research tool but it failed with
perplexity_search [sonar-pro] Whoop API authentication OAuth client ID client secret endpo… undefined is not an object (evaluating 'sources.length')See [Context] file:///Users/sofianebebert/workspace/sof-pi/pi-session-2026-07-01T15-28-54-130Z_019f1e4c-2372-7fe5-a981-aac49640d4be.html
Assistant
The bug:
searchPerplexity()returns{ content, citations }, but the tool readsresult.sources(which isundefined), thenformatSources(undefined)crashes onundefined.length. Let me confirm and fix.Assistant
Confirmed — two references to
result.sourcesshould beresult.citations.Assistant
Let me also double check the research panel uses the right field (
result.citations), since the same client is used there:Assistant
Panel already uses
result.citationscorrectly. Verify it still loads:Assistant
Fixed. The
perplexity_searchtool was readingresult.sourcesbut the API client returns the field asresult.citations(matching thePerplexityResultinterface). Changed both references inindex.ts:formatSources(result.citations)— builds the appended sources listdetails: { sources: result.citations, model }— stores for rendering
The research panel already used
result.citationscorrectly, so only the simple tool was affected. Reload with/reloadand retry — the LLM's nextperplexity_searchcall should return the answer + numbered sources instead of crashing.- User
Ok try the perplexity_search tool to check it workes
Assistant
I'll call the
perplexity_searchtool directly to verify the fix works end-to-end.Assistant
The tool executed without the
sources.lengthcrash — the fix works. But it can't find the API key in this process's environment. Let me check:- User
Reload the environment
- User
Using pi-acp, how can I interact with pi extensions?