$toolCall */ public function __construct(public string $sessionId, public array $toolCall) { $this->tries = (int) config('agent.tools.job.tries', 1); $this->timeout = (int) config('agent.tools.job.timeout_seconds', 60); $this->backoff = (int) config('agent.tools.job.backoff_seconds', 3); } public function handle(ToolExecutor $executor, OutputSink $sink, CancelChecker $cancelChecker): void { $call = ToolCall::fromArray($this->toolCall); logger('ToolRunJob call:', $call->toArray()); if ($cancelChecker->isCanceled($this->sessionId, $call->parentRunId)) { $sink->appendRunStatus($this->sessionId, $call->runId, 'CANCELED', [ 'dedupe_key' => "run:{$call->runId}:status:CANCELED", 'parent_run_id' => $call->parentRunId, ]); return; } try { $result = $executor->execute($call); $sink->appendToolResult($this->sessionId, $result); $status = $result->status === 'SUCCESS' ? 'DONE' : 'FAILED'; $sink->appendRunStatus($this->sessionId, $call->runId, $status, [ 'parent_run_id' => $call->parentRunId, 'tool_call_id' => $call->toolCallId, 'dedupe_key' => "run:{$call->runId}:status:{$status}", 'error' => $result->error, ]); } catch (\Throwable $exception) { $sink->appendRunStatus($this->sessionId, $call->runId, 'FAILED', [ 'parent_run_id' => $call->parentRunId, 'tool_call_id' => $call->toolCallId, 'dedupe_key' => "run:{$call->runId}:status:FAILED", 'error' => $exception->getMessage(), ]); throw $exception; } } }