Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): suppress capped PDF hint

Rakshith Ramprakashc68d9a5e5156
diff --git a/apps/api/AGENT_HINTS.md b/apps/api/AGENT_HINTS.md
index a56e32aaf..37e090a02 100644
--- a/apps/api/AGENT_HINTS.md
+++ b/apps/api/AGENT_HINTS.md
@@ -23,7 +23,7 @@ Raw HTTP and ordinary SDK callers receive no hints unless their adapter explicit
- Search result cluster: when at least four valid HTTP(S) result URLs are present and at least three share one origin representing at least 75% of valid result URLs, offer Map for URL discovery or Crawl for multi-page content.
- Source page 401: when a successful Scrape envelope includes both a page status of 401 and a scrape ID in `metadata.scrapeId` or top-level `scrape_id`, offer Interact using that concrete scrape ID for authentication or page interaction.
- Source page 404/410: offer Search for a current location or alternative. An API cache-miss 404, 429, authentication failure, or timeout does not fire this rule.
-- Truncated PDF: when Scrape reports `totalPages > numPages`, offer another Scrape with a higher PDF `maxPages` value, capped at the API maximum of 10,000.
+- Truncated PDF: when Scrape reports `totalPages > numPages`, offer another Scrape only when its PDF `maxPages` can be raised, capped at the API maximum of 10,000.
- Low credits: when the authoritative billing preflight reports fewer than 100 credits, ask the agent to let the user know they should add more credits. This notice is independent of endpoint success for responses that reach the hint middleware, and it does not replace a useful cross-endpoint suggestion.
Selection reads only request/response fields and billing state already in memory. It makes no additional network/model calls, reads no additional session/database state, and does not scan page text or classify user intent. No hint appears solely to fill an available slot.
diff --git a/apps/api/src/lib/agent-hints.test.ts b/apps/api/src/lib/agent-hints.test.ts
index 5d4918185..0ebbbc4ca 100644
--- a/apps/api/src/lib/agent-hints.test.ts
+++ b/apps/api/src/lib/agent-hints.test.ts
@@ -243,6 +243,9 @@ describe("deterministic agent hints", () => {
expect(
hints({ endpoint: "scrape", response: response(5, 12000) }).join(" "),
).toContain('"maxPages":10000');
+ expect(
+ hints({ endpoint: "scrape", response: response(10000, 12000) }),
+ ).toEqual([]);
expect(hints({ endpoint: "scrape", response: response(47, 47) })).toEqual(
[],
);
diff --git a/apps/api/src/lib/agent-hints.ts b/apps/api/src/lib/agent-hints.ts
index fba028015..e97d4a4d6 100644
--- a/apps/api/src/lib/agent-hints.ts
+++ b/apps/api/src/lib/agent-hints.ts
@@ -77,7 +77,9 @@ export function buildAgentHints(context: AgentHintContext): string[] {
metadata.totalPages > metadata.numPages
) {
const maxPages = Math.min(metadata.totalPages, 10000);
- nextAction = `This document returned ${metadata.numPages} of ${metadata.totalPages} pages. If you need more pages, repeat POST /v2/scrape for the same URL with {"parsers":[{"type":"pdf","maxPages":${maxPages}}]}.`;
+ if (maxPages > metadata.numPages) {
+ nextAction = `This document returned ${metadata.numPages} of ${metadata.totalPages} pages. If you need more pages, repeat POST /v2/scrape for the same URL with {"parsers":[{"type":"pdf","maxPages":${maxPages}}]}.`;
+ }
} else if (context.endpoint === "search") {
const web = Array.isArray(response.data)
? response.data