Skip to content

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

Allow effort alongside model spark-2 on POST /v2/agent

mogery862081e241fb
diff --git a/apps/api/src/__tests__/snips/v2/agent-effort.test.ts b/apps/api/src/__tests__/snips/v2/agent-effort.test.ts
index 2cb77cac9..f9866a188 100644
--- a/apps/api/src/__tests__/snips/v2/agent-effort.test.ts
+++ b/apps/api/src/__tests__/snips/v2/agent-effort.test.ts
@@ -41,20 +41,20 @@ const agentRaw = (body: Record<string, unknown>) =>
// request therefore needs only the API server and an authenticated team, so
// these cases run everywhere instead of skipping with the live runs below.
describe("Agent effort parameter validation", () => {
- it(
- "rejects model and effort together",
- async () => {
+ it.each(["spark-1-pro", "spark-1-mini"] as const)(
+ "rejects effort with %s, which has no reasoning budget",
+ async model => {
const response = await agentRaw({
urls: [TEST_SUITE_WEBSITE],
prompt: "What does this page offer?",
- model: "spark-1-pro",
+ model,
effort: "low",
});
expect(response.statusCode).toBe(400);
expect(response.body.success).toBe(false);
- expect(response.body.error).toContain("model");
expect(response.body.error).toContain("effort");
+ expect(response.body.error).toContain("spark-2");
},
scrapeTimeout,
);
@@ -119,6 +119,37 @@ describeIf(REQUIRES_FIRE_ENGINE && REQUIRES_AI && HAS_AGENT_BETA)(
scrapeTimeout,
);
+ it(
+ "accepts spark-2 and effort together",
+ async () => {
+ const response = await agentRaw({
+ urls: [TEST_SUITE_WEBSITE],
+ prompt: "What does this page offer?",
+ model: "spark-2",
+ effort: "low",
+ });
+
+ if (response.statusCode !== 200) {
+ console.warn(
+ "Agent request with model spark-2 and effort did not succeed",
+ JSON.stringify(response.body, null, 2),
+ );
+ }
+
+ expect(response.statusCode).toBe(200);
+ expect(response.body.success).toBe(true);
+ expect(typeof response.body.id).toBe("string");
+
+ const status = await statusOf(response.body.id);
+ expect(status.statusCode).toBe(200);
+ expect(status.body.model).toBe("spark-2");
+ expect(status.body.effort).toBe("low");
+
+ await cancel(response.body.id);
+ },
+ scrapeTimeout,
+ );
+
it(
"still uses the default model when the caller sends neither field",
async () => {
diff --git a/apps/api/src/controllers/v2/__tests__/agent-status.test.ts b/apps/api/src/controllers/v2/__tests__/agent-status.test.ts
index 1ab41e579..82b8456a4 100644
--- a/apps/api/src/controllers/v2/__tests__/agent-status.test.ts
+++ b/apps/api/src/controllers/v2/__tests__/agent-status.test.ts
@@ -140,18 +140,33 @@ describe("agentRequestSchema model and effort resolution", () => {
},
);
- it("rejects model and effort together, naming both fields", () => {
- let message = "";
- try {
- agentRequestSchema.parse({ ...base, model: "spark-2", effort: "low" });
- } catch (error) {
- message = (error as { issues: { message: string }[] }).issues[0].message;
- }
-
- expect(message).toContain("model");
- expect(message).toContain("effort");
+ it("accepts spark-2 with effort, keeping both", () => {
+ const parsed = agentRequestSchema.parse({
+ ...base,
+ model: "spark-2",
+ effort: "high",
+ });
+
+ expect(parsed.model).toBe("spark-2");
+ expect(parsed.effort).toBe("high");
});
+ it.each(["spark-1-pro", "spark-1-mini"] as const)(
+ "rejects effort with %s, naming spark-2",
+ model => {
+ let message = "";
+ try {
+ agentRequestSchema.parse({ ...base, model, effort: "low" });
+ } catch (error) {
+ message = (error as { issues: { message: string }[] }).issues[0]
+ .message;
+ }
+
+ expect(message).toContain("effort");
+ expect(message).toContain("spark-2");
+ },
+ );
+
it("falls back to the default model when the caller sends neither field", () => {
const parsed = agentRequestSchema.parse({ ...base });
diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.ts
index 0714db55a..d1f2e411c 100644
--- a/apps/api/src/controllers/v2/types.ts
+++ b/apps/api/src/controllers/v2/types.ts
@@ -1031,17 +1031,25 @@ export const agentRequestSchema = z
overrideWhitelist: z.string().optional(),
// Optional, not defaulted: the resolver below must tell "the caller sent a
- // model" apart from "the caller sent nothing", because sending both model
- // and effort is an error rather than a precedence rule.
+ // model" apart from "the caller sent nothing", because effort without a
+ // model resolves to spark-2 while effort against another preset is an
+ // error.
model: z.enum(["spark-1-pro", "spark-1-mini", "spark-2"]).optional(),
effort: z.enum(["low", "medium", "high"]).optional(),
threatProtection: threatProtectionOverrideSchema.optional(),
auditMetadata: auditMetadataSchema.optional(),
})
- .refine(x => !(x.model !== undefined && x.effort !== undefined), {
- error:
- "Send either 'model' or 'effort', not both. 'model' picks a preset and 'effort' picks a reasoning budget.",
- })
+ // spark-2 is the first model with a reasoning budget, so effort only pairs
+ // with spark-2. Effort against an older preset is rejected rather than
+ // silently upgrading the model the caller asked for.
+ .refine(
+ x =>
+ x.effort === undefined || x.model === undefined || x.model === "spark-2",
+ {
+ error:
+ "'effort' is only supported with model 'spark-2'. The spark-1 presets have no reasoning budget; omit 'model' or send 'spark-2' to set one.",
+ },
+ )
// Every effort level runs spark-2. The older presets have no trace or
// snapshot endpoint and use a different credit ladder, so spreading effort
// across presets would change features and price per level. Effort sets the
@@ -2214,18 +2222,15 @@ export const searchRequestSchema = z
x => !(x.includeDomains?.length && x.excludeDomains?.length),
"includeDomains and excludeDomains cannot both be specified",
)
- .refine(
- x => {
- const categories = x.categories ?? [];
- const hasDeveloper = categories.some(category =>
- typeof category === "string"
- ? category === "developer"
- : category.type === "developer",
- );
- return !hasDeveloper || categories.length === 1;
- },
- "the developer category cannot be combined with other categories",
- )
+ .refine(x => {
+ const categories = x.categories ?? [];
+ const hasDeveloper = categories.some(category =>
+ typeof category === "string"
+ ? category === "developer"
+ : category.type === "developer",
+ );
+ return !hasDeveloper || categories.length === 1;
+ }, "the developer category cannot be combined with other categories")
.refine(x => waitForRefine(x.scrapeOptions), waitForRefineOpts)
.transform(x => {
const country =