branch: externals/ellama
commit 501ca4bf1f055d42efe90a6757f2deb8972e1d78
Merge: e421fac701 a72f74288a
Author: Sergey Kostyaev <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #379 from s-kostyaev/fix-tool-calling
Normalize file path in write-file function
---
NEWS.org | 21 +++++++++++++++++++++
ellama-tools.el | 23 ++++++++++++++++-------
ellama.el | 12 ++++++------
skills/changelog/SKILL.md | 2 +-
4 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 7dc3f3f6cf..b848919a7c 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,24 @@
+* Version 1.12.4
+- Normalize file path in write-file function. Added expand-file-name to
properly
+ handle both absolute and relative paths when writing files, preventing
+ potential issues with file path resolution.
+- Filter function objects from function call arguments. This prevents display
of
+ uncallable function objects in the confirmation prompt.
+- Make task tool unaccessible for general subagents. This change improves
+ security and control over tool access.
+- Fix file write tool. Corrected the order of operations in
+ ellama-tools-write-file-tool by setting the buffer file name before inserting
+ content.
+- Fix async tools confirmation. Use callback function to return result to the
+ agent.
+- Improve system message handling. Added optional MSG parameter to
+ ellama-get-system-message to allow callers to provide custom system messages
+ via the :system plist key. This allows sub-agents to use skills.
+- Improve agent response result handling. Updated result encoding to return
+ "done" for nil results instead of causing potential errors.
+- Fix result handling in tool execution wrapper. Improved the logic for
handling
+ tool results by ensuring JSON encoding only occurs when a result exists. This
+ change fixes async task execution.
* Version 1.12.3
- Improve loop control in confirmation dialog. Refactored the while loop in the
confirmation prompt to use explicit t/nil returns for loop continuation
diff --git a/ellama-tools.el b/ellama-tools.el
index ad78c26e09..eec9a0b952 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -92,7 +92,9 @@ Tools from this list will work without user confirmation."
(tools (plist-get cfg :tools)))
(cond
((eq tools :all)
- ellama-tools-available)
+ (cl-remove-if
+ (lambda (tool) (string= (llm-tool-name tool) "task"))
+ ellama-tools-available))
((listp tools)
(cl-remove-if-not
(lambda (tool) (member (llm-tool-name tool) tools))
@@ -152,7 +154,7 @@ approved, \"Forbidden by the user\" otherwise."
ellama-tools-argument-max-length))
(t
(format "%S" arg))))
- args))
+ (cl-remove-if (lambda (arg) (functionp arg)) args)))
(prompt (format "Allow calling %s with arguments: %s?"
function-name
(mapconcat #'identity args-display ", ")))
@@ -172,7 +174,7 @@ approved, \"Forbidden by the user\" otherwise."
arg)
(t
(format "%S" arg))))
- args)))
+ (cl-remove-if (lambda (arg) (functionp arg))
args))))
(with-current-buffer buf
(erase-buffer)
(insert (propertize "Ellama Function Call Confirmation\n"
@@ -201,9 +203,16 @@ approved, \"Forbidden by the user\" otherwise."
((eq answer ?r)
(setq result (read-string "Answer to the agent: "))
nil))))
- (when result (if (stringp result)
- result
- (json-encode result)))))))))
+ (let ((result-str (if (stringp result)
+ result
+ (when result
+ (json-encode result))))
+ (cb (and args
+ (functionp (car args))
+ (car args))))
+ (if (and cb result-str)
+ (funcall cb result-str)
+ (or result-str "done")))))))))
(defun ellama-tools-wrap-with-confirm (tool-plist)
"Wrap a tool's function with automatic confirmation.
@@ -313,8 +322,8 @@ TOOL-PLIST is a property list in the format expected by
`llm-make-tool'."
(defun ellama-tools-write-file-tool (path content)
"Write CONTENT to the file located at the specified PATH."
(with-temp-buffer
+ (setq buffer-file-name (expand-file-name path))
(insert content)
- (setq buffer-file-name path)
(save-buffer)))
(ellama-tools-define-tool
diff --git a/ellama.el b/ellama.el
index 11582f3697..4e54761fe2 100644
--- a/ellama.el
+++ b/ellama.el
@@ -6,7 +6,7 @@
;; URL: http://github.com/s-kostyaev/ellama
;; Keywords: help local tools
;; Package-Requires: ((emacs "28.1") (llm "0.24.0") (plz "0.8") (transient
"0.7") (compat "29.1") (yaml "1.2.3"))
-;; Version: 1.12.3
+;; Version: 1.12.4
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023
@@ -1241,9 +1241,10 @@ Returns the full path to AGENTS.md if found, or nil if
not found."
(buffer-string))))
""))
-(defun ellama-get-system-message ()
- "Return the effective system message, including dynamically scanned skills."
- (let ((msg (concat (or ellama-global-system "")
+(defun ellama-get-system-message (&optional msg)
+ "Return the effective system message, including dynamically scanned skills.
+MSG is a text that will be included in the resulting system message."
+ (let ((msg (concat (or msg ellama-global-system "")
(ellama-get-agents-md)
(ellama-skills-generate-prompt))))
(when (not (string= msg ""))
@@ -1548,8 +1549,7 @@ failure (with BUFFER current).
(error "Error calling the LLM: %s" msg))))
(donecb (or (plist-get args :on-done) #'ignore))
(prompt-with-ctx (ellama-context-prompt-with-context prompt))
- (system (or (plist-get args :system)
- (ellama-get-system-message)))
+ (system (ellama-get-system-message (plist-get args :system)))
(session-tools (and session
(ellama-session-extra session)
(plist-get (ellama-session-extra session)
:tools)))
diff --git a/skills/changelog/SKILL.md b/skills/changelog/SKILL.md
index a6afd73318..9c3bbbf087 100644
--- a/skills/changelog/SKILL.md
+++ b/skills/changelog/SKILL.md
@@ -22,7 +22,7 @@ with header:
* Version {version}
-After header should be changelog content. Content should ends with single
+After header should be changelog content. Content must ends with single
newline.
Example:
```text