branch: externals/ellama
commit 344fe10eead4b9b352af8669bcb4deef6ac1e1e9
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Add async result reporting tool
Add ellama-tools--make-report-result-tool function that dynamically creates
a
report_result tool. This tool allows async result reporting to a callback
and
marks the task as completed, imlementing task completion handling.
---
ellama-tools.el | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/ellama-tools.el b/ellama-tools.el
index e1ae71a64e..fe87ec227e 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -659,5 +659,21 @@ Returns the output of the patch command or an error
message."
:description
"Apply a patch to the file at PATH."))
+(defun ellama-tools--make-report-result-tool (callback session)
+ "Make report_result tool dynamically for SESSION.
+CALLBACK will be used to report result asyncronously."
+ `(:function
+ (lambda (result)
+ (let* ((extra (ellama-session-extra ,session))
+ (done (plist-get extra :task-completed)))
+ (unless done
+ (setf (ellama-session-extra ,session)
+ (plist-put extra :task-completed t))
+ (funcall ,callback result)))
+ "Result received. Task completed.")
+ :name "report_result"
+ :description "Report final result and terminate the task."
+ :args ((:name "result" :type string))))
+
(provide 'ellama-tools)
;;; ellama-tools.el ends here