Function: gptel--inspect-tool-calls
gptel--inspect-tool-calls is an interactive and natively compiled
function defined in gptel.el.
Signature
(gptel--inspect-tool-calls TOOL-CALLS INFO &optional TOOL-OVERLAY)
Documentation
Set up and switch to a buffer to inspect pending tool-calls.
TOOL-CALLS is the alist of tool calls. INFO is the request context plist. TOOL-OVERLAY is the tool call dispatch overlay (if any) in the query buffer.
Key Bindings
gptel-tool-call-actions-map C-c TAB
Source Code
;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
(defun gptel--inspect-tool-calls (tool-calls info &optional tool-overlay)
"Set up and switch to a buffer to inspect pending tool-calls.
TOOL-CALLS is the alist of tool calls. INFO is the request context
plist. TOOL-OVERLAY is the tool call dispatch overlay (if any) in the
query buffer."
(interactive (pcase-let ((`(,resp . ,o) (get-char-property-and-overlay
(point) 'gptel-tool)))
(list resp (overlay-get o 'info) o)))
(with-current-buffer (get-buffer-create "*gptel-tool-calls*")
(let ((inhibit-read-only t)
(tool-use (plist-get info :tool-use)))
(remove-overlays)
(erase-buffer)
(unless (derived-mode-p 'lisp-data-mode)
(lisp-data-mode)
(add-hook 'post-command-hook #'gptel--inspect-tool-post-command nil t))
;; NOTE: This needs to be called after setting the major mode, as
;; buffer-local variables are wiped out.
;; Required to store state for accepting/rejecting calls
(setq gptel--fsm-last (gptel-make-fsm :info info))
(plist-put info :tool-display (list tool-calls tool-overlay)) ;NOTE: INFO is never nil
(insert ";; Inspect or edit tool calls.
;; Adding or deleting tool calls is not supported.\n\n")
(cl-loop for tool-spec-args-cb in tool-calls
for (tool-spec arg-plist _process-tool-result) = tool-spec-args-cb
with o
for name = (gptel-tool-name tool-spec)
for pt = (point)
for index =
(cl-position-if
(lambda (call) (and (not (plist-get call :result))
(string= (plist-get call :name) name)
(null (cl-set-difference
(plist-get call :args) arg-plist
:test #'equal))))
tool-use)
do (prin1 (list :name name :args arg-plist)
(current-buffer) '((length . nil) (level . nil)))
(insert "\n\n") ;Avoid extending the overlay
(setq o (make-overlay pt (- (point) 2) nil nil t))
(overlay-put o 'gptel-tool tool-spec-args-cb)
(overlay-put o 'gptel-overlay index))
(goto-char (point-min)) (forward-line 3))
(use-local-map
(make-composed-keymap
gptel-tool-call-inspection-map (current-local-map)))
(unless header-line-format
(setq header-line-format
(substitute-command-keys
(concat
(propertize "Tool calls" 'face 'font-lock-string-face) ": "
(buttonize "Confirm" #'gptel--inspect-accept-tool-calls)
" \\[gptel--inspect-accept-tool-calls], "
(buttonize "Cancel" #'gptel--inspect-reject-tool-calls)
" \\[gptel--inspect-reject-tool-calls], "
(buttonize "Steer" #'gptel--inspect-steer-tool-calls)
" \\[gptel--inspect-steer-tool-calls], "
(buttonize "Return" #'gptel--inspect-quit-tool-calls)
" \\[gptel--inspect-quit-tool-calls], "
(buttonize "Edit" (lambda (_) (read-only-mode 'toggle)))
" \\[read-only-mode]"))))
(set-buffer-modified-p nil)
(read-only-mode)
(gptel--inspect-tool-post-command)
(display-buffer (current-buffer) gptel-display-buffer-action)))