@introspection-ai/recipes 0.50.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +3 -3
  2. package/dist/api/api-bindings.d.ts +3 -0
  3. package/dist/api/api-bindings.d.ts.map +1 -0
  4. package/dist/api/api-bindings.js +2 -0
  5. package/dist/api/api-bindings.js.map +1 -0
  6. package/dist/api/session.d.ts +1 -0
  7. package/dist/api/session.d.ts.map +1 -1
  8. package/dist/api-bindings.d.ts +101 -0
  9. package/dist/api-bindings.d.ts.map +1 -0
  10. package/dist/api-bindings.js +406 -0
  11. package/dist/api-bindings.js.map +1 -0
  12. package/dist/channels/arguments.d.ts +116 -0
  13. package/dist/channels/arguments.d.ts.map +1 -0
  14. package/dist/channels/arguments.generated.d.ts +15 -0
  15. package/dist/channels/arguments.generated.d.ts.map +1 -0
  16. package/dist/channels/arguments.generated.js +181 -0
  17. package/dist/channels/arguments.generated.js.map +1 -0
  18. package/dist/channels/arguments.js +8 -0
  19. package/dist/channels/arguments.js.map +1 -0
  20. package/dist/channels/module.d.ts +5 -0
  21. package/dist/channels/module.d.ts.map +1 -1
  22. package/dist/channels/module.js +10 -5
  23. package/dist/channels/module.js.map +1 -1
  24. package/dist/channels/tools.d.ts.map +1 -1
  25. package/dist/channels/tools.js +22 -59
  26. package/dist/channels/tools.js.map +1 -1
  27. package/dist/channels/types.d.ts +5 -0
  28. package/dist/channels/types.d.ts.map +1 -1
  29. package/dist/child/session.d.ts +5 -0
  30. package/dist/child/session.d.ts.map +1 -1
  31. package/dist/child/session.js +2 -0
  32. package/dist/child/session.js.map +1 -1
  33. package/dist/clock.d.ts +80 -0
  34. package/dist/clock.d.ts.map +1 -0
  35. package/dist/clock.js +169 -0
  36. package/dist/clock.js.map +1 -0
  37. package/dist/command-parameters.d.ts +37 -5
  38. package/dist/command-parameters.d.ts.map +1 -1
  39. package/dist/command-parameters.js +73 -11
  40. package/dist/command-parameters.js.map +1 -1
  41. package/dist/connector-tools.d.ts +18 -0
  42. package/dist/connector-tools.d.ts.map +1 -1
  43. package/dist/connector-tools.js +49 -6
  44. package/dist/connector-tools.js.map +1 -1
  45. package/dist/documents/module.d.ts.map +1 -1
  46. package/dist/documents/module.js +1 -3
  47. package/dist/documents/module.js.map +1 -1
  48. package/dist/documents/tools.d.ts.map +1 -1
  49. package/dist/documents/tools.js +3 -3
  50. package/dist/documents/tools.js.map +1 -1
  51. package/dist/egress.d.ts +23 -0
  52. package/dist/egress.d.ts.map +1 -0
  53. package/dist/egress.js +36 -0
  54. package/dist/egress.js.map +1 -0
  55. package/dist/issues/index.d.ts +7 -0
  56. package/dist/issues/index.d.ts.map +1 -0
  57. package/dist/issues/index.js +4 -0
  58. package/dist/issues/index.js.map +1 -0
  59. package/dist/issues/module.d.ts +38 -0
  60. package/dist/issues/module.d.ts.map +1 -0
  61. package/dist/issues/module.js +114 -0
  62. package/dist/issues/module.js.map +1 -0
  63. package/dist/issues/tool.d.ts +95 -0
  64. package/dist/issues/tool.d.ts.map +1 -0
  65. package/dist/issues/tool.js +479 -0
  66. package/dist/issues/tool.js.map +1 -0
  67. package/dist/issues/types.d.ts +280 -0
  68. package/dist/issues/types.d.ts.map +1 -0
  69. package/dist/issues/types.js +79 -0
  70. package/dist/issues/types.js.map +1 -0
  71. package/dist/mcp/cli/command-context.d.ts +20 -1
  72. package/dist/mcp/cli/command-context.d.ts.map +1 -1
  73. package/dist/mcp/cli/command-context.js.map +1 -1
  74. package/dist/mcp/cli/core.d.ts +0 -2
  75. package/dist/mcp/cli/core.d.ts.map +1 -1
  76. package/dist/mcp/cli/core.js +9 -33
  77. package/dist/mcp/cli/core.js.map +1 -1
  78. package/dist/mcp/cli/handshake-retry.d.ts +5 -0
  79. package/dist/mcp/cli/handshake-retry.d.ts.map +1 -0
  80. package/dist/mcp/cli/handshake-retry.js +32 -0
  81. package/dist/mcp/cli/handshake-retry.js.map +1 -0
  82. package/dist/mcp/daemon/index.js +3 -4
  83. package/dist/mcp/daemon/index.js.map +1 -1
  84. package/dist/mcp/pi-client.d.ts +2 -0
  85. package/dist/mcp/pi-client.d.ts.map +1 -1
  86. package/dist/mcp/pi-client.js +5 -1
  87. package/dist/mcp/pi-client.js.map +1 -1
  88. package/dist/mcp/pi-mcp-runtime.d.ts +25 -0
  89. package/dist/mcp/pi-mcp-runtime.d.ts.map +1 -0
  90. package/dist/mcp/pi-mcp-runtime.js +215 -0
  91. package/dist/mcp/pi-mcp-runtime.js.map +1 -0
  92. package/dist/mcp/pi-runtime.d.ts +7 -0
  93. package/dist/mcp/pi-runtime.d.ts.map +1 -0
  94. package/dist/mcp/pi-runtime.js +26 -0
  95. package/dist/mcp/pi-runtime.js.map +1 -0
  96. package/dist/mcp-chunks/chunk-3UVHZECT.js +31 -0
  97. package/dist/mcp-chunks/{chunk-PO2SOBEN.js → chunk-CGJ2XOSF.js} +43 -35
  98. package/dist/mcp-chunks/{chunk-GTETFUPQ.js → chunk-IMG2JMBS.js} +8 -8
  99. package/dist/mcp-chunks/{chunk-UFV6SVQG.js → chunk-LQKMNWDE.js} +2 -2
  100. package/dist/mcp-chunks/{chunk-S2F7DDP5.js → chunk-QUDOU7MQ.js} +1 -1
  101. package/dist/mcp-chunks/{cli-IYD7Y7MO.js → cli-BM23ZXPJ.js} +54 -54
  102. package/dist/mcp-chunks/{client-5MNBV3Z7.js → client-RKTAKDAY.js} +7 -7
  103. package/dist/mcp-chunks/{daemon-command-V3B3EMXD.js → daemon-command-VU6WTFCJ.js} +8 -8
  104. package/dist/mcp-chunks/{generate-cli-runner-PW5WJ7KI.js → generate-cli-runner-JAAPSWGX.js} +12 -12
  105. package/dist/mcp-chunks/{generated-daemon-runtime-3C4NWGAU.js → generated-daemon-runtime-LX4L2X7Z.js} +8 -8
  106. package/dist/mcp-chunks/pi-mcp-runtime-GHDEPXUL.js +1231 -0
  107. package/dist/mcp-chunks/{runtime-RMI3XCYJ.js → runtime-T63YI7TC.js} +6 -6
  108. package/dist/mcp-chunks/{serve-command-UF5SVREV.js → serve-command-75P4VBJ6.js} +7 -7
  109. package/dist/mcp-daemon.js +21 -19
  110. package/dist/mcp-run-worker.js +11 -10
  111. package/dist/pi-extension.d.ts +3 -0
  112. package/dist/pi-extension.d.ts.map +1 -1
  113. package/dist/pi-extension.js +82 -18
  114. package/dist/pi-extension.js.map +1 -1
  115. package/dist/productivity/arguments.d.ts +298 -0
  116. package/dist/productivity/arguments.d.ts.map +1 -0
  117. package/dist/productivity/arguments.generated.d.ts +28 -0
  118. package/dist/productivity/arguments.generated.d.ts.map +1 -0
  119. package/dist/productivity/arguments.generated.js +489 -0
  120. package/dist/productivity/arguments.generated.js.map +1 -0
  121. package/dist/productivity/arguments.js +10 -0
  122. package/dist/productivity/arguments.js.map +1 -0
  123. package/dist/productivity/http.d.ts.map +1 -1
  124. package/dist/productivity/http.js +12 -22
  125. package/dist/productivity/http.js.map +1 -1
  126. package/dist/productivity/index.d.ts +1 -1
  127. package/dist/productivity/index.d.ts.map +1 -1
  128. package/dist/productivity/index.js +1 -1
  129. package/dist/productivity/index.js.map +1 -1
  130. package/dist/productivity/module.d.ts +15 -2
  131. package/dist/productivity/module.d.ts.map +1 -1
  132. package/dist/productivity/module.js +24 -21
  133. package/dist/productivity/module.js.map +1 -1
  134. package/dist/productivity/tools.d.ts +6 -0
  135. package/dist/productivity/tools.d.ts.map +1 -1
  136. package/dist/productivity/tools.js +64 -224
  137. package/dist/productivity/tools.js.map +1 -1
  138. package/dist/productivity/types.d.ts +2 -0
  139. package/dist/productivity/types.d.ts.map +1 -1
  140. package/dist/productivity/types.js.map +1 -1
  141. package/dist/recipe/agent.d.ts +40 -10
  142. package/dist/recipe/agent.d.ts.map +1 -1
  143. package/dist/recipe/agent.js +209 -30
  144. package/dist/recipe/agent.js.map +1 -1
  145. package/dist/recipe/companions.d.ts +2 -1
  146. package/dist/recipe/companions.d.ts.map +1 -1
  147. package/dist/recipe/companions.js +11 -9
  148. package/dist/recipe/companions.js.map +1 -1
  149. package/dist/recipe/manifest.generated.d.ts +4 -1
  150. package/dist/recipe/manifest.generated.d.ts.map +1 -1
  151. package/dist/recipe/manifest.generated.js +5 -2
  152. package/dist/recipe/manifest.generated.js.map +1 -1
  153. package/dist/recipe/package.d.ts +28 -3
  154. package/dist/recipe/package.d.ts.map +1 -1
  155. package/dist/recipe/package.js +155 -1
  156. package/dist/recipe/package.js.map +1 -1
  157. package/dist/recipe/providers.d.ts +62 -0
  158. package/dist/recipe/providers.d.ts.map +1 -0
  159. package/dist/recipe/providers.js +95 -0
  160. package/dist/recipe/providers.js.map +1 -0
  161. package/dist/recipe/resolve.d.ts +7 -3
  162. package/dist/recipe/resolve.d.ts.map +1 -1
  163. package/dist/recipe/resolve.js +7 -2
  164. package/dist/recipe/resolve.js.map +1 -1
  165. package/dist/run-controller.d.ts +6 -0
  166. package/dist/run-controller.d.ts.map +1 -1
  167. package/dist/run-controller.js +2 -0
  168. package/dist/run-controller.js.map +1 -1
  169. package/dist/search/egress.d.ts +12 -0
  170. package/dist/search/egress.d.ts.map +1 -0
  171. package/dist/search/egress.js +24 -0
  172. package/dist/search/egress.js.map +1 -0
  173. package/dist/search/http.d.ts +16 -0
  174. package/dist/search/http.d.ts.map +1 -0
  175. package/dist/search/http.js +75 -0
  176. package/dist/search/http.js.map +1 -0
  177. package/dist/search/index.d.ts +10 -0
  178. package/dist/search/index.d.ts.map +1 -0
  179. package/dist/search/index.js +5 -0
  180. package/dist/search/index.js.map +1 -0
  181. package/dist/search/mcp.d.ts +58 -0
  182. package/dist/search/mcp.d.ts.map +1 -0
  183. package/dist/search/mcp.js +84 -0
  184. package/dist/search/mcp.js.map +1 -0
  185. package/dist/search/module.d.ts +28 -0
  186. package/dist/search/module.d.ts.map +1 -0
  187. package/dist/search/module.js +49 -0
  188. package/dist/search/module.js.map +1 -0
  189. package/dist/search/tool.d.ts +101 -0
  190. package/dist/search/tool.d.ts.map +1 -0
  191. package/dist/search/tool.js +518 -0
  192. package/dist/search/tool.js.map +1 -0
  193. package/dist/search/types.d.ts +257 -0
  194. package/dist/search/types.d.ts.map +1 -0
  195. package/dist/search/types.js +63 -0
  196. package/dist/search/types.js.map +1 -0
  197. package/dist/session.d.ts +21 -1
  198. package/dist/session.d.ts.map +1 -1
  199. package/dist/session.js +132 -43
  200. package/dist/session.js.map +1 -1
  201. package/dist/test-utils.d.ts +2 -0
  202. package/dist/test-utils.d.ts.map +1 -1
  203. package/dist/test-utils.js +3 -1
  204. package/dist/test-utils.js.map +1 -1
  205. package/dist/tool-search.d.ts +9 -0
  206. package/dist/tool-search.d.ts.map +1 -1
  207. package/dist/tool-search.js +23 -0
  208. package/dist/tool-search.js.map +1 -1
  209. package/dist/tools/bridge.d.ts +44 -0
  210. package/dist/tools/bridge.d.ts.map +1 -0
  211. package/dist/tools/bridge.js +106 -0
  212. package/dist/tools/bridge.js.map +1 -0
  213. package/dist/tools/cli.d.ts +20 -0
  214. package/dist/tools/cli.d.ts.map +1 -0
  215. package/dist/tools/cli.js +246 -0
  216. package/dist/tools/cli.js.map +1 -0
  217. package/dist/tools/entry.d.ts +2 -0
  218. package/dist/tools/entry.d.ts.map +1 -0
  219. package/dist/tools/entry.js +3 -0
  220. package/dist/tools/entry.js.map +1 -0
  221. package/dist/tools/shell.d.ts +12 -0
  222. package/dist/tools/shell.d.ts.map +1 -0
  223. package/dist/tools/shell.js +50 -0
  224. package/dist/tools/shell.js.map +1 -0
  225. package/dist/tuning/tpe.d.ts +112 -0
  226. package/dist/tuning/tpe.d.ts.map +1 -0
  227. package/dist/tuning/tpe.js +286 -0
  228. package/dist/tuning/tpe.js.map +1 -0
  229. package/docs/README.md +4 -1
  230. package/docs/channels/README.md +10 -0
  231. package/docs/documents/README.md +20 -19
  232. package/docs/host-api.md +10 -0
  233. package/docs/issues/README.md +183 -0
  234. package/docs/mcp-configuration.md +67 -2
  235. package/docs/pi-extension.md +5 -0
  236. package/docs/productivity/README.md +8 -3
  237. package/docs/providers.md +321 -0
  238. package/docs/recipe-format.md +103 -32
  239. package/docs/search/README.md +818 -0
  240. package/package.json +33 -10
  241. package/skills/documents/SKILL.md +2 -1
  242. package/skills/search/SKILL.md +72 -0
  243. package/dist/mcp-chunks/{auth-command-M7TQE3AL.js → auth-command-UYFOGGQR.js} +6 -6
  244. package/dist/mcp-chunks/{call-command-7LD7UEFK.js → call-command-6U5BNDR7.js} +17 -17
  245. package/dist/mcp-chunks/{chunk-PSE442BC.js → chunk-36D4FILJ.js} +26 -26
  246. package/dist/mcp-chunks/{config-command-6DXILFNO.js → config-command-ZSPJI34E.js} +10 -10
  247. package/dist/mcp-chunks/{emit-ts-command-NDCDFDRM.js → emit-ts-command-SY4LQE4S.js} +3 -3
  248. package/dist/mcp-chunks/{inspect-cli-command-4MGF5CPP.js → inspect-cli-command-JPX4ON6N.js} +4 -4
  249. package/dist/mcp-chunks/{resource-command-SRFQQROJ.js → resource-command-DUY4SVE5.js} +4 -4
@@ -0,0 +1,818 @@
1
+ # Web search
2
+
3
+ `@introspection-ai/recipes/search` implements the
4
+ `web_search` tool and its provider contract; six providers (Tavily, Exa,
5
+ Brave, Keenable, Parallel, Perplexity) ship in the companion package
6
+ `@introspection-ai/recipe-search` ([Where things live](#where-things-live)). Tavily, Exa,
7
+ Keenable, Perplexity and Parallel call their hosted MCP servers, kept behind
8
+ `web_search` ([Declare the servers](#declare-the-servers)), through Pi's
9
+ built-in MCP client, and their REST APIs only as a fallback; Brave is REST
10
+ only. Tests run against local HTTP fakes, a fake Pi tool context, and a Recipe
11
+ session with a fake MCP server, each fake answering in the format the live
12
+ server or API returned ([Live checks](#live-checks)). Nothing registers the
13
+ tool yet: [Wiring](#wiring) says what a host does.
14
+ [Open questions](#open-questions) lists what needs a decision.
15
+
16
+ An agent searches the web with one tool, `web_search`, whatever provider
17
+ serves it. A call names the query and, when it wants to, the provider, a mode
18
+ and a few filters. Each provider maps those arguments to its own API under the
19
+ hood. The model reads compact text; the host and the trace get the structured
20
+ result, including the provider, mode and billed units of every call.
21
+
22
+ The same properties hold as for [channels](../channels/README.md),
23
+ [documents](../documents/README.md) and
24
+ [productivity](../productivity/README.md):
25
+
26
+ - **One vocabulary.** Every provider takes the same arguments with the same
27
+ meaning. A provider's own vocabulary (`search_depth`, `type`, goggles,
28
+ `source_policy`) never reaches the model or the Recipe.
29
+ - **What a provider cannot do is stated, not hidden.** Each provider exports a
30
+ capability descriptor saying, per argument, whether it serves it natively,
31
+ approximately or not at all. An argument a provider cannot serve is ignored
32
+ and the result says so in one line.
33
+ - **No credential in the Recipe.** The platform's egress holds each provider's
34
+ key and injects it on the way out ([Credentials](#credentials)).
35
+
36
+ ## The call
37
+
38
+ ```ts
39
+ web_search({
40
+ query: string;
41
+ provider?: "tavily" | "parallel" | "exa" | "keenable" | "perplexity" | "brave";
42
+ mode?: "fast" | "default" | "deep";
43
+ max_results?: number; // 1-10, default 5
44
+ freshness?: "day" | "week" | "month" | "year";
45
+ sites?: string[]; // "arxiv.org" restricts, "-pinterest.com" excludes
46
+ content?: "snippets" | "context"; // default snippets
47
+ country?: string; // ISO 3166-1 alpha-2, "US"
48
+ })
49
+ ```
50
+
51
+ | Argument | Meaning |
52
+ | --- | --- |
53
+ | `query` | What to search for. Parallel also receives it as its `objective`. |
54
+ | `provider` | Which bound provider serves this call. The schema lists only the providers bound to the runtime and leaves the argument out when exactly one is bound. Omitted with several bound, the call fails with `not_bound` and lists them. |
55
+ | `mode` | `fast`, `default` or `deep`: one scale for every provider. `default` is the provider's recommended setting. Each provider maps the three to its own setting ([Modes](#modes)); a provider with one setting maps all three to it and says so in a note. |
56
+ | `max_results` | At most 10 per call, by design: it keeps a response near 550 tokens. OpenRouter's web search allows 25; a Recipe option to raise the ceiling is possible but not built. A provider that returns fewer says so. |
57
+ | `freshness` | Pages from the last day, week, month or year. |
58
+ | `sites` | Domains, optionally with a path, to keep (`arxiv.org`) or drop (`-pinterest.com`). |
59
+ | `country` | Results for one country: an ISO 3166-1 alpha-2 code in upper case (`US`, `DE`). A code that is not an assigned country (`ZZ`, `EU`) fails with `invalid_request`. Each provider receives it in its own form ([Arguments by provider](#arguments-by-provider)). |
60
+ | `content` | `snippets`: about 300 characters per result. `context`: about 1,500 characters of query-relevant text extracted from each page, for grounding (Brave's LLM Context API, Exa's highlights, Tavily's chunks, Parallel's excerpts, Perplexity's page content, Keenable's longer snippets). |
61
+
62
+ Every call chooses its own provider and mode. A Recipe that wants a cheap
63
+ first pass and a thorough second one asks for `mode: "fast"` and then
64
+ `mode: "deep"`, or two providers, within one task. There is no Recipe
65
+ configuration: the providers offered are the providers bound to the runtime.
66
+
67
+ ### Result for the model
68
+
69
+ Compact text, not JSON:
70
+
71
+ ```text
72
+ [1] Agents that search — arxiv.org · 2026-10-02
73
+ https://arxiv.org/abs/2601.00001
74
+ Relevance-ranked text from the page, cut at the content level's length…
75
+
76
+ [2] Example post — example.com · 2026-11-01
77
+ https://www.example.com/post
78
+ An example…
79
+
80
+ (approximated: freshness — Exa filters on published date from the start of the window, so undated pages drop out.)
81
+ ```
82
+
83
+ A note line appears only when an argument was ignored or approximated. A
84
+ failure is one line: `web_search failed (too_many_requests): tavily answered
85
+ 429 … Retry after 30s.`, and the tool result's `details.error` carries the
86
+ same typed error, `{ code, message, status?, retry_after_seconds?, limit? }`:
87
+
88
+ | Code | When | What the model can do |
89
+ | --- | --- | --- |
90
+ | `not_bound` | No provider named when several are bound, or the one named is not bound | Name one of those the message lists |
91
+ | `not_configured` | No credential path for the provider, or it answered 401 or 403 | Use another provider, or say search is unavailable |
92
+ | `out_of_credit` | The provider answered 402: its account is out of credit (Parallel and Keenable document it) | Use another provider, or say search is unavailable |
93
+ | `invalid_request` | An argument fails the schema, or the provider answered 400 or 422 | Fix the argument |
94
+ | `query_too_long` | The query is longer than the provider accepts (`limit`), checked before calling it: Tavily 400 characters, Brave 400 characters and 50 words | Shorten the query |
95
+ | `max_uses_exceeded` | The task has made as many calls as the Recipe allows (`limit`) | Work with the results it has |
96
+ | `too_many_requests` | The provider answered 429; `retry_after_seconds` from `Retry-After`, in seconds or as a date | Wait, or use another provider |
97
+ | `unavailable` | The provider could not be reached or answered 5xx | Retry later or use another provider |
98
+ | `provider_error` | Anything else | Report it |
99
+
100
+ ### Search budget
101
+
102
+ A Recipe caps how many calls one task may make with `maxUses` on
103
+ `createWebSearch` or `registerWebSearchTool` (the host creates one per task
104
+ session). It is not a model argument. A call past the cap fails with
105
+ `max_uses_exceeded` and the limit, before any provider request; a call refused
106
+ earlier (unbound provider, invalid argument, query too long) does not count.
107
+ Unset, there is no cap: the default is none, because a sensible number depends
108
+ on the Recipe, and the platform's per-call pricing is where cost is governed.
109
+
110
+ This mirrors `max_uses` on OpenRouter's web-search server tool. OpenRouter
111
+ also caps `max_total_results` per request; the same cap here would be a
112
+ Recipe option beside `maxUses` (never a model argument) that lowers each
113
+ call's `max_results` to what is left and refuses once none is. It is not
114
+ built: per-result prices apply only beyond each provider's included 10, which
115
+ `max_results` never exceeds.
116
+
117
+ ### Result for the host and the trace
118
+
119
+ The tool result's `details`, and the return value for Recipe code, is a
120
+ `WebSearchResult`:
121
+
122
+ ```ts
123
+ {
124
+ results: Array<{ url, title?, snippet?, published_at?, score?, site? }>;
125
+ provider: "tavily";
126
+ mode: "deep";
127
+ setting: "advanced"; // the provider's own setting that ran, or null
128
+ transport: "mcp"; // the provider's MCP server, or "rest"
129
+ content: "context"; // what was served, after any downgrade
130
+ notes: Array<{ option, outcome: "ignored" | "approximated", detail }>;
131
+ usage: { requests: 1, units?: { name: "credits", count: 2 } };
132
+ }
133
+ ```
134
+
135
+ `setting` is what ran, which is the mode's setting unless an MCP tool cannot
136
+ run it: Exa's `web_search_exa` always runs `auto`, and its advanced tool has
137
+ no `deep`, so a call there records `auto` beside the `mode` it asked for, with
138
+ an `approximated` note. Parallel's MCP tool takes no mode and its answer does
139
+ not say which ran, so `setting` is `null` and no setting is recorded or
140
+ priced.
141
+
142
+ Each call records a `web_search` span with `search.provider`, `search.mode`,
143
+ `search.setting` (left out when `null`), `search.transport`, `search.content`, `search.results`,
144
+ `search.requests`, `search.units.name` and `search.units.count` when the
145
+ provider reports them, and `search.notes`. A call over MCP adds a child client
146
+ span, `tools/call <tool>`, with `mcp.method.name`, `gen_ai.tool.name` and
147
+ `search.mcp.server`, as the Google productivity provider (PR #457) records
148
+ its MCP calls; an `isError` result sets `error.type` to `tool_error`. A
149
+ failed call sets `error.type` to the error code. Cost
150
+ per provider and mode is therefore a query over spans. The span does not carry
151
+ the query, which can hold personal data.
152
+
153
+ A successful call also records the platform's standard usage record:
154
+ `introspection.usage.service` (`<provider>/search`), `.unit` (`credit` when
155
+ the provider reported credits, Tavily's and Keenable's over REST, else
156
+ `request`), `.quantity`, `.variant` (the `search.setting`, left out when it is
157
+ `null`), `.results` (results returned, for providers that price results beyond
158
+ an allowance), `.cost_usd` (Exa's reported dollars, over REST and over its
159
+ advanced MCP tool) and `.key_owner`
160
+ (`customer`, since a project endpoint holds the key). The platform prices it
161
+ against its vendor rate catalog; `search.units.*` stays as the provider's own
162
+ unit.
163
+
164
+ ### Recipe code
165
+
166
+ Recipe code calls the same function with the same arguments:
167
+
168
+ ```ts
169
+ import {
170
+ createWebSearch,
171
+ loadSearchProviders,
172
+ } from "@introspection-ai/recipes/search";
173
+
174
+ const providers = await loadSearchProviders({ recipeDir });
175
+ const search = createWebSearch({ providers, bound: ["tavily", "brave"] });
176
+ const { results } = await search({
177
+ query: "…",
178
+ provider: "tavily",
179
+ mode: "deep",
180
+ });
181
+ ```
182
+
183
+ A host that registers the tool returns the same function from
184
+ `registerWebSearchTool`, so an extension can share it. Calling the function
185
+ from Recipe code reaches providers over REST; MCP servers are reached
186
+ through the `web_search` tool.
187
+
188
+ ## Providers
189
+
190
+ Researched from each provider's official SDK source, API reference or
191
+ published skill, and checked against the live API where this session could
192
+ reach it ([Live checks](#live-checks)). Prices are list prices as last known
193
+ and must be checked before they are relied on; nothing in the tool depends on
194
+ them.
195
+
196
+ | Provider | Endpoint | Credential header | Quality knob | Content | Filters | Max results | Billing | Sources |
197
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- |
198
+ | Tavily | `POST https://api.tavily.com/search` | `Authorization: Bearer` | `search_depth`: `ultra-fast`, `fast`, `basic`, `advanced` | `content` per result; `chunks_per_source` 1-3 (advanced only); `include_raw_content`; `include_answer` | `time_range`, `start_date`/`end_date`, `include_domains`/`exclude_domains`, `topic` (general, news, finance), `country`, `exact_match` | 20 | Credits: 1 per basic, fast or ultra-fast search, 2 per advanced; `include_usage` reports them | [API reference](https://docs.tavily.com/documentation/api-reference/endpoint/search), [credits](https://docs.tavily.com/documentation/api-credits), [tavily-js](https://github.com/tavily-ai/tavily-js) |
199
+ | Exa | `POST https://api.exa.ai/search` | `x-api-key` | `type`: `auto` (recommended), `lite` (beta), `fast` and `instant` (legacy), `neural`, `keyword`, `deep-lite`, `deep`, `deep-reasoning` | `contents.highlights` (query-relevant extracts), `contents.text`, `contents.summary` | `startPublishedDate`/`endPublishedDate`, `includeDomains`/`excludeDomains`, `category`, `userLocation`, `includeText`/`excludeText` | 100 | Dollars per request by type and contents; the response's `costDollars` reports them | [Search reference](https://docs.exa.ai/reference/search), [exa-js](https://github.com/exa-labs/exa-js) |
200
+ | Parallel | `POST https://api.parallel.ai/v1/search` | `x-api-key` | `mode`: `turbo`, `fast`, `basic`, `advanced` (the default when omitted) | `excerpts` per result (markdown); `advanced_settings.excerpt_settings.max_chars_per_result`, `max_chars_total` | `objective` and `search_queries` (at least one, 3-6 words each); in `advanced_settings`: `source_policy` (`include_domains`, which when set makes `exclude_domains` ignored; `exclude_domains`; `after_date`), `location` (ISO 3166-1 alpha-2, lower case), `fetch_policy`. Unknown fields answer 422 | `advanced_settings.max_results`, default 10 | Per request; the response's `usage` lists SKUs (`sku_search`, …) and counts; `402` means the account is out of credit | [Search API reference](https://docs.parallel.ai/api-reference/search-beta/search), [parallel-sdk-typescript](https://github.com/parallel-web/parallel-sdk-typescript) |
201
+ | Perplexity | `POST https://api.perplexity.ai/search` (the Search API, not Sonar's chat completions) | `Authorization: Bearer` | `search_type`: `web` (default), `fast` | `snippet` per result; `max_tokens_per_page`, `max_tokens` | `search_recency_filter` (hour to year), `search_after_date_filter`/`search_before_date_filter`, `search_domain_filter` (`-` prefix denies), `country`, `search_language_filter`, `search_mode` (web, academic, sec) | 20 | Per request | [perplexity-node](https://github.com/perplexityai/perplexity-node) (`src/generated/api.ts`), [modelcontextprotocol](https://github.com/perplexityai/modelcontextprotocol) (`src/server.ts`) |
202
+ | Keenable | `POST https://api.keenable.ai/v1/search` (keyless `/v1/search/public` with an `X-Keenable-Title` header) | `X-API-Key` | `mode`: `realtime` (fastest), `pro` (the default) | `snippet` (`snippet_max_length` 180-10,000 characters), `description`; page text through `fetch_page_content` | `site` (one domain), `published_after`/`published_before` and `acquired_after`/`acquired_before` (a date, a timestamp or an offset such as `7d`), `query_time` | 50 | Credits: 1 per `realtime` or `pro` search, in the response's `usage` (`sku`, `amount`, `credits`, `paid`); $4 per 1,000 requests (confirmed by Introspection); `402` means out of credits | [keenable.ai](https://keenable.ai), the live API and MCP server |
203
+ | Brave | `GET https://api.search.brave.com/res/v1/web/search` and `GET …/res/v1/llm/context` | `X-Subscription-Token` | none | Web Search: `description`, `extra_snippets` (up to 5). LLM Context: extracted `snippets` per URL, bounded by `maximum_number_of_tokens(_per_url)` and `maximum_number_of_snippets(_per_url)` | `freshness` (`pd`, `pw`, `pm`, `py` or a date range), Goggles (inline `$discard`, `$site=`), `country`, `search_lang`, `safesearch`, `context_threshold_mode` | Web Search 20, LLM Context 50 | Both on the Search plan; $5 of monthly credit covers about 1,000 requests | [LLM Context](https://api-dashboard.search.brave.com/app/documentation/llm-context/get-started), [brave-search-skills](https://github.com/brave/brave-search-skills) |
204
+
205
+ **Rate limits** are per plan for every provider and none was confirmed from a
206
+ reachable source. All answer `429` when exceeded; when the answer carries
207
+ `Retry-After`, the tool passes it to the model as a retry delay. Parallel's
208
+ anonymous MCP tier is rate-limited by the `session_id` each call sends: one
209
+ random id per `createWebSearch`, so per task, never the task id.
210
+
211
+ ## MCP servers
212
+
213
+ Where a provider runs a hosted MCP server, `web_search` calls the server's
214
+ search tool and falls back to the REST API only for what the tool cannot
215
+ express. MCP first is decided for Tavily, Exa, Keenable, Perplexity and
216
+ Parallel. Each server's `tools/list` and one call were run live, except
217
+ Perplexity's, which needs a key this session did not have; its row is from the
218
+ server's source ([perplexityai/modelcontextprotocol](https://github.com/perplexityai/modelcontextprotocol)
219
+ `src/server.ts`, 1.4.0).
220
+
221
+ | Provider | Server | Auth | Search tool and its arguments | Cannot express | Result | Choice |
222
+ | --- | --- | --- | --- | --- | --- | --- |
223
+ | Tavily | `https://mcp.tavily.com/mcp/` (tavily-mcp 4.1.5) | `Authorization: Bearer <key>`; also `?tavilyApiKey=` and OAuth | `tavily_search`: `query`, `search_depth` (`basic`, `advanced`, `fast`, `ultra-fast`), `topic`, `time_range`, `start_date`/`end_date`, `max_results`, `include_domains`/`exclude_domains`, `country` (a country name; boosts rather than filters), `include_raw_content`, `include_published_date`, `filter_by_published_date`, `exact_match`, images and favicon. No other property is accepted | `chunks_per_source`, so `content: "context"` in `deep`; credits | `structuredContent` and the same JSON as text: `results[]` with `url`, `title`, `content`, `score`, `id`, and `published_date` when `include_published_date` is set; `response_time`, `request_id`. No credits | MCP; REST for `context` in `deep` |
224
+ | Exa | `https://mcp.exa.ai/mcp` (exa-search-server 3.5.0) | `x-api-key` or `Authorization: Bearer`; also `?exaApiKey=` and OAuth | Default `web_search_exa`: `query`, `numResults` only (type `auto`, highlights fixed). Opt-in `web_search_advanced_exa` (`?tools=web_search_advanced_exa,web_search_exa` on the URL): `type` (`auto`, `lite`, `fast`, `instant`: no `deep`), `numResults`, `includeDomains`/`excludeDomains`, `startPublishedDate`/`endPublishedDate`, `userLocation`, `enableHighlights`, `highlightsMaxCharacters`, `textMaxCharacters`, `contextMaxCharacters`, `category`, `maxAgeHours` (cache age, not freshness), and more | Default tool: `mode` other than `default`, `freshness`, `sites`, `country`. Advanced tool: `mode: "deep"` | Default: text with `Title:`, `URL:`, `Published:`, `Author:`, `Highlights:`. Advanced: the API's JSON as text, no `structuredContent`: `results[]` (`id`, `url`, `title`, `publishedDate`, `highlights`; the whole page as `text` unless highlights or a text limit are set), `costDollars` | MCP, advanced tool first; REST for `deep`, and when only the default tool is offered and the call filters |
225
+ | Keenable | `https://api.keenable.ai/mcp` (keenable-mcp-server 0.2.1) | `X-API-Key`; answers without a key at lower limits | `search_web_pages`: `query`, `mode` (`realtime`, `pro`), `max_results` (1-50), `snippet_max_length` (180-10,000), `site`, `published_after`/`published_before`, `acquired_after`/`acquired_before`, `query_time`, `output_format` (`text`, `json`), `session_id`, `disable_cards`. Also `fetch_page_content` | `exclude_sites`, `country`, more than one site | With `output_format: "json"`, the REST response as text (`results[]` with `title`, `url`, `description`, `snippet`, `published_at` when known, `acquired_at`), without `usage`; the credits travel in the result's `_meta` (`keenable/usage`), which Pi's client drops | MCP |
226
+ | Perplexity | `https://api.perplexity.ai/mcp` | `Authorization: Bearer <key>` | `perplexity_search`: `query`, `max_results` (1-20), `max_tokens_per_page` (256-2048), `country` (ISO alpha-2), `search_recency_filter`, `search_domain_filter` (`-` prefix denies), `search_type` (`web`, `fast`) | Nothing we send | Formatted text, `structuredContent` `{ results: <the same text> }`: `N. **title**`, then indented `URL:`, snippet, `Date:`, `Last updated:` | MCP |
227
+ | Parallel | `https://search.parallel.ai/mcp`; `search-mcp.parallel.ai` answers 401 to every call | `Authorization: Bearer <key>`; anonymous at free-tier limits, rate-limited by `session_id`. A key it does not recognize answers 401, so an anonymous call sends no key header | `web_search`: `objective`, `search_queries` (3-6 words each; `site:` with a bare domain, never a path or quoted phrase), `session_id`, `model_name`. Also `web_fetch` | `mode`, `freshness`, `country`; a result count (it returns about 10) | `structuredContent` and the same JSON as text: `search_id`, `results[]` (`url`, `title`, `publish_date` or null, `excerpts[]`, about 2,400 characters each), `warnings`, `metadata` (null), `session_id`. No mode, usage or cost | MCP; REST for `fast`, `freshness` and `country` |
228
+ | Brave | **Local only**: `@brave/brave-search-mcp-server`, stdio or a self-run HTTP server ([brave-search-mcp-server](https://github.com/brave/brave-search-mcp-server)) | `BRAVE_API_KEY` in the server's environment | `brave_web_search`, `brave_llm_context`, … | n/a | n/a | REST: a local server would need the key in the sandbox, or a placeholder the egress swaps, and adds a process for the same request |
229
+
230
+ Notes:
231
+
232
+ - **Tavily's MCP result carries scores and, asked, dates.** The adapter sends
233
+ `include_published_date: true`. It reads `structuredContent`, then the
234
+ JSON text, then the older `Title:`/`URL:`/`Content:` text format. Credits
235
+ are not reported, so the usage record counts one request.
236
+ - **Exa needs its advanced tool listed.** The binding's URL names the tools
237
+ (`?tools=web_search_advanced_exa,web_search_exa`); without the advanced
238
+ tool, a call that filters goes to REST, or, with no REST endpoint, runs on
239
+ the default tool with a note for each argument it dropped. The adapter
240
+ always sets `enableHighlights` and `highlightsMaxCharacters`, so the tool
241
+ never returns whole pages.
242
+ - **Keenable's MCP tool is asked for JSON**, and a text answer fails as
243
+ `provider_error`. Over MCP its credits are not seen; Keenable bills one
244
+ credit per search either way, so the usage record's one request matches.
245
+ - **Parallel's MCP tool takes only queries.** The adapter sends the query as
246
+ the `objective` and its first six words as the keyword query, one per
247
+ included domain with `site:` (up to five), and filters the results to the
248
+ included and excluded sites itself, by Parallel's own matching rule (a
249
+ domain covers its subdomains, a path matches at segment boundaries). It
250
+ cannot set a mode, a date or a country, so those go to REST when REST is
251
+ bound, and are noted otherwise.
252
+ - **A hosted server's tool names are the server's**, so each adapter lists
253
+ the tools it may call, and `web_search` calls only a tool the bound server
254
+ offers.
255
+
256
+ ## MCP transport
257
+
258
+ Inside the tool, a provider's MCP path sits behind one small internal
259
+ interface:
260
+
261
+ ```ts
262
+ interface SearchMcpClient {
263
+ hasTool(server: string, tool: string): boolean;
264
+ callTool(
265
+ server: string,
266
+ tool: string,
267
+ args: Record<string, unknown>,
268
+ signal?: AbortSignal,
269
+ ): Promise<McpCallToolResult>; // content, structuredContent, isError
270
+ }
271
+ ```
272
+
273
+ A provider adds an optional `mcp` adapter beside its REST `search`: the hosted
274
+ URL and credential header (for docs and bindings), the tools it may call, a
275
+ `plan(request, hasTool, now)` that maps the normalized request onto one tool's
276
+ arguments, lists what that tool cannot express and, when the tool runs a
277
+ setting other than the mode's, says which (`setting`, or `null` when the
278
+ server does not report it), and a `parse(result)` that maps the tool's answer
279
+ onto the same results REST returns. The host chooses:
280
+
281
+ 1. If the provider's MCP server is bound, the call comes through the
282
+ `web_search` tool (which carries Pi's MCP client), and
283
+ the server offers one of the adapter's tools: MCP, unless the tool cannot
284
+ express an argument **and** the REST API is bound too, in which case REST.
285
+ 2. With MCP chosen and something it cannot express, each dropped argument is
286
+ an `ignored` note, and a mode it cannot run an `approximated` one naming
287
+ the setting that ran.
288
+ 3. Otherwise REST, through the egress as before. A provider bound only as an
289
+ MCP server fails with `not_bound` when its tool is missing, or when Recipe
290
+ code calls the function directly.
291
+
292
+ ### Pi's built-in MCP client
293
+
294
+ Pi ships an MCP client (`createMcpExtension`, `pi.registerMcpServer`,
295
+ Streamable HTTP and stdio). Its tools are Pi tools named
296
+ `mcpToolName(server, tool)` (`@introspection-ai/recipes/mcp`), exposed to the
297
+ model directly, through `codemode`, deferred or hidden. An extension tool
298
+ calls one with `ctx.executeTool(name, args)`, which runs it through the same
299
+ validation, hooks and permission checks as a model's call and returns the
300
+ whole MCP `CallToolResult` as the nested result's `structuredContent`. A
301
+ tool's `reachesTools` makes such a call wait for a server still connecting.
302
+
303
+ A Recipe's server runs on that client under `mcp.mode: codemode`, and in
304
+ every mode when it is kept `behind` a tool
305
+ ([MCP configuration](../mcp-configuration.md#keep-a-server-behind-a-tool)),
306
+ which is how `web_search` uses it.
307
+
308
+ The tool backs the interface with exactly that.
309
+ `hasTool` looks for `mcpToolName(server, tool)` in `ctx.tools` and, given
310
+ `toolInfos` (the extension's `pi.getAllTools`), takes it as the server's only
311
+ when Pi's namespace for the tool is the server's (`isPiMcpServerTool`), since
312
+ Pi hashes long names and may hash two that collide. `callTool` is
313
+ `ctx.executeTool(mcpToolName(server, tool), args)`, reading the
314
+ `CallToolResult` back from `structuredContent`; a call Pi refuses (an unknown
315
+ or blocked tool) has none and fails as `unavailable`. `registerWebSearchTool`
316
+ builds it from each call's context and declares `reachesTools` with the MCP
317
+ tools it may call.
318
+
319
+ ### Declare the servers
320
+
321
+ A Recipe declares each provider's server in `package.json` and keeps it behind
322
+ `web_search` in the agent file, in any `mcp.mode`:
323
+
324
+ ```yaml
325
+ tools: [web_search]
326
+ mcp:
327
+ mode: tools # or cli, or codemode
328
+ servers:
329
+ tavily:
330
+ include: [tavily_search]
331
+ behind: [web_search]
332
+ exa:
333
+ include: [web_search_advanced_exa, web_search_exa]
334
+ behind: [web_search]
335
+ keenable:
336
+ include: [search_web_pages]
337
+ behind: [web_search]
338
+ perplexity:
339
+ include: [perplexity_search]
340
+ behind: [web_search]
341
+ parallel:
342
+ include: [web_search]
343
+ behind: [web_search]
344
+ ```
345
+
346
+ The model then sees one tool, `web_search`. The servers' tools are not
347
+ declared to it, codemode does not list them, `tool_search` does not find them,
348
+ and the system prompt's list of MCP servers leaves them out. A direct call,
349
+ from the model, a codemode script or another tool, is refused; only the calls
350
+ `web_search` nests reach the server. `test/search-mcp-behind.test.ts` checks
351
+ this in every mode against a fake Tavily server.
352
+
353
+ ### Credentials for a hosted MCP server
354
+
355
+ A provider's hosted MCP server is a Recipe MCP binding like any other: a
356
+ `kind='mcp'` endpoint whose shared header carries the provider's key through a
357
+ credential reference (`Authorization: Bearer ${TAVILY_API_KEY}`,
358
+ `x-api-key: ${EXA_API_KEY}`, `X-API-Key: ${KEENABLE_API_KEY}`,
359
+ `Authorization: Bearer ${PERPLEXITY_API_KEY}` or
360
+ `${PARALLEL_API_KEY}`), injected by the egress outside the sandbox, where MCP bindings dial the edge
361
+ and send no locator. The bootstrap carries only the URL. So:
362
+
363
+ - **Header, never query string.** Tavily's `?tavilyApiKey=` and Exa's
364
+ `?exaApiKey=` put the key in the URL the sandbox sees; bind with the header.
365
+ Exa's `?tools=` is not secret and belongs in the URL.
366
+ - **OAuth is not used.** A server on Pi's client is bound with a header, and
367
+ the key is the project's, not a member's.
368
+ - **Parallel and Keenable also serve anonymous calls**, at free-tier limits.
369
+ A binding without a credential works for evaluation; Parallel answers 401 to
370
+ a key it does not recognize, so such a binding sends no key header at all.
371
+
372
+ ## Modes
373
+
374
+ Callers only ever pass `mode: "fast" | "default" | "deep"`, the same for every
375
+ provider. Each provider's adapter turns it into that provider's own request
376
+ parameter; the table shows which parameter that is, and the value each mode
377
+ sends. The model and Recipe code never see these provider names; the value
378
+ actually sent is recorded on the call's span as `search.setting`. The rows for
379
+ built providers are their descriptors' `modes` (`test/search.test.ts` checks
380
+ this table against them); the others are the proposed mapping.
381
+
382
+ For example, `web_search({ query, provider: "tavily", mode: "deep" })` sends
383
+ Tavily `search_depth: "advanced"`.
384
+
385
+ | Provider | Provider's request parameter that `mode` sets | `mode: "fast"` sends | `mode: "default"` sends | `mode: "deep"` sends |
386
+ | --- | --- | --- | --- | --- |
387
+ | `tavily` | `search_depth` | `fast` | `basic` | `advanced` |
388
+ | `exa` | `type` | `fast` | `auto` | `deep` |
389
+ | `keenable` | `mode` | `realtime` | `pro` | `pro` |
390
+ | `perplexity` | `search_type` | `fast` | `web` | `web` |
391
+ | `parallel` | `mode` | `fast` | `advanced` | `advanced` |
392
+ | `brave` | none | one level (approximated) | one level | one level (approximated) |
393
+
394
+ A `deep` that sends the same setting as `default` is approximated, and the
395
+ result says so. Over MCP, a tool that cannot run the setting runs its own
396
+ ([Result for the host](#result-for-the-host-and-the-trace)): Exa's advanced
397
+ tool runs `auto` for `deep` (REST serves `deep` when bound), its default tool
398
+ `auto` for every mode, and Parallel's tool an unreported setting.
399
+
400
+ What each costs and means:
401
+
402
+ - **Tavily.** `basic` returns one snippet per result for 1 credit; `fast` (1
403
+ credit) trades some relevance for latency; `advanced` returns up to three
404
+ relevant chunks per source and costs 2 credits. `default` follows Tavily's
405
+ own default, `basic`, so the pairing named as "tavily / advanced" is
406
+ `mode: "deep"`.
407
+ - **Exa.** `auto` lets Exa choose its retrieval and is its recommendation.
408
+ `fast` is a legacy type Exa still accepts; it suggests `lite` for new code,
409
+ but `lite` rejects some parameters, so `fast` maps to `fast` until `lite`
410
+ accepts the ones this tool sends. `deep` runs several searches and costs
411
+ more, and only REST takes it. "exa / auto" is `mode: "default"`.
412
+ - **Keenable.** `pro`, its default, gives the better results; `realtime` is
413
+ the fastest. Both cost one credit. Nothing is deeper than `pro`, so `deep`
414
+ is approximated.
415
+ - **Perplexity.** `web` is the default search; `fast` its lower-latency,
416
+ lower-cost variant. Nothing is deeper, so `deep` is approximated.
417
+ "perplexity / default" is `mode: "default"`.
418
+ - **Parallel.** The API defaults to `advanced`, so `default` is `advanced`
419
+ and "parallel / advanced" is `mode: "default"`. `fast` targets about a
420
+ second; `turbo` and `basic` are not used. Nothing in the Search API is
421
+ deeper than `advanced` (deeper research is its Task API), so `deep` is
422
+ approximated.
423
+ - **Brave.** One quality level, so `fast` and `deep` are approximated. What
424
+ "brave / llm-context" named is not a quality level but a different endpoint
425
+ returning extracted text, which is what `content: "context"` asks for.
426
+ `content` therefore selects the endpoint: `snippets` uses Web Search,
427
+ `context` uses LLM Context. Tying it to `content` rather than `mode` keeps
428
+ `mode` one scale for every provider and lets any provider serve `context`.
429
+
430
+ ## Arguments by provider
431
+
432
+ From each descriptor's `options`. `approximate` means the argument applies in
433
+ a form close to its meaning, and the note line says how.
434
+
435
+ | Provider | `freshness` | `sites` include | `sites` exclude | `context` | `country` |
436
+ | --- | --- | --- | --- | --- | --- |
437
+ | `tavily` | native (`time_range`) | native | native | approximate: chunks only in `deep` | native (`country`, the English name in lower case, `united states`; also on the MCP tool, which boosts rather than filters) |
438
+ | `exa` | approximate: published-date start, so undated pages drop out | native | native | native (`highlights`) | native (`userLocation`; on MCP only `web_search_advanced_exa` takes it, so with the default tool a call goes to REST, or is ignored with a note) |
439
+ | `brave` | native (`freshness`) | native (Goggles allowlist) | native (Goggles `$discard`) | native (LLM Context) | native (`country`) |
440
+ | `parallel` | approximate (`after_date`; REST only) | native (`include_domains`; over MCP, `site:` queries and a filter on the results) | native, alone (`combine_sites: false`; over MCP, a filter on the results) | native (`max_chars_per_result`; over MCP, excerpts cut to length) | native (`location`, lower case; REST only) |
441
+ | `perplexity` | native (`search_recency_filter`) | native (`search_domain_filter`) | native (`-domain`), alone (`combine_sites: false`) | native (`max_tokens_per_page`: 256 for snippets, 1024 for context) | native (`country`) |
442
+ | `keenable` | approximate (`published_after`: `1d`, `7d`, `1mo`, `1y`) | native for one site (`site`; `max_include_sites: 1`, the rest ignored with a note) | none | native (`snippet_max_length`) | none: ignored with a note |
443
+
444
+ **Included and excluded sites together.** Each descriptor declares
445
+ `combine_sites`. Tavily, Exa and Brave take both in one request. Parallel
446
+ ignores exclusions once an inclusion is set (its API reference says so),
447
+ Perplexity answers 400 to both (per OpenRouter's notes on the same engines),
448
+ and Keenable takes no exclusions, so they declare `false`:
449
+ a call with both sends only the included sites and adds `(ignored: exclude
450
+ sites — … cannot combine included and excluded sites …)`. Exclusions alone
451
+ are sent as usual.
452
+
453
+ A provider that restricts to fewer sites than a call lists declares
454
+ `max_include_sites` (Keenable: 1): the first are sent, and the note names the
455
+ rest. A site's domain is lower-cased and its path kept as given, since paths
456
+ are case-sensitive.
457
+
458
+ Every provider honours `max_results` up to its own maximum. What one provider
459
+ offers and the tool does not (answers, `topic`, language, safe search, Exa's
460
+ `category`, Goggles beyond sites) is listed under [Later](#later).
461
+
462
+ ### Do site filters match subdomains?
463
+
464
+ `sites: ["example.com"]` is sent as the provider's domain filter, and whether
465
+ `blog.example.com` matches is the provider's rule, not the tool's. What each
466
+ provider states:
467
+
468
+ | Provider | Subdomains of a listed domain | Source |
469
+ | --- | --- | --- |
470
+ | `tavily` | Unknown: not stated in the API reference | [Search reference](https://docs.tavily.com/documentation/api-reference/endpoint/search) |
471
+ | `exa` | A wildcard, `*.example.com`, matches every subdomain; whether a bare domain does is not stated. A path (`exa.ai/blog`) narrows to that section | [Domain and path filter changelog](https://exa.ai/docs/changelog/domain-path-filter) |
472
+ | `brave` | Unknown: Goggles' `site=` matches on the hostname, and the quickstart does not say whether a parent domain covers its subdomains | [goggles-quickstart](https://github.com/brave/goggles-quickstart) |
473
+ | `parallel` | Yes: a plain domain matches itself and its subdomains, and a path matches at segment boundaries. The MCP path filters its results by the same rule | [Search API reference](https://docs.parallel.ai/api-reference/search-beta/search) (`SourcePolicy`) |
474
+ | `perplexity` | Unknown | |
475
+ | `keenable` | Unknown | |
476
+
477
+ The tool passes a domain as given; to be sure of a subdomain, list it, and
478
+ read each result's `site`.
479
+
480
+ ## Bound providers
481
+
482
+ How a provider is bound depends on whether it has a hosted MCP server
483
+ adapter:
484
+
485
+ - **A provider with a hosted MCP server** (Tavily, Exa, Keenable,
486
+ Perplexity, Parallel) is bound when the Recipe declares its server behind `web_search`
487
+ ([Declare the servers](#declare-the-servers)) and the runtime binds it.
488
+ `mcpServers` maps provider to server id (`{ tavily: "tavily" }`). The server
489
+ is the provider's when its bound URL has the adapter's host
490
+ (`mcp.tavily.com`, `mcp.exa.ai`, `api.keenable.ai`, `api.perplexity.ai`,
491
+ `search.parallel.ai`), or, for an evaluation fake on another
492
+ host, when its id is the provider's id. A REST endpoint for its host is then
493
+ the fallback, and on its own does not bind it.
494
+ - **A REST-only provider** (Brave) is bound
495
+ when the runtime holds an endpoint for its host with a credential: a
496
+ `kind='api'` endpoint row, at project, runtime, runtime group or
497
+ environment scope. The bound set is what the egress will authenticate. It needs no
498
+ declaration in the Recipe: a search provider is interchangeable and chosen
499
+ per call.
500
+
501
+ `boundSearchProviders({ hosts, mcpServers }, providers)` applies both rules and returns
502
+ the `bound` (REST) and `mcpServers` options for the tool: `hosts` are the
503
+ egress's credentialed endpoint hosts, `mcpServers` the servers the Recipe keeps
504
+ behind `web_search` with their bound URLs. The host discovers the hosts:
505
+
506
+ - **Legacy provider lane:** the sandbox receives the credential-injected
507
+ hosts as `INTROSPECTION_ENDPOINT_HOSTS` (comma-separated), which the data
508
+ plane builds from the session's endpoint targets.
509
+ - **Proxy-native egress:** the runtime removes `INTROSPECTION_ENDPOINT_HOSTS`
510
+ when it accepts the proxy-native offer, and
511
+ `INTROSPECTION_EGRESS_PLACEHOLDERS` is keyed by variable name, not host. So
512
+ on a proxy-native runtime nothing in the sandbox lists the bound hosts
513
+ today. The proposal is that the data plane keeps a non-secret list of
514
+ credentialed endpoint hosts in the bootstrap (or keeps the variable as
515
+ information only), and that the runtime passes it to Recipes. This needs a
516
+ platform decision; it affects only Brave, and the REST fallbacks.
517
+ - **Other hosts** pass `bound` themselves, and `credentialHeaders` when they
518
+ attach credentials their own way.
519
+
520
+ A bound provider this package does not implement is not offered.
521
+
522
+ ## Credentials
523
+
524
+ A provider sends its request to its own host, and the Recipe never holds the
525
+ key. The host's egress supplies it, as for the Slack channel
526
+ (`packages/channels/slack/src/client.ts`):
527
+
528
+ | Provider | Host to bind | Header the endpoint injects |
529
+ | --- | --- | --- |
530
+ | Tavily | `api.tavily.com` | `Authorization: Bearer <key>` |
531
+ | Exa | `api.exa.ai` | `x-api-key: <key>` |
532
+ | Parallel | `api.parallel.ai` (MCP: `search.parallel.ai`, `Authorization: Bearer`) | `x-api-key: <key>` |
533
+ | Perplexity | `api.perplexity.ai` (REST and MCP) | `Authorization: Bearer <key>` |
534
+ | Keenable | `api.keenable.ai` (REST and MCP) | `X-API-Key: <key>` |
535
+ | Brave | `api.search.brave.com` | `X-Subscription-Token: <key>` |
536
+
537
+ - **Proxy-native egress** (`INTROSPECTION_EGRESS_PROXY_NATIVE=1`): the request
538
+ leaves without the header. The egress intercepts the bound host and, finding
539
+ the endpoint's header absent, injects it.
540
+ - **Legacy provider lane** (`INTROSPECTION_EGRESS_URL` and
541
+ `INTROSPECTION_TOKEN`): the session locator travels in the provider's own
542
+ header, with its prefix, and ext_proc swaps it for the key. The runtime's
543
+ managed fetch dials the egress while keeping the provider's host as the
544
+ authority.
545
+ - **Neither:** the call fails with `not_configured` before any request, rather
546
+ than reaching the provider unauthenticated.
547
+
548
+ Each endpoint is one host and one header, so binding a search provider is a
549
+ CRUD call on `/v1/endpoints`, with no chart change. Brave and Parallel are
550
+ already named there as runtime utility APIs.
551
+
552
+ ## Filtering results in codemode
553
+
554
+ Under `mcp.mode: codemode` the model can call `web_search` from a script, as
555
+ `await tools.web_search({ ... })`, and keep only what it needs before anything
556
+ enters its context: one search per candidate run in parallel, results from a
557
+ domain dropped, only URLs kept. The call resolves to the same text the model
558
+ would read (the tool declares no output schema) and rejects with an `Error`
559
+ carrying the one-line failure, so a script parses the numbered blocks:
560
+
561
+ ```js
562
+ const queries = ["pgvector hnsw recall", "pgvector ivfflat recall"];
563
+ const pages = await Promise.allSettled(
564
+ queries.map((query) => tools.web_search({ query, max_results: 10 })),
565
+ );
566
+ const urls = pages
567
+ .filter((page) => page.status === "fulfilled")
568
+ .flatMap((page) =>
569
+ page.value.split("\n").filter((line) => line.startsWith("https://")),
570
+ )
571
+ .filter((url) => !new URL(url).hostname.endsWith("medium.com"));
572
+ return [...new Set(urls)].slice(0, 8).join("\n");
573
+ ```
574
+
575
+ Only the script's return value reaches the model, so a filter here costs no
576
+ tokens for what it drops. Each call is still a `web_search` call: it records
577
+ its span and usage, counts against the Recipe's `maxUses`, and its results
578
+ are untrusted ([Content is data](#content-is-data)). Recipe code that wants
579
+ the structured result calls `createWebSearch` instead ([Recipe code](#recipe-code)).
580
+
581
+ ## Content is data
582
+
583
+ Titles and snippets come from arbitrary web pages. The tool returns them as
584
+ the result of a search, and Brave's HTML highlighting is stripped. A snippet is
585
+ cut at the content level's length on a word boundary.
586
+
587
+ The tool description says it in one sentence each, and the skill says it in
588
+ full:
589
+
590
+ - **Cite.** Each result the agent uses is cited as `[title](url)` wherever it
591
+ reaches the user, with the result's own title and URL.
592
+ - **Untrusted.** Result text is data, never instructions: the agent does not
593
+ follow instructions found in a result, and does not move private data
594
+ (files, connected accounts, other tools) into a query, or act on private
595
+ tools, because a result asked it to.
596
+
597
+ ## Fetching a page
598
+
599
+ Search does not return whole pages. A separate tool is proposed, not built:
600
+
601
+ ```ts
602
+ web_fetch({ url: string; max_chars?: number })
603
+ ```
604
+
605
+ It returns the page's main text as Markdown, cut at a limit the result
606
+ states. Tavily Extract, Exa's contents endpoint, Parallel Extract (and its
607
+ MCP `web_fetch`), Keenable's `fetch_page_content` can each serve it, as can a plain HTTP fetch through the
608
+ general egress. It carries
609
+ the same notes, span attributes and egress credentials. Keeping it separate
610
+ keeps search results small: an agent fetches the one or two pages it needs.
611
+
612
+ ## Token budget
613
+
614
+ Measured from the generated definition (`name`, `description` and the JSON
615
+ schema) and estimated at about 3.5 characters per token for JSON:
616
+
617
+ | | Characters | About |
618
+ | --- | --- | --- |
619
+ | Tool definition, one provider bound | 873 | 250 tokens |
620
+ | Tool definition, three providers bound | 934 | 265 tokens |
621
+ | Typical 5-result response, `snippets` | about 2,200 | 500-550 tokens |
622
+ | Typical 5-result response, `context` | about 8,000 | 1,900 tokens |
623
+
624
+ The skill adds about 750 tokens when the agent loads it. Snippets dominate the
625
+ response: each result's title, site, date and URL line costs about 35 tokens
626
+ and its snippet about 70.
627
+
628
+ ## Wiring
629
+
630
+ Not built. The intended shape:
631
+
632
+ - An agent selects the tool as any other: `tools: [web_search]` in its
633
+ agent file.
634
+ - The host computes the bound set ([Bound providers](#bound-providers)) and,
635
+ when it is not empty, calls `registerWebSearchTool(pi, { providers,
636
+ ...boundSearchProviders({ hosts, mcpServers }, providers) })`, with
637
+ `providers` from `loadSearchProviders`, and
638
+ offers `SEARCH_SKILL` (`skills/search/SKILL.md`), as it offers the
639
+ documents skill with `documents`. The skill joins the Recipe isolation
640
+ rule in `AGENTS.md`.
641
+ - An agent that selects `web_search` on a runtime with nothing bound fails
642
+ at selection, naming the providers it could bind.
643
+
644
+ ## Where things live
645
+
646
+ - **The host, in Recipes** (`src/search`, the `@introspection-ai/recipes/search`
647
+ subpath): the tool's schema and registration (`createWebSearch`,
648
+ `registerWebSearchTool`), argument normalization (modes, sites, country,
649
+ freshness, the budget), typed errors, the MCP path through Pi's
650
+ `ctx.executeTool`, the HTTP request and its credential lanes, spans and the
651
+ usage record, `boundSearchProviders`, `loadSearchProviders`, and the
652
+ provider contract (`SearchProviderModule`, `RecipeSearchModule`,
653
+ `SEARCH_PROVIDER_API_VERSION`).
654
+ - **The providers, in `@introspection-ai/recipe-search`** (`packages/search`):
655
+ one plain `SearchProviderModule` per provider, exported together as the
656
+ package's default `RecipeSearchModule` (`{ kind: "search", apiVersion,
657
+ providers }`) and each by name. It imports only types from Recipes; the
658
+ host injects what runs (`context.request` for HTTP, the MCP call itself).
659
+ It is a companion package: Recipes installs it alongside itself as an
660
+ `optionalDependency`, and a Recipe that lists it in `dependencies` pins
661
+ its copy.
662
+
663
+ `loadSearchProviders({ recipeDir, hostDir?, declarations? })` resolves the
664
+ package from the Recipe, then beside Recipes, checks its `apiVersion` and
665
+ returns the providers. With the package not installed it returns none, and
666
+ `web_search` offers no provider: a call fails with `not_bound`.
667
+
668
+ ### Declare providers
669
+
670
+ A Recipe that declares nothing gets the first-party providers the runtime
671
+ binds. `pi.search` names the providers instead, first-party by id or the
672
+ Recipe's own by `package` (an installed package listed in `dependencies`):
673
+
674
+ ```json
675
+ {
676
+ "pi": {
677
+ "search": [
678
+ { "provider": "brave" },
679
+ { "provider": "acme", "package": "@acme/recipe-search" }
680
+ ]
681
+ }
682
+ }
683
+ ```
684
+
685
+ A host passes the manifest's `search` as `declarations`, and
686
+ `loadSearchProviders` loads them through the shared provider loader
687
+ ([providers.md](../providers.md)). Ids are open slugs, unique in `pi.search`;
688
+ `SEARCH_PROVIDER_IDS` lists the first-party ones.
689
+
690
+ ## Write a provider
691
+
692
+ A provider is a plain module, `SearchProviderModule`:
693
+
694
+ - `kind: "search"`, `apiVersion` (`SEARCH_PROVIDER_API_VERSION`, checked
695
+ when it loads), and `id`, the id its declaration names.
696
+ - `capabilities`: `modes` (each of `fast`, `default` and `deep` with the
697
+ provider's `setting`, and `approximate` when the setting does not mean the
698
+ mode), `mode_parameter`, `max_results`, `combine_sites`,
699
+ `max_include_sites` where it takes fewer sites than a call lists, `options` (native, approximate or
700
+ none for `freshness`, `include_sites`, `exclude_sites` and `context`, with a
701
+ one-sentence `note` for each approximation), `host`, `hosts` (every host it
702
+ sends to, REST and MCP), `credential` (header and prefix) and `billing`.
703
+ - `mcp` (optional): the hosted server's `url` and `credential`, the `tools`
704
+ it may call, `plan` and `parse` ([MCP transport](#mcp-transport)).
705
+ - `search(request, context)`: `request` is normalized, with the mode's
706
+ `setting`, the content level and its `max_chars`, and only the arguments the
707
+ descriptor serves, and a `session` id stable for the task.
708
+ `context` carries `request(path, init)`, which sends one JSON request to the
709
+ provider's host with the credential its egress lane needs and throws a
710
+ typed `SearchProviderError` for a failure (429 with its delay, 401, 402,
711
+ 5xx), `now` and the abort `signal`. It returns results and the billed
712
+ `units`. An adapter's MCP `parse` may throw a plain `Error`, which the host
713
+ reports as `provider_error`.
714
+
715
+ The six providers share one package, `@introspection-ai/recipe-search`,
716
+ because each is a few HTTP or MCP calls with no SDK and no dependency of its
717
+ own. A provider that needs its own dependencies would be a companion package
718
+ of its own under the companion rule in `AGENTS.md`.
719
+
720
+ ## Test search
721
+
722
+ - **Unit:** `test/search.test.ts` loads the providers from
723
+ `packages/search` and runs each against a local HTTP
724
+ server: request shape per mode and argument, the credential header on each
725
+ egress lane, response mapping, notes, errors and spans. The MCP path runs
726
+ against a fake Pi tool context whose `executeTool` answers as Pi's client
727
+ does, with each server's real output format as the live servers returned
728
+ it (Tavily's `structuredContent` and older text, Exa's JSON and text,
729
+ Keenable's JSON, Perplexity's formatted text, Parallel's
730
+ `structuredContent`): tool name and arguments, MCP or REST per argument,
731
+ the setting that ran, notes, tool errors, refused calls and the MCP span.
732
+ No live calls and no keys.
733
+ - **Session:** `test/search-mcp-behind.test.ts` runs a Recipe session in each
734
+ `mcp.mode` with a fake Tavily MCP server behind `web_search`: the tool's
735
+ nested call reaches the server, and a direct call from the model or a
736
+ codemode script is refused.
737
+ - **Evals:** a search provider is a REST API, so it fits eval-simulate's API
738
+ fakes (`@introspection-ai/eval-simulate`):
739
+ one fake per provider under `fakes/api/<id>/`, its manifest naming the host
740
+ above, and a scenario's world holding the pages each query finds. Parallel
741
+ and Perplexity generate their SDKs from OpenAPI documents the trim could
742
+ capture; for the others the document would be written from their
743
+ reference. Until then, a Recipe's eval can bind a fake provider module
744
+ through `providers`.
745
+ - **Evals over MCP:** the provider's MCP server is an ordinary binding, so
746
+ an eval binds an MCP fake for it, as for any MCP server.
747
+ - **Live:** `introspection dev` with a bound endpoint per provider, or a
748
+ script calling `createWebSearch` over REST through a proxy that injects
749
+ the keys ([Live checks](#live-checks)).
750
+
751
+ ## Later
752
+
753
+ Possible additions, each only once a real Recipe needs it:
754
+
755
+ - **Fallback** to another bound provider on a rate limit or outage, reported
756
+ in the notes and the span.
757
+ - **Strict** mode, refusing an argument a provider cannot serve exactly, for
758
+ evals that compare providers.
759
+ - **Recipe defaults** for `country`, `language`, `topic`, safe search and
760
+ snippet length.
761
+ - **Provider passthrough** options, such as Tavily's `chunks_per_source` or a
762
+ Brave Goggle, outside the model's schema.
763
+ - **Answers**: Tavily's `include_answer` and Perplexity's Sonar return an
764
+ answer with citations. An answer is a model's summary of results the agent
765
+ could read itself, so it belongs in the tool only if it saves real tokens
766
+ and keeps its citations.
767
+ - **Several queries in one call**, which Parallel takes natively
768
+ (`search_queries`); others would fan out and merge.
769
+ - **Pagination.**
770
+
771
+ ## Live checks
772
+
773
+ Run from a session whose egress proxy injected the Keenable, Tavily, Exa and
774
+ Brave keys, with a script around `web_search` and a minimal Streamable HTTP
775
+ MCP client (not committed). Every call below returned results in the shape the tests'
776
+ fakes use:
777
+
778
+ | Provider | Transport | Call | Came back |
779
+ | --- | --- | --- | --- |
780
+ | Keenable | MCP | `fast`, `freshness: "year"` | `realtime`, 3 dated results; no credits over MCP |
781
+ | Keenable | MCP | `context`, `sites: ["github.com"]` | `pro`, 2 github.com results |
782
+ | Keenable | REST | default | `pro`, 3 results, `usage` 1 credit |
783
+ | Tavily | MCP | `deep`, `country`, `freshness`, an exclusion | `advanced`, results with scores and dates |
784
+ | Exa | MCP | advanced tool, `freshness: "year"` | `auto`, 3 dated results with highlights, $0.007 |
785
+ | Exa | MCP | `deep` | ran `auto`, with the approximated note |
786
+ | Parallel | MCP, anonymous | `sites: ["github.com"]` | 3 github.com results; no setting reported |
787
+ | Brave | REST | `snippets` | 3 results from Web Search |
788
+ | Brave | REST | `context`, `sites: ["github.com/modelcontextprotocol"]` | 3 github.com results from LLM Context; one of two runs also returned `github.com/jancurn/modelcontextprotocol/…`, since a Goggles path pattern is not anchored to the start of the path |
789
+
790
+ Not run live: Perplexity (no key; built from its server's source), Parallel's
791
+ REST API (the account had no credit, which answered 402), and Exa's and
792
+ Tavily's REST APIs (unchanged, fake-tested).
793
+
794
+ ## Open questions
795
+
796
+ 1. **Bound hosts under proxy-native egress.** Nothing in a proxy-native
797
+ sandbox lists the bound endpoint hosts. Should the data plane keep
798
+ `INTROSPECTION_ENDPOINT_HOSTS` (or a new non-secret list) for discovery?
799
+ 2. **Answers.** Do answer-style providers (Perplexity Sonar, Tavily's
800
+ answer, Exa's answer endpoint) belong in `web_search`, in a separate
801
+ `web_answer` tool, or nowhere?
802
+ 3. **Cost limits.** A Recipe can cap calls per task (`maxUses`). Does the
803
+ platform also need a budget in money, or one that refuses only `deep` once
804
+ spent?
805
+ 4. **Tavily `default`.** It maps to Tavily's own default, `basic`, so the
806
+ named pairing "tavily / advanced" is `mode: "deep"`. Confirm, or map
807
+ `default` to `advanced`.
808
+ 5. **Exa `fast`.** Keep the legacy `fast` type, or move to `lite` and accept
809
+ that it rejects some arguments?
810
+ 6. **Credits over MCP.** Keenable reports credits in the result's `_meta`,
811
+ which Pi's client drops, and Tavily's MCP result reports none, so over MCP
812
+ both record one request. Should Pi pass `_meta` through to nested calls?
813
+ 7. **Parallel's MCP setting.** Its tool runs a mode it does not report, so
814
+ those calls carry no `setting` and no usage variant. Price them as
815
+ `advanced` (the API's default), or route every Parallel call that names a
816
+ mode to REST?
817
+ 8. **Perplexity live.** Its server's tool and output format are from source;
818
+ one keyed `tools/list` and call would confirm them.