kunwp1 commented on code in PR #9603:
URL: https://github.com/apache/texera/pull/9603#discussion_r4683339253
##########
agent-service/src/agent/texera-agent.spec.ts:
##########
@@ -906,6 +906,35 @@ describe("sendMessage", () => {
expect(agent.getAllSteps().map(s => s.stepId)).toEqual([0, 1, 2, 3]);
});
+ 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.
+ let n = 0;
+ const model = new MockLanguageModelV4({
+ doGenerate: async () => {
+ n++;
+ if (n > 200) throw new Error("runaway");
+ return {
+ content: [
+ {
+ type: "tool-call",
+ toolCallId: "c" + n,
+ toolName: "deleteOperator",
+ input: JSON.stringify({ operatorId: "ghost" }),
+ },
+ ],
+ finishReason: finish("tool-calls"),
+ usage: usage(1, 1),
+ warnings: [],
+ } as any;
+ },
+ });
+ const agent = makeAgentWith(model);
+ expect(agent.getSettings().maxSteps).toBe(25);
+ await agent.sendMessage("go");
+ expect(n).toBe(25);
+ });
Review Comment:
Optional: `toolCallingModel` in the "step limit notice" block above already
builds this model. Raise its runaway guard from 20 to 50, and this test fits in
that block in a few lines. It can also check the notice the user sees:
```ts
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"));
});
```
Checked locally at 69179ad:
- `bun test` in `agent-service` passes (358 tests), with `typecheck` and
`format:check` clean, both at the head and with the change above.
- With `server.ts` and `types/agent.ts` reverted to main, the three new
tests fail. With the default set back to 100, the version above fails too.
##########
agent-service/src/agent/texera-agent.spec.ts:
##########
@@ -906,6 +906,35 @@ describe("sendMessage", () => {
expect(agent.getAllSteps().map(s => s.stepId)).toEqual([0, 1, 2, 3]);
});
+ 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.
+ let n = 0;
+ const model = new MockLanguageModelV4({
+ doGenerate: async () => {
+ n++;
+ if (n > 200) throw new Error("runaway");
+ return {
+ content: [
+ {
+ type: "tool-call",
+ toolCallId: "c" + n,
+ toolName: "deleteOperator",
+ input: JSON.stringify({ operatorId: "ghost" }),
+ },
+ ],
+ finishReason: finish("tool-calls"),
+ usage: usage(1, 1),
+ warnings: [],
+ } as any;
+ },
+ });
+ const agent = makeAgentWith(model);
+ expect(agent.getSettings().maxSteps).toBe(25);
+ await agent.sendMessage("go");
+ expect(n).toBe(25);
+ });
Review Comment:
Optional: `toolCallingModel` in the "step limit notice" block above already
builds this model. Raise its runaway guard from 20 to 50, and this test fits in
that block in a few lines. It can also check the notice the user sees:
```ts
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"));
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]