Function: gptel--process-tool-call
gptel--process-tool-call is a natively compiled function defined in
gptel-request.el.
Signature
(gptel--process-tool-call FSM TOOL-SPEC TOOL-CALL RESULT)
Documentation
Add tool RESULT to a TOOL-CALL and transition FSM if required.
TOOL-CALL is a plist with the tool :name, :args and other metadata.
TOOL-SPEC is the gptel-tool object, and FSM is the request state.
If all pending tool calls in the current request have finished, it injects the results into the prompt data and transitions the FSM.
Source Code
;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(defun gptel--process-tool-call (fsm tool-spec tool-call result)
"Add tool RESULT to a TOOL-CALL and transition FSM if required.
TOOL-CALL is a plist with the tool :name, :args and other metadata.
TOOL-SPEC is the `gptel-tool' object, and FSM is the request state.
If all pending tool calls in the current request have finished, it
injects the results into the prompt data and transitions the FSM."
(let* ((info (gptel-fsm-info fsm))
(tool-result-alist (plist-get info :tool-result))
;; MAYBE(tool-hooks): Use plist-member for valid nil :result?
(remaining (cl-loop for call in (plist-get info :tool-use)
count (not (plist-get call :result)))))
(let ((result (gptel--to-string result)))
;; FIXME(tool-hooks): If a hook has changed the tool that was called
;; tool-spec needs to be updated.
(push (list tool-spec (plist-get tool-call :args) result)
tool-result-alist)
(plist-put info :tool-result tool-result-alist) ;for the callback
;; NOTE: tool-call is a member of (plist-get info :tool-use), so :tool-use
;; is modified by side effect.
;; FIXME: Make the implicit addition to :tool-use explicit
(plist-put tool-call :result result)) ;for the LLM
;; All tools have run
(when (<= (cl-decf remaining) 0) (gptel--fsm-transition fsm))))