This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/main by this push:
new 6eab74829f feat(agent-service): lower the default step limit to 25 and
cap it at 50 (#9603)
6eab74829f is described below
commit 6eab74829f6074da64ca36bc45db050d4b434597
Author: Jiadong Bai <[email protected]>
AuthorDate: Wed Nov 25 08:49:18 2026 +0000
feat(agent-service): lower the default step limit to 25 and cap it at 50
(#9603)
### What changes were proposed in this PR?
Lowers the agent's default limit on model calls (steps) per message from
100 to 25 (`maxSteps` in `agent-service/src/types/agent.ts`). It also
caps the limit at 50, the settings dialog's maximum, so a request sent
straight to the API can no longer go past it
(`agent-service/src/server.ts`). A looping agent stops only at this
limit, so a runaway turn now costs a quarter of the calls. 25 is about
twice the largest of 60 measured turns (13 model calls, median 3), so
ordinary turns are not cut. Users can still raise it per agent in the
settings, up to 50.
### Any related issues, documentation, discussions?
Closes #9602
Part of #9576
### How was this PR tested?
`bun test` in `agent-service`. A new test drives a model that never
stops calling tools, without setting `maxSteps`, and expects the turn to
stop after 25 calls. Two route tests send a limit of 51: the creation
test expects a 400 and no new agent, and the settings test expects a 400
and an unchanged limit. Both accept 50. All three fail on `main`.
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Fable 5.2, Claude Opus 5.5)
---
agent-service/src/agent/texera-agent.spec.ts | 13 ++++++++++++-
agent-service/src/server.spec.ts | 22 ++++++++++++++++++++++
agent-service/src/server.ts | 6 +++---
agent-service/src/types/agent.ts | 10 +++++++++-
4 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/agent-service/src/agent/texera-agent.spec.ts
b/agent-service/src/agent/texera-agent.spec.ts
index 0ccb784496..f3eee77e83 100644
--- a/agent-service/src/agent/texera-agent.spec.ts
+++ b/agent-service/src/agent/texera-agent.spec.ts
@@ -767,7 +767,7 @@ describe("sendMessage", () => {
return new MockLanguageModelV4({
doGenerate: async () => {
n++;
- if (n > 20) throw new Error("runaway");
+ if (n > 50) throw new Error("runaway");
options.onCall?.(n);
const callsTool = n <= toolCalls;
return {
@@ -815,6 +815,17 @@ describe("sendMessage", () => {
expect(agent.getState()).toBe(AgentState.AVAILABLE);
});
+ test("stops a looping model at the default step limit", async () => {
+ // Nothing sets maxSteps here, so the default is all that bounds a model
that never stops
+ // calling tools.
+ const model = toolCallingModel(Infinity);
+ const agent = makeAgentWith(model);
+ expect(agent.getSettings().maxSteps).toBe(25);
+ await agent.sendMessage("go");
+ expect(model.doGenerateCalls).toHaveLength(25);
+ expect(agent.getAllSteps().at(-1)?.content).toBe(notice("25 steps"));
+ });
+
test("adds nothing when the model answers on the last allowed step", async
() => {
const agent = makeAgentWith(toolCallingModel(2));
agent.updateSettings({ maxSteps: 3 });
diff --git a/agent-service/src/server.spec.ts b/agent-service/src/server.spec.ts
index be66e4f3f3..9ae96fcd52 100644
--- a/agent-service/src/server.spec.ts
+++ b/agent-service/src/server.spec.ts
@@ -332,6 +332,19 @@ describe(`PATCH ${API}/agents/:id/settings`, () => {
expect(reread.maxSteps).toBe(7);
expect(reread.toolTimeoutSeconds).toBe(30);
});
+
+ test("refuses a step limit above 50, the settings dialog's maximum", async
() => {
+ const created = await readJson<{ id: string }>(await createAgent());
+ const settingsPath = `${API}/agents/${created.id}/settings`;
+ const readMaxSteps = async () => (await readJson<{ maxSteps: number
}>(await getJson(settingsPath))).maxSteps;
+ const before = await readMaxSteps();
+
+ expect((await patchJson(settingsPath, { maxSteps: 51 })).status).toBe(400);
+ expect(await readMaxSteps()).toBe(before);
+
+ expect((await patchJson(settingsPath, { maxSteps: 50 })).status).toBe(200);
+ expect(await readMaxSteps()).toBe(50);
+ });
});
describe("agent creation edge cases", () => {
@@ -350,6 +363,15 @@ describe("agent creation edge cases", () => {
expect(body.settings.toolTimeoutSeconds).toBe(12);
});
+ test("refuses an initial step limit above 50 without creating the agent",
async () => {
+ expect((await createAgent({ settings: { maxSteps: 51 }
})).status).toBe(400);
+ expect((await readJson<{ agents: unknown[] }>(await
getJson(`${API}/agents`))).agents).toHaveLength(0);
+
+ const res = await createAgent({ settings: { maxSteps: 50 } });
+ expect(res.status).toBe(200);
+ expect((await readJson<{ settings: { maxSteps: number }
}>(res)).settings.maxSteps).toBe(50);
+ });
+
test("creates the agent even when the workflow load fails (non-fatal)",
async () => {
// retrieveWorkflow targets the (unavailable) dashboard service; the
failure
// is caught and the agent is still created.
diff --git a/agent-service/src/server.ts b/agent-service/src/server.ts
index 1ce80c955a..52ac7783fb 100644
--- a/agent-service/src/server.ts
+++ b/agent-service/src/server.ts
@@ -39,7 +39,7 @@ import type {
ReActStep,
UserInfo,
} from "./types/agent";
-import { AgentState, OperatorResultSerializationMode } from "./types/agent";
+import { AgentState, MAX_STEPS_LIMIT, OperatorResultSerializationMode } from
"./types/agent";
import type { WsClientCommand, WsServerEvent } from "./types/ws";
import { WsServerSnapshotEvent, WsServerStepEvent, WsServerStatusEvent,
WsServerErrorEvent } from "./types/ws";
import type { OperatorExecutionSummary } from "./types/execution";
@@ -260,7 +260,7 @@ const agentsRouter = new Elysia({ prefix: "/agents" })
toolTimeoutSeconds: t.Optional(t.Number()),
executionTimeoutMinutes: t.Optional(t.Number()),
disabledTools: t.Optional(t.Array(t.String())),
- maxSteps: t.Optional(t.Integer({ minimum: 1 })),
+ maxSteps: t.Optional(t.Integer({ minimum: 1, maximum:
MAX_STEPS_LIMIT })),
allowedOperatorTypes: t.Optional(t.Array(t.String())),
})
),
@@ -396,7 +396,7 @@ const agentsRouter = new Elysia({ prefix: "/agents" })
operatorResultSerializationMode: t.Optional(t.Literal("tsv")),
toolTimeoutSeconds: t.Optional(t.Number()),
executionTimeoutMinutes: t.Optional(t.Number()),
- maxSteps: t.Optional(t.Integer({ minimum: 1 })),
+ maxSteps: t.Optional(t.Integer({ minimum: 1, maximum: MAX_STEPS_LIMIT
})),
disabledTools: t.Optional(t.Array(t.String())),
allowedOperatorTypes: t.Optional(t.Array(t.String())),
}),
diff --git a/agent-service/src/types/agent.ts b/agent-service/src/types/agent.ts
index 89bf75aa40..a872a98128 100644
--- a/agent-service/src/types/agent.ts
+++ b/agent-service/src/types/agent.ts
@@ -78,6 +78,12 @@ export interface AgentSettings {
allowedOperatorTypes: string[];
}
+/**
+ * The highest step limit the API accepts, the same as the settings dialog's
maximum. A looping
+ * agent stops only at its step limit, so this bounds what one message can
cost.
+ */
+export const MAX_STEPS_LIMIT = 50;
+
export const DEFAULT_AGENT_SETTINGS: Omit<AgentSettings, "systemPrompt"> = {
disabledTools: new Set(),
maxOperatorResultCharLimit: 2000,
@@ -85,7 +91,9 @@ export const DEFAULT_AGENT_SETTINGS: Omit<AgentSettings,
"systemPrompt"> = {
operatorResultSerializationMode: OperatorResultSerializationMode.TSV,
toolTimeoutMs: 240000,
executionTimeoutMs: 240000,
- maxSteps: 100,
+ // Model calls allowed per user message. Real turns take about 3 and the
largest measured took
+ // 13, while a looping agent stops only at this limit, so it stays close to
real use.
+ maxSteps: 25,
allowedOperatorTypes: [
"CSVFileScan",
"Filter",