Skip to content

Commit f66e443

Browse files
tobjawkarthink
authored andcommitted
gptel: allow functions for tool confirmation
* gptel.el (gptel-make-tool, gptel--handle-tool-use): The `CONFIRM' argument for `gptel-make-tool' now accepts a function. This allows for conditional confirmation of tool calls, where the function determines if user prompting is required based on the tool's arguments.
1 parent 9077a8b commit f66e443

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

gptel.el

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,11 @@ The following keys are optional
19641964
CATEGORY: A string indicating a category for the tool. This is
19651965
used only for grouping in gptel's UI. Defaults to \"misc\".
19661966
1967-
CONFIRM: Whether the tool call should wait for the user to run
1968-
it. If true, the user will be prompted with the proposed tool
1969-
call, which can be examined, accepted, deferred or canceled.
1967+
CONFIRM: Whether the tool call should wait for the user to run it. If
1968+
true, the user will be prompted with the proposed tool call, which can
1969+
be examined, accepted, deferred or canceled. It can also be a function
1970+
that receives the same arguments as FUNCTION and returns true if the
1971+
user should be prompted.
19701972
19711973
INCLUDE: Whether the tool results should be included as part of
19721974
the LLM output. This is useful for logging and as context for
@@ -2444,8 +2446,10 @@ Run post-response hooks."
24442446
(plist-get args key)))
24452447
(gptel-tool-args tool-spec)))
24462448
;; Check if tool requires confirmation
2447-
(if (and gptel-confirm-tool-calls (or (eq gptel-confirm-tool-calls t)
2448-
(gptel-tool-confirm tool-spec)))
2449+
(if (and gptel-confirm-tool-calls
2450+
(or (eq gptel-confirm-tool-calls t) ;always confirm, or
2451+
(and-let* ((confirm (gptel-tool-confirm tool-spec)))
2452+
(or (not (functionp confirm)) (apply confirm arg-values)))))
24492453
(push (list tool-spec arg-values process-tool-result)
24502454
pending-calls)
24512455
;; If not, run the tool

0 commit comments

Comments
 (0)