bobbai00 commented on code in PR #9259:
URL: https://github.com/apache/texera/pull/9259#discussion_r4619090216
##########
agent-service/src/agent/util/context-utils.ts:
##########
@@ -150,8 +150,7 @@ function serializeToolCallDetails(input: any, result: {
output: any; isError?: b
if (!result) return lines;
const text = typeof result.output === "string" ? result.output :
JSON.stringify(result.output);
if (text === undefined || text === "") return lines;
- // Tool errors come back as "[ERROR] ..." strings, so the marker counts as
well as isError.
- if (result.isError || text.startsWith("[ERROR]")) {
+ if (result.isError) {
Review Comment:
**Advisory:**
A rejected call's error quotes its whole input (`Text: <input>` if the reply
was cut off, `Value: <input>` if a field is missing). This branch keeps it
whole in [every later
prompt](https://github.com/apache/texera/blob/7cf765e6eab0ccac5c26e5c10b70a734c953b57e/agent-service/src/agent/util/context-utils.ts#L57-L80).
A 150-line UDF passed to `addOperator` gave 5.5 KB (cut off) or 6.2 KB (no
`summary`) per prompt, and the reason is the last line. I'd cap a long error
here to its first line and last ~1,000 characters; the stored step keeps the
full text. I missed this in round 2; fine as a follow-up.
##########
agent-service/src/agent/texera-agent.spec.ts:
##########
@@ -583,14 +584,97 @@ describe("sendMessage", () => {
return { ok: true, json: async () => ({ operatorOutputSchemas: {},
operatorErrors: {} }) } as any;
}) as any);
await agent.sendMessage("del");
- const counts = agent
- .getAllSteps()
- .map(s => [s.role, s.beforeWorkflowContent?.operators.length,
s.afterWorkflowContent?.operators.length]);
+ const steps = agent.getAllSteps();
+ const counts = steps.map(s => [
+ s.role,
+ s.beforeWorkflowContent?.operators.length,
+ s.afterWorkflowContent?.operators.length,
+ ]);
expect(counts).toEqual([
["user", 1, 1],
["agent", 1, 0],
["agent", 0, 0],
]);
+ expect(steps[1].toolResults).toEqual([{ toolCallId: "c1", output: "Deleted
operator: op1", isError: false }]);
+ expect(steps[2].inputMessages?.[0]?.content).toContain("- deleteOperator
(succeeded)");
+ });
+
+ test.each([new Error("The operation was aborted."), "tool failed", null])(
+ "preserves a thrown tool error in stored JSON and subsequent context: %p",
Review Comment:
**Polish:**
Bun's `%p` prints an `Error` with its code frame and stack, so the first
case's name is about 10 lines of this file plus its absolute path. CI uploads
test names to Codecov Test Analytics
([build.yml:1298](https://github.com/apache/texera/blob/fddc4303e8f739fe2a9e707a5d176e5032191753/.github/workflows/build.yml#L1298)),
so this one would change with any edit near line 600. Labeled cases read `...:
Error` / `string` / `null`. This shape passed prettier (after `bun run
format`), typecheck and the file's 67 tests:
```ts
test.each([
["Error", new Error("The operation was aborted.")],
["string", "tool failed"],
["null", null],
])("preserves a thrown tool error in stored JSON and subsequent context:
%s", async (_kind, thrown) => {
```
--
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]