refactor: replace context_token_budget with model context_window for context trimming

The per-bot context_token_budget column was unused (no frontend UI) and
has been removed. Context trimming now derives the budget from the chat
model's context_window setting, which is already configured per model.
This commit is contained in:
Acbox
2026-04-14 21:04:42 +08:00
parent cb44408277
commit 84f1d0612a
10 changed files with 16 additions and 42 deletions
-1
View File
@@ -155,7 +155,6 @@ CREATE TABLE IF NOT EXISTS bots (
discuss_probe_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
tts_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
browser_context_id UUID REFERENCES browser_contexts(id) ON DELETE SET NULL,
context_token_budget INTEGER,
persist_full_tool_results BOOLEAN NOT NULL DEFAULT false,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
@@ -0,0 +1,4 @@
-- 0067_drop_context_token_budget (down)
-- Restore the context_token_budget column.
ALTER TABLE bots ADD COLUMN IF NOT EXISTS context_token_budget INTEGER;
@@ -0,0 +1,5 @@
-- 0067_drop_context_token_budget
-- Remove the unused context_token_budget column from bots table.
-- Context trimming now derives the budget from the chat model's context_window.
ALTER TABLE bots DROP COLUMN IF EXISTS context_token_budget;
+1 -5
View File
@@ -20,7 +20,6 @@ SELECT
image_models.id AS image_model_id,
tts_models.id AS tts_model_id,
browser_contexts.id AS browser_context_id,
bots.context_token_budget,
bots.persist_full_tool_results
FROM bots
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
@@ -56,11 +55,10 @@ WITH updated AS (
image_model_id = COALESCE(sqlc.narg(image_model_id)::uuid, bots.image_model_id),
tts_model_id = COALESCE(sqlc.narg(tts_model_id)::uuid, bots.tts_model_id),
browser_context_id = COALESCE(sqlc.narg(browser_context_id)::uuid, bots.browser_context_id),
context_token_budget = COALESCE(sqlc.narg(context_token_budget)::integer, bots.context_token_budget),
persist_full_tool_results = sqlc.arg(persist_full_tool_results),
updated_at = now()
WHERE bots.id = sqlc.arg(id)
RETURNING bots.id, bots.language, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.compaction_enabled, bots.compaction_threshold, bots.compaction_ratio, bots.timezone, bots.chat_model_id, bots.heartbeat_model_id, bots.compaction_model_id, bots.title_model_id, bots.image_model_id, bots.search_provider_id, bots.memory_provider_id, bots.tts_model_id, bots.browser_context_id, bots.context_token_budget, bots.persist_full_tool_results
RETURNING bots.id, bots.language, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.compaction_enabled, bots.compaction_threshold, bots.compaction_ratio, bots.timezone, bots.chat_model_id, bots.heartbeat_model_id, bots.compaction_model_id, bots.title_model_id, bots.image_model_id, bots.search_provider_id, bots.memory_provider_id, bots.tts_model_id, bots.browser_context_id, bots.persist_full_tool_results
)
SELECT
updated.id AS bot_id,
@@ -83,7 +81,6 @@ SELECT
image_models.id AS image_model_id,
tts_models.id AS tts_model_id,
browser_contexts.id AS browser_context_id,
updated.context_token_budget,
updated.persist_full_tool_results
FROM updated
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
@@ -116,7 +113,6 @@ SET language = 'auto',
memory_provider_id = NULL,
tts_model_id = NULL,
browser_context_id = NULL,
context_token_budget = NULL,
persist_full_tool_results = false,
updated_at = now()
WHERE id = $1;