Skip to content

Commit a17524a

Browse files
committed
feat: refactor debug payload extraction in sanitizeToolCallOutputForDebug function
1 parent b0d9ac4 commit a17524a

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

agent/toolCallEvents.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,37 @@ const TOOL_MESSAGE_DEBUG_KEYS = new Set([
2626
"response_metadata",
2727
]);
2828

29+
function getToolCallDebugPayload(outputRecord: Record<string, unknown>) {
30+
const lcKwargs =
31+
typeof outputRecord.lc_kwargs === "object" && outputRecord.lc_kwargs !== null
32+
? outputRecord.lc_kwargs as Record<string, unknown>
33+
: null;
34+
35+
if (lcKwargs && "tool_call_id" in lcKwargs) {
36+
return lcKwargs;
37+
}
38+
39+
if ("tool_call_id" in outputRecord) {
40+
return outputRecord;
41+
}
42+
43+
return null;
44+
}
45+
2946
function sanitizeToolCallOutputForDebug(output: unknown) {
3047
if (typeof output !== "object" || output === null) {
3148
return output;
3249
}
3350

3451
const outputRecord = output as Record<string, unknown>;
52+
const debugPayload = getToolCallDebugPayload(outputRecord);
3553

36-
if (!("tool_call_id" in outputRecord)) {
54+
if (!debugPayload) {
3755
return output;
3856
}
3957

4058
return Object.fromEntries(
41-
Object.entries(outputRecord).filter(([key]) => !TOOL_MESSAGE_DEBUG_KEYS.has(key)),
59+
Object.entries(debugPayload).filter(([key]) => !TOOL_MESSAGE_DEBUG_KEYS.has(key)),
4260
);
4361
}
4462

0 commit comments

Comments
 (0)