timeoutSeconds = $this->timeoutSeconds ?? (int) config('agent.tools.timeout_seconds', 15); $this->maxResultBytes = $this->maxResultBytes ?? (int) config('agent.tools.result_max_bytes', 4096); } public function execute(ToolCall $call): ToolResult { $tool = $this->registry->get($call->name); if (! $tool) { return new ToolResult( $call->runId, $call->parentRunId, $call->toolCallId, $call->name, 'FAILED', '', 'TOOL_NOT_FOUND' ); } $started = microtime(true); try { $result = $tool->execute($call->arguments); $output = is_string($result) ? $result : json_encode($result, JSON_UNESCAPED_UNICODE); } catch (\Throwable $exception) { return new ToolResult( $call->runId, $call->parentRunId, $call->toolCallId, $call->name, 'FAILED', '', Str::limit($exception->getMessage(), 200) ); } $duration = microtime(true) - $started; $truncated = false; if ($this->maxResultBytes > 0 && strlen($output) > $this->maxResultBytes) { $output = substr($output, 0, $this->maxResultBytes); $truncated = true; } if ($this->timeoutSeconds > 0 && $duration > $this->timeoutSeconds) { return new ToolResult( $call->runId, $call->parentRunId, $call->toolCallId, $call->name, 'TIMEOUT', $output, 'TOOL_TIMEOUT', $truncated ); } return new ToolResult( $call->runId, $call->parentRunId, $call->toolCallId, $call->name, 'SUCCESS', $output, null, $truncated ); } }