Implement background process monitoring and inspection tools (#23799)

This commit is contained in:
Coco Sheng
2026-04-02 11:01:00 -04:00
committed by GitHub
parent 18e20c8650
commit daddac16e3
13 changed files with 1181 additions and 12 deletions
+27 -2
View File
@@ -65,6 +65,7 @@ export interface ShellToolParams {
description?: string;
dir_path?: string;
is_background?: boolean;
delay_ms?: number;
[PARAM_ADDITIONAL_PERMISSIONS]?: SandboxPermissions;
}
@@ -521,6 +522,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
this.context.config.getEnableInteractiveShell(),
{
...shellExecutionConfig,
sessionId: this.context.config?.getSessionId?.() ?? 'default',
pager: 'cat',
sanitizationConfig:
shellExecutionConfig?.sanitizationConfig ??
@@ -547,6 +549,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
},
backgroundCompletionBehavior:
this.context.config.getShellBackgroundCompletionBehavior(),
originalCommand: strippedCommand,
},
);
@@ -556,10 +559,32 @@ export class ShellToolInvocation extends BaseToolInvocation<
}
// If the model requested to run in the background, do so after a short delay.
let completed = false;
if (this.params.is_background) {
resultPromise
.then(() => {
completed = true;
})
.catch(() => {
completed = true; // Also mark completed if it failed
});
const sessionId = this.context.config?.getSessionId?.() ?? 'default';
const delay = this.params.delay_ms ?? BACKGROUND_DELAY_MS;
setTimeout(() => {
ShellExecutionService.background(pid);
}, BACKGROUND_DELAY_MS);
ShellExecutionService.background(pid, sessionId, strippedCommand);
}, delay);
// Wait for the delay amount to see if command returns quickly
await new Promise((resolve) => setTimeout(resolve, delay));
if (!completed) {
// Return early with initial output if still running
return {
llmContent: `Command is running in background. PID: ${pid}. Initial output:\n${cumulativeOutput}`,
returnDisplay: `Background process started with PID ${pid}.`,
};
}
}
}