bobbai00 commented on code in PR #9244:
URL: https://github.com/apache/texera/pull/9244#discussion_r4446620951
##########
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:
**Advisory:**
About the PR title. [AGENTS.md's type
table](https://github.com/apache/texera/blob/main/AGENTS.md#branch-and-commit-naming)
says "implementing something that was never actually there is a `feat`".
`serializeTask` has written only the call name and status since #4495; only the
system prompt promised these lines. By that table the title reads as
`feat(agent-service): show past tool results in the agent's history`. The type
also decides backports: the bot queued release/v1.3 and release/v1.2 because of
`fix:`, so keep `fix` only if those branches should get this.
##########
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:
**Must fix:**
`isError` stays false until #9120 lands
([texera-agent.ts:594](https://github.com/apache/texera/blob/bb28d6423f38a1c28bccfacd115c55b63d3e2ba2/agent-service/src/agent/texera-agent.ts#L594)),
so every failure takes the first-line `Output:` path. `executeOperator` errors
span several lines. On an operator with no input link, the history shows only
`Output: [ERROR] Operator op8:`, and the reason
([workflow-execution-tools.ts:452-456](https://github.com/apache/texera/blob/bb28d6423f38a1c28bccfacd115c55b63d3e2ba2/agent-service/src/agent/tools/workflow-execution-tools.ts#L452-L456))
appears nowhere else in the prompt. Checking the `[ERROR]` marker here, as
`serializeOperator` does at line 250, keeps the whole message and still holds
after #9120. Test 2 then expects the `Error:` block.
```suggestion
if (result.isError || text.startsWith("[ERROR]")) {
```
##########
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:
**Advisory:**
This case is not "no result yet". `prepareStep` runs after the previous
step's tools finish. So a call without a result is one the AI SDK rejected:
schema-invalid input such as `addOperator` without `summary`, or a throwing
execute. `onStepFinish` drops those `tool-error` parts
([texera-agent.ts:591-595](https://github.com/apache/texera/blob/bb28d6423f38a1c28bccfacd115c55b63d3e2ba2/agent-service/src/agent/texera-agent.ts#L591-L595)),
so the call reads `(succeeded)` with no reason, and the #9119 loop survives
for it. Should they be recorded as failed results, here or with #9120, or
tracked in a follow-up?
##########
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:
**Advisory:**
`step.toolResults` has no entry for a call the SDK rejected, so matching by
position can hand a rejected call the next call's result, and the new lines
would print it there. Steps carry one call today
([texera-agent.ts:578](https://github.com/apache/texera/blob/bb28d6423f38a1c28bccfacd115c55b63d3e2ba2/agent-service/src/agent/texera-agent.ts#L578)
disables parallel calls), so this is hardening. Matching by id, as
`getOperatorIdsFromStep` does
([texera-agent.ts:785](https://github.com/apache/texera/blob/bb28d6423f38a1c28bccfacd115c55b63d3e2ba2/agent-service/src/agent/texera-agent.ts#L785)),
removes the dependency.
```suggestion
const tr = step.toolResults?.find(r => r.toolCallId ===
tc.toolCallId);
```
--
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]