From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sender5-of-o51.zoho.com (sender5-of-o51.zoho.com [165.173.182.51]) by hrrol.systemreboot.net (OpenSMTPD) with ESMTPS id ea29397e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 9 Nov 2026 13:26:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1794230757; cv=none; d=zohomail.com; s=zohoarc; b=PZgprVamREAOdiPpT8QzgMYE9RnqhdJyfH1K45aTbJ4M6//lQ6ga6rSPLtWjPmo+oZqDPGnicyPk7F9FbDUSg7KcbQrGPmuHPG1vUZetpuCc6LyiEYsKu20InrO0/jdG89i5YmsSIbCjsEhC54H28R+gvVbJnp9WdKfKge4lSuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794230757; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=1PGE+hFc72pxo2+Ft6MVJMJgeDoPeNsrk7zlK+N9vhU=; b=mraxei/VR5a3cYa8/v9zpmI3U8+SbJjt7FYO6WjbSxC2NkUa9wMXnMuvM2IH2CiPKoxGZsYh2QN3Ol0nSUuxqHcB4dPUyMkPFbNBypjS8fZTar9PdyevG275zpg1zQlNVuSkFQeSx9fbUiAg4+fnTp+gfgVpK0KktaXl6bzuXt4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=UweH17pZcMP2ZwZa05uHrZ6pxcU3yU3obS41VJHRkzl3PnlUuDp+yOzaaY/n7vw691lcCW6ZU+RjtAjhgFbSUwbJ9q3+E3xMypSzpQl2nd6QkeEFuQ5hQzC9CyVhRB9DKY/uEPGo+3hP3UereRuzyzWfeTKPhJglps/PQ/X/5Vc=; c=relaxed/relaxed; s=zoho; d=elephly.net; v=1; bh=1PGE+hFc72pxo2+Ft6MVJMJgeDoPeNsrk7zlK+N9vhU=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1794230755809801.7756801630205; Mon, 9 Nov 2026 05:25:55 -0800 (PST) From: Ricardo Wurmus To: Arun Isaac Cc: Ricardo Wurmus , kaagum@systemreboot.net Subject: Re: strategies for context management In-Reply-To: <87zevkqf4d.fsf@systemreboot.net> References: <87ld76e5w0.fsf@elephly.net> <87fqxerqg6.fsf@systemreboot.net> <87jympps3s.fsf@elephly.net> <87eccxoy4k.fsf@elephly.net> <87zevkqf4d.fsf@systemreboot.net> User-Agent: mu4e 1.14.4; emacs 31.1 Date: Mon, 09 Nov 2026 14:25:52 +0100 Message-ID: <87o6bynnkv.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External List-Id: Hi Arun, >> My proposal is to add a compaction strategy record with a=20 >> predicate >> and a handler. The predicate takes the current state and=20 >> decides >> whether compaction should be performed. The handler takes state=20 >> and >> returns new state. > > That's a neat interface=E2=80=94it avoids hard-coding a specific=20 > compacter; I > like it. > > I have written up a draft (and completely untested) patch=20 > implementing > it. Let me know what you think, and if you'd be happy to flesh=20 > it out > and experiment with it a bit. The patch follows in a subsequent=20 > mail. Thank you! > Some differences from your proposal: > - Instead of a predicate and a handler, I have a single=20 > function. The > function can be identity for a no-compaction strategy. > - The compacter doesn't update the state. The state remains=20 > complete and > whole, just like without compaction. The compaction only happens=20 > in > do-effect, just before querying the LLM. This means that the compaction function will see an=20 ever-increasing number of messages. I understand that having more=20 context can be useful to avoid drift and loss of important=20 information, but it also means that compaction cannot build up its=20 own state. It would have to perform the same work over and over=20 again, just with more messages tacked on, yet it has no way to=20 checkpoint its progress. Perhaps a compacter would need to bring=20 its own infrastructure to avoid repeating work across turns. > Other things to think about: > - The compacter function is directly exposed to the JSON tree of=20 > the > messages; we should probably introduce an =20 > record > type abstraction. Yes, this seems like a good idea. > - The compacter function is not told how many tokens the=20 > previous LLM > query took. This may be important information. Is that information available to kaagum? >> A complication is that a handler may issue LLM calls (e.g. to >> summarize stuff), and I don't know how this would slot into the=20 >> TEA >> loop. Perhaps triggering session/fork would be appropriate=20 >> then. > > That is a valid use case, and we should support it. But it may=20 > be best > to let the compacter make its own LLM calls without having to=20 > integrate > those LLM calls into the TEA loop. I don't know enough to understand why it would be desirable to let=20 the compacter make its own calls instead of considering it an=20 optional detour in the back and forth between kaagum and the LLM. --=20 Ricardo