fix(data): propagate errors so is_error is set correctly in run-log
Previously the data tool caught all errors and returned them as normal tool results with error info in the JSON content. This meant pi-agent-core never saw an exception and always set isError=false in the run-log, even for rate limit errors (errCode 9001) and other API failures. Now errors propagate to pi-agent-core which sets isError=true and formats the error message for the LLM automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
486b090577
commit
357bf326e0
1 changed files with 12 additions and 28 deletions
|
|
@ -83,36 +83,20 @@ export function createDataTool(): AgentTool<typeof DataToolSchema, DataToolResul
|
|||
const { domain, action, params } = args as DataToolArgs;
|
||||
|
||||
if (domain !== "finance") {
|
||||
const errorPayload = {
|
||||
error: true,
|
||||
message: `Unknown domain: "${domain}". Currently supported: "finance".`,
|
||||
};
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(errorPayload, null, 2) }],
|
||||
details: { domain, action, data: null } as unknown as DataToolResult,
|
||||
};
|
||||
throw new Error(`Unknown domain: "${domain}". Currently supported: "finance".`);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await executeFinanceAction(action, params ?? {}, signal);
|
||||
const payload: DataToolResult = {
|
||||
domain,
|
||||
action,
|
||||
data: result.data,
|
||||
sourceUrl: result.sourceUrl,
|
||||
};
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
|
||||
details: payload,
|
||||
};
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const errorPayload = { error: true, domain, action, message };
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(errorPayload, null, 2) }],
|
||||
details: { domain, action, data: null } as unknown as DataToolResult,
|
||||
};
|
||||
}
|
||||
const result = await executeFinanceAction(action, params ?? {}, signal);
|
||||
const payload: DataToolResult = {
|
||||
domain,
|
||||
action,
|
||||
data: result.data,
|
||||
sourceUrl: result.sourceUrl,
|
||||
};
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
|
||||
details: payload,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue