Skip to content

Commit 4638b26

Browse files
Bill Leoutsakoscursoragent
authored andcommitted
feat(pi): optional multi-provider web search for the coding agent
Adds a search provider dropdown (Exa, Serper, Parallel, Firecrawl) to the Pi block, off by default. The selected provider's key comes from the block field or Workspace Settings → BYOK; a Sim-hosted key is never spent, so a missing key fails the run with a setup message instead of quietly billing Sim. Search is available in all three modes. Local Dev and Review Code register a host-side tool that goes through the existing provider tools, while Create PR has no host in the loop and gets a generated Pi extension in the sandbox. Both paths derive their requests from one normalizer and are held together by a parity test, since the sandbox copy cannot import Sim's code. Results are normalized to title, URL, snippet, and publication date, capped per field and per envelope, marked untrusted in the prompt, and limited to 20 searches per run so a tool loop cannot drain the workspace's quota. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f43b52c commit 4638b26

28 files changed

Lines changed: 2866 additions & 80 deletions

apps/docs/content/docs/en/workflows/blocks/pi.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Review Code uses a disposable sandbox for the repository, but the Pi harness and
3737
- Requires sandbox execution. The provider key stays in Sim, so hosted keys and BYOK are both supported.
3838
- Needs a **GitHub token** that can clone the repo and submit reviews (see [Setup](#setup-cloud-code-review)).
3939
- Needs the **Pull Request Number** to review.
40-
- Does not load skills or memory, and never exposes shell, write, edit, or arbitrary network tools to the reviewer.
40+
- Does not load skills or memory, and never exposes shell, write, or edit tools to the reviewer. Its only network access is [Internet Search](#internet-search), and only when you select a provider.
4141
- Rechecks the PR immediately before submission and pins the review to the exact checked-out head commit.
4242
- The deliverable is a **submitted review** — read `reviewUrl` and `commentsPosted`.
4343

@@ -63,6 +63,16 @@ The model that drives the agent. Defaults to `claude-sonnet-4-6`. The dropdown c
6363

6464
Your key for the chosen provider. On hosted Sim it is optional for Local Dev and Review Code runs (a hosted key is used and metered to your workspace). **Create PR requires your own key** because its model client runs in the sandbox. When the provider supports workspace BYOK, you can store the key in **Settings → BYOK** instead of entering it on the block.
6565

66+
### Internet Search
67+
68+
Off by default. Pick a provider — **Exa**, **Serper**, **Parallel AI**, or **Firecrawl** — and the agent gains a single `web_search` tool that returns a handful of results, each with a title, URL, snippet, and (where the provider reports one) a publication date. It works the same way in all three modes, and it is the agent's only network access in Review Code. The tool accepts at most 20 calls per run, which bounds accidental tool loops and the quota one run can consume.
69+
70+
Search always uses **your own key** for the selected provider, never a Sim-hosted one, because Create PR places the key inside the coding sandbox. Enter it in **Search API Key** or store it in **Settings → BYOK**; the run fails with a setup error before any sandbox is created when neither is present. Switching providers clears the key field in the editor, so re-enter the key that belongs to the provider you picked.
71+
72+
Results are third-party data. The agent is instructed to treat them as quoted evidence and never to follow instructions found inside them — the same posture Pi takes toward repository contents.
73+
74+
Traffic goes both ways: the agent writes its own queries after reading the repository, so leave search on **None** in Review Code when the pull request comes from an untrusted fork of a private repo. Injected instructions in a diff could otherwise put repository text into a query sent to the provider.
75+
6676
### Repository (Create PR / Review Code)
6777

6878
- **Repository Owner / Repository Name** — the GitHub repo (for example `your-org` / `your-repo`).
@@ -176,6 +186,7 @@ Enable sandbox execution as for Create PR. BYOK is optional because the model cr
176186
{ question: "Why does Local Dev need a public hostname?", answer: "Sim connects over raw SSH and blocks localhost, LAN, and private/reserved addresses for safety. Expose the machine with a TCP tunnel such as `ngrok tcp 22` and use the tunnel's host and port. Tailscale's private 100.x addresses won't work for the same reason." },
177187
{ question: "What GitHub permissions does Create PR need?", answer: "A token that can clone, push, and open a PR. With a fine-grained token: select the repo and grant Contents: Read and write plus Pull requests: Read and write. With a classic token: the repo scope. For organization repos, the token must be SSO-authorized." },
178188
{ question: "What GitHub permissions does Review Code need?", answer: "A token that can clone the repo and submit a review. With a fine-grained token: Contents: Read plus Pull requests: Read and write. Push permission is not required. With a classic token: the repo scope. For organization repos, the token must be SSO-authorized." },
189+
{ question: "Can the agent search the web?", answer: "Only if you pick a provider under Internet Search — Exa, Serper, Parallel AI, or Firecrawl. That adds one web_search tool in every mode, backed by your own key for that provider (on the block or in Settings → BYOK); Sim never supplies a search key. Leave it on None and the agent has no search tool at all." },
179190
{ question: "Can I give it Gmail, Slack, or other integrations?", answer: "Yes, in Local Dev via the Tools field. Selected Sim tools run through Sim with your connected credentials, the same as the Agent block, so the agent can act beyond the repo while it codes. MCP and custom tools aren't supported yet." },
180191
{ question: "Where do the changes or feedback go?", answer: "In Create PR, to a new branch and a pull request (read prUrl and branch). In Review Code, to a submitted GitHub review on the existing PR (read reviewUrl and commentsPosted). In Local Dev, the files are edited in place on the target machine — review them with git there. Create PR and Local Dev also return changedFiles and a diff." },
181192
{ question: "What happens when memory or context gets large?", answer: "For Create PR and Local Dev, Sim trims memory before the run based on the memory type, and Pi compacts older turns as needed. Review Code does not load or save memory because a malicious PR could otherwise expose or poison prior context." },

apps/sim/blocks/blocks/pi.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it, vi } from 'vitest'
5+
6+
// The registry lives server-side (`keys.ts` reaches BYOK, which reaches the database) and the block
7+
// deliberately does not import it — no block imports from `@/executor`. This test is what ties the
8+
// two copies together, so adding a provider to one and not the other fails here.
9+
vi.mock('@/lib/api-key/byok', () => ({ getBYOKKey: vi.fn(), getApiKeyWithBYOK: vi.fn() }))
10+
11+
import { evaluateSubBlockCondition } from '@/lib/workflows/subblocks/visibility'
12+
import { PiBlock } from '@/blocks/blocks/pi'
13+
import { PI_SEARCH_PROVIDERS } from '@/executor/handlers/pi/keys'
14+
15+
const searchProviderField = PiBlock.subBlocks.find((subBlock) => subBlock.id === 'searchProvider')
16+
const searchApiKeyField = PiBlock.subBlocks.find((subBlock) => subBlock.id === 'searchApiKey')
17+
18+
function searchKeyVisible(values: Record<string, unknown>): boolean {
19+
return evaluateSubBlockCondition(searchApiKeyField?.condition, values)
20+
}
21+
22+
describe('Pi block search fields', () => {
23+
it('offers None plus exactly the providers the resolver knows, defaulting to None', () => {
24+
expect(searchProviderField?.type).toBe('dropdown')
25+
expect(searchProviderField?.defaultValue).toBe('none')
26+
27+
const options = searchProviderField?.options as { id: string; label: string }[]
28+
expect(options.map(({ id }) => id)).toEqual(['none', ...Object.keys(PI_SEARCH_PROVIDERS)])
29+
// Labels too: a mismatch here means the dropdown names a provider differently from the setup
30+
// error the run fails with.
31+
expect(options.slice(1).map(({ label }) => label)).toEqual(
32+
Object.values(PI_SEARCH_PROVIDERS).map(({ label }) => label)
33+
)
34+
})
35+
36+
// The same handling this block already gives githubToken, password, and privateKey.
37+
it('keeps the search key out of connections, references, and plain text', () => {
38+
expect(searchApiKeyField?.password).toBe(true)
39+
expect(searchApiKeyField?.paramVisibility).toBe('user-only')
40+
expect(searchApiKeyField?.connectionDroppable).toBe(false)
41+
})
42+
43+
it('declares the key as dependent on the provider, which is what clears it in the editor', () => {
44+
expect(searchApiKeyField?.dependsOn).toEqual(['searchProvider'])
45+
})
46+
47+
it('shows the key field only once a provider is selected', () => {
48+
expect(searchKeyVisible({ searchProvider: 'exa' })).toBe(true)
49+
expect(searchKeyVisible({ searchProvider: 'firecrawl' })).toBe(true)
50+
expect(searchKeyVisible({ searchProvider: 'none' })).toBe(false)
51+
expect(searchKeyVisible({ searchProvider: '' })).toBe(false)
52+
})
53+
54+
// A Pi block saved before this field existed has no stored value, and the serializer does not
55+
// inject subBlock defaults — so `undefined` has to behave like None here too.
56+
it('hides the key field on blocks saved before the field existed', () => {
57+
expect(searchKeyVisible({})).toBe(false)
58+
expect(searchKeyVisible({ searchProvider: undefined })).toBe(false)
59+
})
60+
61+
// `inputs` is the block's type map, not the delivery mechanism — the handler reads resolved
62+
// params — but an undeclared input is a convention break the next block author would copy.
63+
it('declares both fields in the block input map', () => {
64+
expect(PiBlock.inputs.searchProvider).toBeDefined()
65+
expect(PiBlock.inputs.searchApiKey).toBeDefined()
66+
})
67+
})

apps/sim/blocks/blocks/pi.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,45 @@ const AUTHORING_MODES: { field: 'mode'; value: Array<'cloud' | 'local'> } = {
5353
}
5454
const MEMORY_TYPES = ['conversation', 'sliding_window', 'sliding_window_tokens']
5555

56+
const SEARCH_PROVIDER_OPTIONS = [
57+
{ label: 'None', id: 'none' },
58+
{ label: 'Exa', id: 'exa' },
59+
{ label: 'Serper', id: 'serper' },
60+
{ label: 'Parallel AI', id: 'parallel' },
61+
{ label: 'Firecrawl', id: 'firecrawl' },
62+
]
63+
64+
/**
65+
* Mirrors `getApiKeyCondition()` for the model key: the search key's visibility is computed rather
66+
* than declarative. The never-matching sentinel is how `buildModelVisibilityCondition` hides the
67+
* model key when nothing is selected, and it is what keeps the field hidden on a block saved before
68+
* this field existed — such a block has no stored `searchProvider`, and the declarative negative
69+
* form would show the field, because a scalar `not` condition evaluates `undefined !== 'none'` as
70+
* true.
71+
*/
72+
function getSearchApiKeyCondition() {
73+
return (values?: Record<string, unknown>) => {
74+
const provider = typeof values?.searchProvider === 'string' ? values.searchProvider : ''
75+
if (!provider || provider === 'none') {
76+
return { field: 'searchProvider', value: '__no_search_provider__' }
77+
}
78+
return { field: 'searchProvider', value: provider }
79+
}
80+
}
81+
5682
export const PiBlock: BlockConfig<PiResponse> = {
5783
type: 'pi',
5884
name: 'Pi Coding Agent',
5985
description: 'Run an autonomous coding agent on a repo',
6086
authMode: AuthMode.ApiKey,
6187
longDescription:
62-
'The Pi Coding Agent runs the Pi harness against a real repository. Create PR spins up an isolated sandbox, clones a GitHub repo, edits with native shell + git, and opens a pull request. Review Code checks out a pinned PR snapshot with read-only tools and posts a structured review with optional inline comments. Local Dev edits files on your own machine over SSH. Create PR and Local Dev can reuse skills and multi-turn memory; Review Code runs without either because PR contents are untrusted.',
88+
'The Pi Coding Agent runs the Pi harness against a real repository. Create PR spins up an isolated sandbox, clones a GitHub repo, edits with native shell + git, and opens a pull request. Review Code checks out a pinned PR snapshot with read-only tools and posts a structured review with optional inline comments. Local Dev edits files on your own machine over SSH. Create PR and Local Dev can reuse skills and multi-turn memory; Review Code runs without either because PR contents are untrusted. Any mode can optionally get one web_search tool backed by your own Exa, Serper, Parallel AI, or Firecrawl key; the agent writes its own queries, so repository content may reach the provider, and results are untrusted third-party data.',
6389
bestPractices: `
6490
- Use Create PR for hands-off changes against a GitHub repo where a reviewable PR is the deliverable.
6591
- Use Review Code to analyze an existing PR and leave summary + inline review comments.
6692
- Use Local Dev to edit a repo on your own machine; expose the machine on a public hostname/tunnel so Sim can reach it over SSH.
6793
- Create PR requires your own provider API key because the model runs in the sandbox. Review Code keeps the model key in Sim and can use either BYOK or a hosted key.
94+
- Internet Search is off by default and always needs your own key for the selected provider, from the block field or Settings > BYOK. Leave it on None unless the task genuinely needs external information.
6895
`,
6996
category: 'blocks',
7097
integrationType: IntegrationType.AI,
@@ -122,6 +149,29 @@ export const PiBlock: BlockConfig<PiResponse> = {
122149

123150
...getProviderCredentialSubBlocks(),
124151

152+
{
153+
id: 'searchProvider',
154+
title: 'Internet Search',
155+
type: 'dropdown',
156+
defaultValue: 'none',
157+
options: SEARCH_PROVIDER_OPTIONS,
158+
tooltip:
159+
'Gives the agent a single web_search tool backed by the selected provider. Search always uses your own key for that provider, never a Sim-hosted one, because Create PR places the key inside the coding sandbox.',
160+
},
161+
{
162+
id: 'searchApiKey',
163+
title: 'Search API Key',
164+
type: 'short-input',
165+
password: true,
166+
paramVisibility: 'user-only',
167+
connectionDroppable: false,
168+
placeholder: 'Falls back to the key stored in Settings > BYOK',
169+
tooltip:
170+
'Key for the selected search provider. Switching providers clears this field, so re-enter the key for the provider you picked.',
171+
condition: getSearchApiKeyCondition(),
172+
dependsOn: ['searchProvider'],
173+
},
174+
125175
{
126176
id: 'owner',
127177
title: 'Repository Owner',
@@ -434,6 +484,11 @@ export const PiBlock: BlockConfig<PiResponse> = {
434484
conversationId: { type: 'string', description: 'Conversation ID for memory' },
435485
slidingWindowSize: { type: 'string', description: 'Number of messages for sliding window' },
436486
slidingWindowTokens: { type: 'string', description: 'Max tokens for token-based window' },
487+
searchProvider: {
488+
type: 'string',
489+
description: 'Web search provider for the agent: none, exa, serper, parallel, or firecrawl',
490+
},
491+
searchApiKey: { type: 'string', description: 'API key for the selected search provider' },
437492
...PROVIDER_CREDENTIAL_INPUTS,
438493
},
439494
outputs: {

apps/sim/executor/handlers/pi/backend.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { TSchema } from 'typebox'
1111
import type { SSHConnectionConfig } from '@/app/api/tools/ssh/utils'
1212
import type { Message } from '@/executor/handlers/agent/types'
1313
import type { PiEvent, PiRunTotals } from '@/executor/handlers/pi/events'
14+
import type { PiSearchKeySource, PiSearchProvider } from '@/executor/handlers/pi/keys'
1415
import type { PiSupportedProvider } from '@/providers/pi-provider-configs'
1516

1617
/** A conversation message seeded into the Pi run (subset of the Agent block's message). */
@@ -31,6 +32,7 @@ export type PiSshConnection = Pick<
3132
/** Result of invoking a tool Pi called. */
3233
export interface PiToolResult {
3334
text: string
35+
/** Reported to Pi by throwing `text` from the converted tool; see `toPiTool` for why. */
3436
isError: boolean
3537
}
3638

@@ -43,9 +45,28 @@ export interface PiToolSpec {
4345
name: string
4446
description: string
4547
parameters: TSchema
48+
/**
49+
* Guideline bullets Pi folds into the system prompt while the tool is active. This is the
50+
* trusted channel: a `description` travels in the provider request's tool-definition array, so
51+
* guidance placed there carries the same trust level as the payload it describes. Dropped in
52+
* Review Code, which supplies a sealed `customPrompt` instead.
53+
*/
54+
promptGuidelines?: string[]
4655
execute: (args: Record<string, unknown>) => Promise<PiToolResult>
4756
}
4857

58+
/** Optional web search for a Pi run, resolved by the handler before mode dispatch. */
59+
export interface PiSearchConfig {
60+
provider: PiSearchProvider
61+
apiKey: string
62+
keySource: PiSearchKeySource
63+
/**
64+
* Host-side tool for the two SDK modes. Absent for `cloud`, which has no host in the loop and
65+
* registers a sandbox extension instead, so a spec built there could never execute.
66+
*/
67+
tool?: PiToolSpec
68+
}
69+
4970
interface PiRunBaseParams {
5071
/** Sim's catalog ID, retained for billing and output. */
5172
model: string
@@ -56,6 +77,7 @@ interface PiRunBaseParams {
5677
isBYOK: boolean
5778
task: string
5879
thinkingLevel?: string
80+
search?: PiSearchConfig
5981
}
6082

6183
interface PiContextualRunParams extends PiRunBaseParams {

0 commit comments

Comments
 (0)