mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-07-25 16:21:23 +00:00
Port goclaw context pruning to match upstream TS design in
openclaw/src/agents/pi-hooks/context-pruning/:
- Opt-in default: prune only when mode="cache-ttl" (was opt-out)
- Remove Pass 0 per-result 30% guard (duplicated Pass 1 with different
suffix, caused wobble)
- Dedupe double prune call per iteration: PruneStage owns the single
entry point; loop_history only runs limitHistoryTurns + sanitizeHistory
- Add cache-TTL gate for Anthropic prompt cache: skip prune while cache
is live, scoped per-session via sync.Map
- Add context.pruned event emission for observability
- Configurable TTL as Go duration string ("5m", "30s")
BREAKING CHANGE: context pruning now opt-in. Add
contextPruning.mode: "cache-ttl" to config.agents.defaults to restore.
Migration 51 / SQLite v19 backfills mode="cache-ttl" for agents with
existing custom context_pruning config missing the mode field, so
previously-configured agents keep pruning after the opt-in flip.
NULL configs stay NULL (new opt-in default applies).
Web UI adds Cache TTL input + toggle wiring mode to cache-ttl/off.
13 lines
643 B
SQL
13 lines
643 B
SQL
-- Backfill mode: "cache-ttl" for agents that have custom context_pruning config
|
|
-- but are missing the "mode" field. This preserves user intent after the
|
|
-- opt-in default flip (faithful port of TS behavior) — see CHANGELOG.
|
|
--
|
|
-- Rows matched: context_pruning is a non-empty JSON object without a "mode" key.
|
|
-- Rows skipped: NULL, empty object, non-object values, or already has "mode".
|
|
UPDATE agents
|
|
SET context_pruning = jsonb_set(context_pruning, '{mode}', '"cache-ttl"'::jsonb)
|
|
WHERE context_pruning IS NOT NULL
|
|
AND jsonb_typeof(context_pruning) = 'object'
|
|
AND context_pruning <> '{}'::jsonb
|
|
AND NOT (context_pruning ? 'mode');
|