bobbai00 commented on code in PR #9244:
URL: https://github.com/apache/texera/pull/9244#discussion_r4577594937


##########
agent-service/src/agent/util/context-utils.ts:
##########
@@ -135,6 +136,30 @@ function serializeTask(steps: ReActStep[], status: 
"completed" | "ongoing"): str
   return lines.join("\n").trimEnd();
 }
 
+/**
+ * The `Summary` / `Output` / `Error` lines under a past tool call, in the 
layout the system prompt
+ * describes. Output keeps only its first line: an operator's data is already 
in the dataflow
+ * section, and the first line is the tool's one-line result. An error is kept 
whole, since it is
+ * what the model needs to avoid repeating the call.
+ */
+function serializeToolCallDetails(input: any, result: { output: any; isError?: 
boolean } | undefined): string[] {
+  const lines: string[] = [];
+  if (typeof input?.summary === "string" && input.summary) {
+    lines.push(`  - Summary: ${input.summary}`);
+  }
+  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]")) {

Review Comment:
   **Advisory:**
   
   The PR description predates this line. It says an unflagged `[ERROR]` result 
reaches the model "through its `Output:` line" until #9120 lands, and says the 
same of test 2. This line now gives that result the full `Error:` block. The 
body becomes the default squash commit message, so please update those 
passages, list the id-matching test, and say the no-result call is one the SDK 
rejected.



##########
agent-service/src/agent/util/context-utils.spec.ts:
##########
@@ -133,6 +133,57 @@ describe("assembleContext", () => {
     expect(content).toContain("- executeOperator (failed)");
     expect(content).toContain("- deleteOperator (succeeded)");
   });
+
+  test("writes each past call's summary and result under it, so a failed call 
is not repeated blindly", () => {
+    const agentStep: ReActStep = {
+      ...step("m1", "agent", 1, "acting", true),
+      toolCalls: [
+        { toolName: "addOperator", toolCallId: "c1", input: { operatorId: 
"op1", summary: "Load CSV data" } },
+        { toolName: "executeOperator", toolCallId: "c2", input: { operatorId: 
"op1" } },
+        { toolName: "modifyOperator", toolCallId: "c3", input: { operatorId: 
"op1", summary: "Link op7" } },
+        { toolName: "deleteOperator", toolCallId: "c4", input: { operatorId: 
"op1" } },
+      ],
+      toolResults: [
+        { toolCallId: "c1", output: "Added operator op1, input ports: 0, 
output ports: 1" },
+        { toolCallId: "c2", output: "Executed operator op1\nOutput(table 
shape): (3, 2)\n| a | b |" },
+        { toolCallId: "c3", output: '[ERROR] Source operator "op7" not found\n 
 at resolveInputLinks', isError: true },
+      ],
+    };
+    const content = contentOf(
+      assembleContext([step("m1", "user", 0, "req", true), agentStep], new 
WorkflowState(), new Map())
+    );
+    expect(content).toContain(
+      [
+        "- addOperator (succeeded)",
+        "  - Summary: Load CSV data",
+        "  - Output: Added operator op1, input ports: 0, output ports: 1",
+        "- executeOperator (succeeded)",
+        "  - Output: Executed operator op1",
+        "- modifyOperator (failed)",
+        "  - Summary: Link op7",
+        "  - Error:",
+        '    [ERROR] Source operator "op7" not found',
+        "      at resolveInputLinks",
+        // No result yet: only the call itself.

Review Comment:
   Verified: #9259 (the #9120 fix) records `tool-error` parts as failed 
results, and for schema-invalid input the SDK stores the error as a string, so 
these calls will show as failed with their message once it lands. No follow-up 
issue needed.



-- 
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]

Reply via email to