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

* Re: draft: Feature to load external tools
  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
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Arun Isaac @ 2026-11-05  0:17 UTC (permalink / raw)
  To: Ricardo Wurmus, kaagum


Hi Ricardo,

> 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.

This is a great idea. I've been wanting something like this for a while.
Thanks for thinking about it, and drafting it out!

I have a slightly modified proposal. I think we should do this with a
"custom tools file", rather like how we do manifest files and package
definition files in Guix. The user defines their tools in a file and
returns them as the final expression. They may refer to other modules or
packages by modifying the GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH
environment variables. I've implemented this in the patch that follows.
Let me know what you think.

> 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:

Good point. I'm sending a patch to this effect as well.

Regards,
Arun

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

* [PATCH 1/2] Allow setting environment variables with agent shell.
  2026-11-05  0:17 ` Arun Isaac
@ 2026-11-05  0:19   ` 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
  2 siblings, 0 replies; 6+ messages in thread
From: Arun Isaac @ 2026-11-05  0:19 UTC (permalink / raw)
  To: Arun Isaac, Ricardo Wurmus, kaagum

---
 emacs/agent-shell-kaagum.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/emacs/agent-shell-kaagum.el b/emacs/agent-shell-kaagum.el
index 8e89cf5..748dd11 100644
--- a/emacs/agent-shell-kaagum.el
+++ b/emacs/agent-shell-kaagum.el
@@ -43,6 +43,22 @@
   :type '(repeat string)
   :group 'agent-shell)
 
+(defcustom agent-shell-kaagum-environment
+  nil
+  "Environment variables for the kaagum agent.
+
+This should be a list of environment variables to be used when starting
+the kaagum agent.
+
+Example usage to set custom environment variables:
+
+  (setq agent-shell-kaagum-environment
+        (agent-shell-make-environment-variables
+         \"MY_VAR\" \"some-value\"
+         \"MY_OTHER_VAR\" \"another-value\"))"
+  :type '(repeat string)
+  :group 'agent-shell)
+
 (defun agent-shell-kaagum-make-agent-config ()
   "Create a kaagum ACP agent configuration.
 
@@ -65,6 +81,7 @@ Returns an agent configuration alist using `agent-shell-make-agent-config'."
   "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
+                                :environment-variables agent-shell-kaagum-environment
                                 :context-buffer buffer))
 
 (defun agent-shell-kaagum--welcome-message (config)
-- 
2.54.0


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

* [PATCH 2/2] Allow custom tools.
  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   ` Arun Isaac
  2026-11-05  7:08   ` draft: Feature to load external tools Ricardo Wurmus
  2 siblings, 0 replies; 6+ messages in thread
From: Arun Isaac @ 2026-11-05  0:19 UTC (permalink / raw)
  To: Arun Isaac, Ricardo Wurmus, kaagum

---
 README.md  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 bin/kaagum |  7 +++++++
 2 files changed, 55 insertions(+)

diff --git a/README.md b/README.md
index 045598c..67a3ad2 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,54 @@ Install the `kaagum` and `emacs-agent-shell-kaagum` packages from Guix. Then, pu
 ```
 Change to the directory you want to work in. kaagum will only have access to that directory and its contents. Run `M-x agent-shell` and select `kaagum` from the menu.
 
+# Using custom tools with kaagum
+
+kaagum empowers you to equip your agents with custom tools specific to your needs. To do this, you write a scheme file (let's call it `custom-tools.scm`) that defines your custom tools. Then, you pass that file on to kaagum using the `--more-tools=custom-tools.scm` parameter.
+
+What should your custom tools file look like? Here's an example:
+```scheme
+(use-modules (kaagum tools))
+
+(define %string-length
+  (tool #:description "Compute the length of a string."
+        #:parameters `(("str" . ,(tool-parameter
+                                  #:type "string"
+                                  #:description "String whose length to compute"
+                                  #:required? #t)))
+        #:proc (lambda* (#:key str)
+                 (format #t "~a~%" (string-length str)))
+        #:title (lambda* (#:key str)
+                  (format #f "string-length ~s" str))
+        #:kind "other"))
+
+`(("string-length" . ,%string-length))
+```
+The file must return an association list mapping tool names to definitions (`<tool>` objects) as its final expression.
+
+`<tool>` objects are defined using `tool` from `(kaagum tools)`. `tool` takes the following keyword arguments:
+- **description:** string that describes the tool; this is read by the LLM to decide whether and how to use the tool—make it a detailed documentation of the tool and the parameters that it takes.
+- **parameters:** association list mapping tool parameter names to `<tool-parameter>` objects.
+- **proc:** the actual function run if the tool is executed; parameters are passed to it as keyword arguments, and output must be written to standard output
+- **title:** human-readable string describing what the tool is doing; this is used by the ACP client in its UI
+- **kind:** category of tool—one of `"read"`, `"edit"`, `"delete"`, `"move"`, `"search"`, `"execute"`, `"think"`, `"fetch"`, `"switch_mode"`, or `"other"`; this is also used by the ACP client in its UI
+- **container-mappings:** list of Guix `<file-system-mapping>` objects representing file system paths to mount into the container of the tool call process
+- **container-namespaces:** list of namespaces to create for the container—should be like `%namespaces` from Guix's `(gnu build linux-container)`
+
+`<tool-parameter>` objects are defined using `tool-parameter` from `(kaagum tools)`. tool-parameter takes the following keyword arguments:
+- **type:** parameter type—`"string"`, `"boolean"`, etc.
+- **description:** string describing the tool parameter
+- **required?:** `#t` if this parameter is required (that is, mandatory), else `#f`; if the parameter is not required, the default argument must be specified in the `lambda*` function in `#:proc` and `#:title`.
+
+See definitions of built-in tools under `kaagum/tools/*.scm` for examples.
+
+If your custom tools require other Guile packages or modules, you may provide access by setting the `GUILE_LOAD_PATH` and `GUILE_LOAD_COMPILED_PATH` environment variables. If you're using Emacs agent shell, you can do this by setting the `agent-shell-kaagum-environment` variable.
+```elisp
+(setq agent-shell-kaagum-environment
+      (agent-shell-make-environment-variables
+       "GUILE_LOAD_PATH" "/some/path/"
+       "GUILE_LOAD_COMPILED_PATH" "/some/path/"))
+```
+
 # Contributing
 
 Please report issues or send patches to the public inbox at [kaagum@systemreboot.net](https://lists.systemreboot.net/kaagum/).
diff --git a/bin/kaagum b/bin/kaagum
index 75e837f..2c8c9ee 100755
--- a/bin/kaagum
+++ b/bin/kaagum
@@ -50,6 +50,9 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
         (option (list #\k "api-key-command") #t #f
                 (lambda (opt name arg result)
                   (acons 'api-key-command arg result)))
+        (option (list #\t "more-tools") #t #f
+                (lambda (opt name arg result)
+                  (acons 'more-tools arg result)))
         (option (list "kagi-api-key-command") #t #f
                 (lambda (opt name arg result)
                   (acons 'kagi-api-key-command arg result)))
@@ -75,6 +78,7 @@ Run kaagum AI agent.
   -k, --api-key-command=COMMAND  command to run to get API key
   -m, --model=MODEL              LLM model name to start new sessions with
                                  (default: \"anthropic/claude-opus-4.8\")
+  -t, --more-tools=FILE          scheme file providing more tools to the agent
 
   --kagi-api-key-command=COMMAND command to run to get Kagi API key
 
@@ -128,6 +132,9 @@ Run kaagum AI agent.
                                   %forge-tools
                                   (if kagi-api-key-command
                                       %kagi-tools
+                                      '())
+                                  (if (assq-ref args 'more-tools)
+                                      (load (assq-ref args 'more-tools))
                                       '())))))
          (parameterize ((%kagi-api-key (and kagi-api-key-command
                                             (get-api-key kagi-api-key-command))))
-- 
2.54.0


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

* Re: draft: Feature to load external tools
  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   ` Ricardo Wurmus
  2026-11-05 10:59     ` Arun Isaac
  2 siblings, 1 reply; 6+ messages in thread
From: Ricardo Wurmus @ 2026-11-05  7:08 UTC (permalink / raw)
  To: Arun Isaac; +Cc: Ricardo Wurmus, kaagum

Hi Arun,

> I have a slightly modified proposal. I think we should do this 
> with a
> "custom tools file" [...]

Perfect, the patches look good to me.  Thank you!

-- 
Ricardo

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

* Re: draft: Feature to load external tools
  2026-11-05  7:08   ` draft: Feature to load external tools Ricardo Wurmus
@ 2026-11-05 10:59     ` Arun Isaac
  0 siblings, 0 replies; 6+ messages in thread
From: Arun Isaac @ 2026-11-05 10:59 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: Ricardo Wurmus, kaagum


Brilliant, pushed!

^ 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