shaynhornik commented on code in PR #9244:
URL: https://github.com/apache/texera/pull/9244#discussion_r4458381204
##########
agent-service/src/agent/util/context-utils.ts:
##########
@@ -135,6 +136,29 @@ 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;
+ if (result.isError) {
Review Comment:
Fixed in 360e30fb3: an output starting with `[ERROR]` now gets the full
`Error:` block, with or without `isError`. Test 2 now uses a two-line execution
error (`[ERROR] Operator op8:` / `Input port 0 has no link`) and expects both
lines in the `Error:` block. The `(succeeded)`/`(failed)` label still comes
from `isError`, which #9120 is fixing.
##########
agent-service/src/agent/util/context-utils.ts:
##########
@@ -127,6 +127,7 @@ function serializeTask(steps: ReActStep[], status:
"completed" | "ongoing"): str
const tr = step.toolResults?.[i];
Review Comment:
Done, results are now matched by `toolCallId`. Added a test where the first
call has no result and the second call's output stays on the second call.
##########
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:
Good catch, the comment in the test now says this is a call the SDK
rejected. Recording those `tool-error` parts as failed results happens in
`onStepFinish`, the same place #9120 changes, so I'd rather not touch it here.
If @oliarmak-web isn't covering it in #9120, I'm happy to open a follow-up
issue and take it.
##########
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", () => {
Review Comment:
Agreed: the history never had these lines, so I've retitled the PR to
`feat`. That also means it shouldn't go to the release branches.
--
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]