bobbai00 commented on code in PR #9259:
URL: https://github.com/apache/texera/pull/9259#discussion_r4596023881
##########
agent-service/src/agent/texera-agent.ts:
##########
@@ -596,11 +597,14 @@ export class TexeraAgent {
input: tc.input,
}));
- const formattedToolResults = toolResults?.map(tr => ({
- toolCallId: tr.toolCallId,
- output: tr.output,
- isError: !!(tr.output as any)?.error,
- }));
+ const formattedToolResults = content
+ .filter(part => part.type === "tool-result" || part.type ===
"tool-error")
+ .map(part => ({
+ toolCallId: part.toolCallId,
+ output: part.type === "tool-error" ? part.error : part.output,
Review Comment:
**Must fix:**
When a tool's `execute` throws, `part.error` is the thrown `Error` itself.
JSON turns that into `{}`, both in
[`serializeToolCallDetails`](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/util/context-utils.ts#L151)
and in the WebSocket snapshot. Pressing Stop while `executeOperator` runs in
delegate mode does this (the AbortError is rethrown at
[workflow-execution-tools.ts:471](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/tools/workflow-execution-tools.ts#L471)),
and the next turn shows `Error: {}`. Store the message as
[server.ts:162](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/server.ts#L162)
does, and add a test with a throwing tool.
```suggestion
output:
part.type === "tool-error"
? part.error instanceof Error
? part.error.message
: String(part.error)
: part.output,
```
##########
agent-service/src/agent/util/context-utils.ts:
##########
@@ -122,9 +122,9 @@ function serializeTask(steps: ReActStep[], status:
"completed" | "ongoing"): str
lines.push(`Thought: ${step.content}`);
}
if (step.toolCalls && step.toolCalls.length > 0) {
- for (let i = 0; i < step.toolCalls.length; i++) {
- const tc = step.toolCalls[i];
- const tr = step.toolResults?.find(r => r.toolCallId === tc.toolCallId);
+ const toolResultsByCallId = new Map(step.toolResults?.map(result =>
[result.toolCallId, result]));
+ for (const tc of step.toolCalls) {
+ const tr = toolResultsByCallId.get(tc.toolCallId);
Review Comment:
**Advisory:**
After this fix, a call with no result here is one the SDK never ran: a
complete tool call under a finish reason other than `stop` or `tool-calls`
(reproduced with `length`). Line 128 still labels it `(succeeded)`, but
[texera-agent.ts:646](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/texera-agent.ts#L646)
now treats a missing result as not succeeded. I'd label it `(failed)` so the
model retries it. The comments at
[context-utils.spec.ts:167](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/util/context-utils.spec.ts#L167)
and
[:191](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/util/context-utils.spec.ts#L191)
also still say a rejected call has no result.
##########
agent-service/src/agent/texera-agent.ts:
##########
@@ -596,11 +597,14 @@ export class TexeraAgent {
input: tc.input,
}));
- const formattedToolResults = toolResults?.map(tr => ({
- toolCallId: tr.toolCallId,
- output: tr.output,
- isError: !!(tr.output as any)?.error,
- }));
+ const formattedToolResults = content
+ .filter(part => part.type === "tool-result" || part.type ===
"tool-error")
+ .map(part => ({
+ toolCallId: part.toolCallId,
+ output: part.type === "tool-error" ? part.error : part.output,
+ isError: part.type === "tool-error" ||
isErrorResult(part.output),
Review Comment:
**Advisory:**
This line now sets `isError` for every error result, so the `[ERROR]`
fallback at
[context-utils.ts:153-154](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/util/context-utils.ts#L153-L154)
can't change anything. Its test
([context-utils.spec.ts:175-187](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/util/context-utils.spec.ts#L175-L187))
pins a shape nothing produces, and its comment says isError "is not set for
them yet (#9120)". Drop both, so `isErrorResult` stays the one rule.
##########
agent-service/src/agent/texera-agent.spec.ts:
##########
@@ -1154,7 +1160,9 @@ describe("delegate mode", () => {
agent.setDelegateConfig({ userToken: "tok", workflowId: 7 });
await agent.sendMessage("bad call");
const step = agent.getAllSteps()[1];
- expect(step.toolResults).toEqual([]);
+ expect(step.toolResults).toHaveLength(1);
Review Comment:
**Polish:**
This test's name ([line
1136](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/texera-agent.spec.ts#L1136))
describes the `operatorId` guard at
[texera-agent.ts:649](https://github.com/apache/texera/blob/a35e1ab924c2640583381bff6afbe329ce7f0931/agent-service/src/agent/texera-agent.ts#L649).
But `{}` now fails the SDK's input check, so the skip at line 646 returns
first and the guard is never reached. Rename it for what it now checks, e.g.
"an SDK-rejected modifyOperator is recorded as failed and does not run".
--
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]