Function: gptel--accept-tool-calls

gptel--accept-tool-calls is an interactive and natively compiled function defined in gptel.el.

Signature

(gptel--accept-tool-calls &optional TOOL-CALLS OV)

Documentation

Run pending tool-calls.

TOOL-CALLS is the edited tool call list, OV is the tool call dispatch overlay in the query buffer.

Key Bindings

gptel-tool-call-actions-map C-c C-c

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
(defun gptel--accept-tool-calls (&optional tool-calls ov)
  "Run pending tool-calls.

TOOL-CALLS is the edited tool call list, OV is the tool call dispatch
overlay in the query buffer."
  (interactive (pcase-let ((`(,resp . ,o) (get-char-property-and-overlay
                                           (point) 'gptel-tool)))
                 (list resp o)))
  (when (overlayp ov)                   ;Update UI indicator
    (with-current-buffer (overlay-buffer ov)
      (when gptel-mode
        (let ((names (cl-loop for call in tool-calls
                              collect (gptel-tool-name (car call)))))
          (gptel--update-status
           (concat
            (propertize
             (if (length> names 1) " Calling tools (" " Calling tool (")
             'face 'mode-line-emphasis)
            (mapconcat (lambda (name) (propertize name 'face 'font-lock-keyword-face))
                       names (propertize ", " 'face 'mode-line-emphasis))
            (propertize ")" 'face 'mode-line-emphasis)))))))
  ;; Clear the overlays first, because we need the buffer to be cleaned up
  ;; before inserting synchronous tool results.
  (when (and (overlayp ov) (overlay-buffer ov))
    (with-current-buffer (overlay-buffer ov)
      (when-let* ((preview-handles (overlay-get ov 'previews)))
        (dolist (func-to-handle preview-handles)
          (when (car func-to-handle) (apply func-to-handle))))
      (dolist (prompt-ov (overlay-get ov 'prompt))
        (when-let* (((overlay-buffer prompt-ov))
                    (inhibit-read-only t))
          (delete-region (overlay-start prompt-ov)
                         (overlay-end prompt-ov)))))
    (delete-overlay ov))
  (message "Continuing query...")
  (cl-loop for (tool-spec arg-plist process-tool-result) in tool-calls
           for arg-values = (gptel--map-tool-args tool-spec arg-plist)
           do
           (if (gptel-tool-async tool-spec)
               (apply (gptel-tool-function tool-spec)
                      process-tool-result arg-values)
             (let ((result
                    (condition-case errdata
                        (apply (gptel-tool-function tool-spec) arg-values)
                      (error (mapconcat #'gptel--to-string errdata " ")))))
               (funcall process-tool-result result)))))