From: Arun Isaac <arunisaac@systemreboot.net>
To: Arun Isaac <arunisaac@systemreboot.net>,
Ricardo Wurmus <rekado@elephly.net>
Cc: kaagum@systemreboot.net
Subject: [PATCH v2 5/5] Allow user-defined context compacters.
Date: Sun, 15 Nov 2026 04:47:50 +0000 [thread overview]
Message-ID: <20261115044752.5595-6-arunisaac@systemreboot.net> (raw)
In-Reply-To: <87ik20nycd.fsf@systemreboot.net>
---
README.md | 15 +++++++++++++++
bin/kaagum | 12 +++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 210089a..19a6d39 100644
--- a/README.md
+++ b/README.md
@@ -113,6 +113,21 @@ noop-compacter
```
The noop compacter is an identity compacter. It doesn't compact at all; use this compacter to disable context compaction. To use this compacter, pass `--compacter-eval=noop-compacter` to kaagum.
+## User-defined compacters
+
+kaagum also supports custom user-defined compacters. Similar to the `--more-tools` parameter, you define your custom compacter in a scheme file and pass it to kaagum using the `--compacter-file` parameter.
+
+A compacter is a function that accepts a list of `messages` and returns a compacted list of messages. `messages` is a list of `<user-message>`, `<assistant-message>` or `<tool-message>` records. See `kaagum/message.scm` for definitions of these record types and utilities to operate on them.
+
+In addition, compacters are also provided the following keyword arguments:
+- **tokens:** number of tokens that correspond to all `messages` put together
+- **context-length:** context length of the model in use
+- **llm-base-uri:** base URI of the LLM provider
+- **llm-api-key:** API key to authenticate with the LLM provider
+- **model:** name of the model in use
+
+See definitions of built-in compacters in `kaagum/compacters.scm` for examples.
+
# 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 50fbb76..ac5ab4d 100755
--- a/bin/kaagum
+++ b/bin/kaagum
@@ -57,6 +57,9 @@ exec guile --no-auto-compile -e main -s "$0" "$@"
(option (list #\c "compacter-eval") #t #f
(lambda (opt name arg result)
(acons 'compacter-eval arg result)))
+ (option (list "compacter-file") #t #f
+ (lambda (opt name arg result)
+ (acons 'compacter-file arg result)))
(option (list "kagi-api-key-command") #t #f
(lambda (opt name arg result)
(acons 'kagi-api-key-command arg result)))
@@ -84,6 +87,7 @@ Run kaagum AI agent.
(default: \"anthropic/claude-opus-4.8\")
-t, --more-tools=FILE scheme file providing more tools to the agent
-c, --compacter-eval=EXPR expression returning compacter (default: noop)
+ --compacter-file=FILE scheme file providing compacter
--kagi-api-key-command=COMMAND command to run to get Kagi API key
@@ -142,9 +146,11 @@ Run kaagum AI agent.
(if (assq-ref args 'more-tools)
(load (assq-ref args 'more-tools))
'()))
- (eval (call-with-input-string (assq-ref args 'compacter-eval)
- read)
- (interaction-environment)))))
+ (if (assq-ref args 'compacter-file)
+ (load (assq-ref args 'compacter-file))
+ (eval (call-with-input-string (assq-ref args 'compacter-eval)
+ read)
+ (interaction-environment))))))
(parameterize ((%kagi-api-key (and kagi-api-key-command
(get-api-key kagi-api-key-command))))
;; (trace 'kagi "Key ~a" (%kagi-api-key))
--
2.54.0
next prev parent reply other threads:[~2026-11-15 4:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 8:11 strategies for context management Ricardo Wurmus
2026-11-06 14:21 ` Arun Isaac
2026-11-06 21:28 ` Ricardo Wurmus
2026-11-07 8:15 ` Ricardo Wurmus
2026-11-08 1:35 ` Arun Isaac
2026-11-08 1:36 ` [PATCH] Support context compaction Arun Isaac
2026-11-09 13:25 ` strategies for context management Ricardo Wurmus
2026-11-10 23:42 ` Arun Isaac
2026-11-13 22:41 ` [PATCH 1/4] Add message record equality comparators Arun Isaac
2026-11-13 22:41 ` [PATCH 2/4] Support context compaction Arun Isaac
2026-11-13 22:41 ` [PATCH 3/4] Add sliding window compacter Arun Isaac
2026-11-13 22:41 ` [PATCH 4/4] Allow loading compacter from file Arun Isaac
2026-11-13 22:46 ` strategies for context management Arun Isaac
2026-11-15 4:47 ` [PATCH v2 0/5] Context compaction Arun Isaac
2026-11-19 14:28 ` Ricardo Wurmus
2026-11-19 14:29 ` Ricardo Wurmus
2026-11-19 18:43 ` Arun Isaac
2026-11-20 5:39 ` Ricardo Wurmus
2026-11-20 5:56 ` Ricardo Wurmus
2026-11-20 13:42 ` Arun Isaac
2026-11-20 13:45 ` Arun Isaac
2026-11-20 14:01 ` Ricardo Wurmus
2026-11-22 16:54 ` Arun Isaac
2026-11-15 4:47 ` [PATCH v2 1/5] Support context compaction Arun Isaac
2026-11-15 4:47 ` [PATCH v2 2/5] Add sliding window compacter Arun Isaac
2026-11-15 4:47 ` [PATCH v2 3/5] Add summarizing compacter Arun Isaac
2026-11-15 4:47 ` [PATCH v2 4/5] Document context compacters Arun Isaac
2026-11-15 4:47 ` Arun Isaac [this message]
2026-11-08 1:43 ` strategies for context management Arun Isaac
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261115044752.5595-6-arunisaac@systemreboot.net \
--to=arunisaac@systemreboot.net \
--cc=kaagum@systemreboot.net \
--cc=rekado@elephly.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox