public inbox for kaagum@systemreboot.net
 help / color / mirror / Atom feed
* draft: Feature to load external tools
@ 2026-11-04 17:39 Ricardo Wurmus
  2026-11-05  0:17 ` Arun Isaac
  0 siblings, 1 reply; 6+ messages in thread
From: Ricardo Wurmus @ 2026-11-04 17:39 UTC (permalink / raw)
  To: kaagum

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]

Hi Arun,

I'd like to grant kaagum access to a bunch of custom tools that 
I'm about to write (e.g. for web fetch, bioinfo data retrieval, 
interfacing with a qemu socket, etc), and I thought it would be 
helpful to have kaagum load user-specified Guile modules from 
KAAGUM_TOOLS_PATH.

The implementation is rough, but it works for my purposes.  I 
haven't put any polish on it as I'm not sure going through an 
environment variable is desirable.  Below is a patch.  Note that 
this probably isn't a good way to do things when a tool requires 
other Guile packages, because nothing is added to the Guile load 
path.

This also required a change to agent-shell-kaagum-make-client to 
set the variable; other agent-shell clients have a dedicated 
variable for setting environment variables, which could be a 
useful addition anyway:

--8<---------------cut here---------------start------------->8---
(defun agent-shell-kaagum-make-client (buffer)
  "Create a kaagum ACP client using BUFFER as context."
  (agent-shell--make-acp-client :command 
  agent-shell-kaagum-command
                                :command-params 
                                agent-shell-kaagum-parameters
                                :context-buffer buffer
                                :environment-variables
                                (agent-shell-make-environment-variables
                                 "KAAGUM_TOOLS_PATH" 
                                 "/home/rekado/dev/external-tools")))
--8<---------------cut here---------------end--------------->8---

What do you think?

-- 
Ricardo



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP-external-tools.patch --]
[-- Type: text/x-patch, Size: 3595 bytes --]

From 9f99a60b36188e8ce03f53f21d5437063a4a2945 Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
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{<tool>} objects."
       (else
        (assertion-violation (focus tool-call-status tool-call)
                             "Invalid tool call status")))))
+
+
+\f
+(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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-05 10:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 17:39 draft: Feature to load external tools Ricardo Wurmus
2026-11-05  0:17 ` Arun Isaac
2026-11-05  0:19   ` [PATCH 1/2] Allow setting environment variables with agent shell Arun Isaac
2026-11-05  0:19   ` [PATCH 2/2] Allow custom tools Arun Isaac
2026-11-05  7:08   ` draft: Feature to load external tools Ricardo Wurmus
2026-11-05 10:59     ` Arun Isaac

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox