[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 97934261f2: gptel: Run tools in request buffer (#748
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 97934261f2: gptel: Run tools in request buffer (#748) |
Date: |
Wed, 26 Mar 2025 16:01:56 -0400 (EDT) |
branch: elpa/gptel
commit 97934261f2418d69996b7cba78a3c63ab301e5a1
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel: Run tools in request buffer (#748)
* gptel.el (gptel--handle-tool-use): Currently tools run at
toplevel without setting the buffer. Run tools in the buffer from
which the request originates instead. This is required for tools
that make use of the buffer-local context. An example is when a
tool runs `(project-current)'. (#748)
* NEWS: Add entry about the change.
---
NEWS | 8 +++++
gptel.el | 109 +++++++++++++++++++++++++++++++--------------------------------
2 files changed, 62 insertions(+), 55 deletions(-)
diff --git a/NEWS b/NEWS
index dda92bc0ee..45ca70d2eb 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@
* 0.9.9
+** Breaking changes
+
+** New models and backends
+
** New features and UI changes
- The new option ~gptel-curl-extra-args~ can be used to specify extra
@@ -10,6 +14,10 @@
which can be used to specify Curl arguments when using a specific
backend.
+- Tools now run in the buffer from which the request originates.
+
+** Notable Bug fixes
+
* 0.9.8 2025-03-13
Version 0.9.8 adds support for new Gemini, Anthropic, OpenAI,
diff --git a/gptel.el b/gptel.el
index e6ce76ec26..2e3d0ed8b2 100644
--- a/gptel.el
+++ b/gptel.el
@@ -2068,63 +2068,62 @@ Run post-response hooks."
(with-current-buffer (plist-get info :buffer)
(when gptel-mode
(gptel--update-status
- (format " Calling tool..." ) 'mode-line-emphasis)))
-
- (let ((result-alist) (pending-calls))
- (mapc ; Construct function calls
- (lambda (tool-call)
- (letrec ((args (plist-get tool-call :args))
- (name (plist-get tool-call :name))
- (arg-values)
- (tool-spec
- (cl-find-if
- (lambda (ts) (equal (gptel-tool-name ts) name))
- (plist-get info :tools)))
- (process-tool-result
- (lambda (result)
- (plist-put info :tool-success t)
- (let ((result (gptel--to-string result)))
- (plist-put tool-call :result result)
- (push (list tool-spec args result) result-alist))
- (cl-incf tool-idx)
- (when (>= tool-idx ntools) ; All tools have run
- (gptel--inject-prompt
- backend (plist-get info :data)
- (gptel--parse-tool-results
- backend (plist-get info :tool-use)))
- (funcall (plist-get info :callback)
- (cons 'tool-result result-alist) info)
- (gptel--fsm-transition fsm)))))
- (if (null tool-spec)
- (message "Unknown tool called by model: %s" name)
- (setq arg-values
- (mapcar
- (lambda (arg)
- (let ((key (intern (concat ":" (plist-get arg :name)))))
- (plist-get args key)))
- (gptel-tool-args tool-spec)))
- ;; Check if tool requires confirmation
- (if (and gptel-confirm-tool-calls (or (eq
gptel-confirm-tool-calls t)
- (gptel-tool-confirm
tool-spec)))
- (push (list tool-spec arg-values process-tool-result)
- pending-calls)
- ;; If not, run the tool
- (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)))))))
- tool-use)
- (when pending-calls
- (with-current-buffer (plist-get info :buffer)
+ (format " Calling tool..." ) 'mode-line-emphasis))
+
+ (let ((result-alist) (pending-calls))
+ (mapc ; Construct function calls
+ (lambda (tool-call)
+ (letrec ((args (plist-get tool-call :args))
+ (name (plist-get tool-call :name))
+ (arg-values)
+ (tool-spec
+ (cl-find-if
+ (lambda (ts) (equal (gptel-tool-name ts) name))
+ (plist-get info :tools)))
+ (process-tool-result
+ (lambda (result)
+ (plist-put info :tool-success t)
+ (let ((result (gptel--to-string result)))
+ (plist-put tool-call :result result)
+ (push (list tool-spec args result) result-alist))
+ (cl-incf tool-idx)
+ (when (>= tool-idx ntools) ; All tools have run
+ (gptel--inject-prompt
+ backend (plist-get info :data)
+ (gptel--parse-tool-results
+ backend (plist-get info :tool-use)))
+ (funcall (plist-get info :callback)
+ (cons 'tool-result result-alist) info)
+ (gptel--fsm-transition fsm)))))
+ (if (null tool-spec)
+ (message "Unknown tool called by model: %s" name)
+ (setq arg-values
+ (mapcar
+ (lambda (arg)
+ (let ((key (intern (concat ":" (plist-get arg
:name)))))
+ (plist-get args key)))
+ (gptel-tool-args tool-spec)))
+ ;; Check if tool requires confirmation
+ (if (and gptel-confirm-tool-calls (or (eq
gptel-confirm-tool-calls t)
+ (gptel-tool-confirm
tool-spec)))
+ (push (list tool-spec arg-values process-tool-result)
+ pending-calls)
+ ;; If not, run the tool
+ (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)))))))
+ tool-use)
+ (when pending-calls
(setq gptel--fsm-last fsm)
(when gptel-mode (gptel--update-status
- (format " Run tools?" ) 'mode-line-emphasis)))
- (funcall (plist-get info :callback)
- (cons 'tool-call pending-calls) info)))))
+ (format " Run tools?" ) 'mode-line-emphasis))
+ (funcall (plist-get info :callback)
+ (cons 'tool-call pending-calls) info))))))
;;;; State machine predicates
;; Predicates used to find the next state to transition to, see
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/gptel 97934261f2: gptel: Run tools in request buffer (#748),
ELPA Syncer <=