Skip to content

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

feat(agent): allow exchange on zero data retention /v2/agent runs (#5317)

Rakshith Ramprakash16b3b8359797
diff --git a/apps/api/src/controllers/v2/__tests__/agent-zdr.test.ts b/apps/api/src/controllers/v2/__tests__/agent-zdr.test.ts
index 0dd0e5c9b..b55639508 100644
--- a/apps/api/src/controllers/v2/__tests__/agent-zdr.test.ts
+++ b/apps/api/src/controllers/v2/__tests__/agent-zdr.test.ts
@@ -176,9 +176,37 @@ describe("agentController zero data retention", () => {
expect(logRequest).not.toHaveBeenCalled();
});
- it("rejects exchange options under ZDR", async () => {
+ it.each([
+ [
+ "opted in",
+ { zeroDataRetention: true },
+ { scrapeZDR: "allowed", searchZDR: "allowed" },
+ ],
+ ["forced", {}, { scrapeZDR: "forced", searchZDR: "forced-zdr" }],
+ ])(
+ "forwards exchange options with the ZDR flag when %s",
+ async (_name, body, flags) => {
+ const exchange = { enabled: true, toolkits: ["fred"], maxCalls: 4 };
+ const res = await run({ ...body, exchange }, flags);
+
+ expect(res.status).toHaveBeenCalledWith(200);
+ expect(forwardedBody()).toMatchObject({
+ exchange,
+ zeroDataRetention: true,
+ });
+ expect(logRequest).toHaveBeenCalledWith(
+ expect.objectContaining({ zeroDataRetention: true }),
+ );
+ },
+ );
+
+ it("rejects a thread follow-up under ZDR even when it asks for exchange", async () => {
const res = await run(
- { zeroDataRetention: true, exchange: { enabled: true } },
+ {
+ zeroDataRetention: true,
+ threadId: "0190e3c8-4b2a-7c3d-8e9f-0a1b2c3d4e5f",
+ exchange: { enabled: true },
+ },
{ scrapeZDR: "allowed", searchZDR: "allowed" },
);
@@ -186,11 +214,19 @@ describe("agentController zero data retention", () => {
expect(res.json).toHaveBeenCalledWith(
expect.objectContaining({
success: false,
- code: "zdr_exchange_unsupported",
+ code: "zdr_threads_unsupported",
}),
);
expect(fetch).not.toHaveBeenCalled();
- expect(logRequest).not.toHaveBeenCalled();
+ });
+
+ it("forwards exchange options unchanged without ZDR", async () => {
+ const exchange = { enabled: true };
+ const res = await run({ exchange }, {});
+
+ expect(res.status).toHaveBeenCalledWith(200);
+ expect(forwardedBody().exchange).toEqual(exchange);
+ expect(forwardedBody()).not.toHaveProperty("zeroDataRetention");
});
it("marks rejected threat events as ZDR", async () => {
diff --git a/apps/api/src/controllers/v2/agent.ts b/apps/api/src/controllers/v2/agent.ts
index 7ba757931..7f3ebf66a 100644
--- a/apps/api/src/controllers/v2/agent.ts
+++ b/apps/api/src/controllers/v2/agent.ts
@@ -79,15 +79,6 @@ export async function agentController(
});
}
- if (zeroDataRetention && req.body.exchange) {
- return res.status(400).json({
- success: false,
- code: "zdr_exchange_unsupported",
- error:
- "Exchange is not supported with zero data retention. Remove the exchange option.",
- });
- }
-
logger.info("Agent starting...", {
request: req.body,
originalRequest,
diff --git a/apps/api/src/lib/error-serde.ts b/apps/api/src/lib/error-serde.ts
index b357505ff..7ecc8d535 100644
--- a/apps/api/src/lib/error-serde.ts
+++ b/apps/api/src/lib/error-serde.ts
@@ -116,7 +116,6 @@ const errorMap: Record<ErrorCodes, any> = {
// Agent zero data retention rejections are API-level too.
zdr_threads_unsupported: null,
- zdr_exchange_unsupported: null,
zdr_expired: null,
zdr_no_snapshots: null,
zdr_not_enabled: null,
diff --git a/apps/api/src/lib/error.ts b/apps/api/src/lib/error.ts
index e6b2771f6..9a2ba91f9 100644
--- a/apps/api/src/lib/error.ts
+++ b/apps/api/src/lib/error.ts
@@ -63,7 +63,6 @@ export type ErrorCodes =
| "exchange_not_enabled"
// Agent zero data retention. Lowercase to match the agent service's codes.
| "zdr_threads_unsupported"
- | "zdr_exchange_unsupported"
| "zdr_expired"
| "zdr_no_snapshots"
| "zdr_not_enabled";