From 9f99a60b36188e8ce03f53f21d5437063a4a2945 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Wed, 4 Nov 2026 13:15:22 +0100 Subject: [PATCH] WIP: external tools --- bin/kaagum | 4 +++- kaagum/tools.scm | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/bin/kaagum b/bin/kaagum index 45a24d9..6696f72 100755 --- a/bin/kaagum +++ b/bin/kaagum @@ -27,6 +27,7 @@ exec guile --no-auto-compile -e main -s "$0" "$@" (kaagum config) (kaagum openai) (kaagum tea) + (kaagum tools) (kaagum tools base) (kaagum tools forges) (kaagum tools kagi) @@ -128,7 +129,8 @@ Run kaagum AI agent. %forge-tools (if kagi-api-key-command %kagi-tools - '()))))) + '()) + (external-tools))))) (parameterize ((%kagi-api-key (pk (and kagi-api-key-command (get-api-key kagi-api-key-command))))) ;; (trace 'kagi "Key ~a" (%kagi-api-key)) diff --git a/kaagum/tools.scm b/kaagum/tools.scm index 65060ea..08f10d2 100644 --- a/kaagum/tools.scm +++ b/kaagum/tools.scm @@ -23,21 +23,25 @@ #:use-module (rnrs records syntactic) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-31) #:use-module (srfi srfi-43) #:use-module (ice-9 match) #:use-module (gnu build linux-container) #:use-module (gnu system file-systems) #:use-module (json) #:use-module (lens) + #:use-module ((guix ui) #:select (load*)) #:use-module (kaagum container) #:use-module (kaagum records) #:use-module (kaagum utils) + #:autoload (ice-9 ftw) (scandir) #:export (tool-call-parse-failure? tool-call-parse-failure-message tool->spec spec->tool-call - eval-tool-call)) + eval-tool-call + external-tools)) (define (readonly-cwd-only-mappings cwd arguments) (list (file-system-mapping @@ -303,3 +307,35 @@ available tools to their respective @code{} objects." (else (assertion-violation (focus tool-call-status tool-call) "Invalid tool call status"))))) + + + +(define (tool-directories) + "Return the list of directories containing tools." + (filter file-exists? + (map (cut string-append <> "/kaagum/tools") + (parse-path (getenv "KAAGUM_TOOLS_PATH"))))) + +(define (tool-files directory) + "Return the list of source files that define Kaagum tools." + (define dot-scm? + (cut string-suffix? ".scm" <>)) + (map (cut string-append directory "/" <>) + (scandir directory dot-scm?))) + +(define (external-tools) + "Load all external tools." + (define tag + (make-prompt-tag "user-code")) + (append-map (lambda (file) + (load* file '((kaagum container) + (kaagum lens) + (kaagum openai) + (kaagum records) + (kaagum tea) + (kaagum tools) + (kaagum trace) + (kaagum utils) + (kaagum web) + ))) + (append-map tool-files (tool-directories)))) -- 2.55.0