From 915d45ec488254083f5a3da14ff87dd1e87b7cff Mon Sep 17 00:00:00 2001 From: "nap.liu" Date: Wed, 8 Apr 2026 23:20:48 +0800 Subject: [PATCH] fix: use agent context_window_size across all channels instead of hardcoded limits Remove redundant history[-ctx_size:] slicing in _call_agent_llm since all callers already truncate history via SQL .limit(ctx_size). The remaining channel handlers (websocket, dingtalk, discord, slack, wecom, teams, discord_gateway, wecom_stream) already use agent.context_window_size with DEFAULT_CONTEXT_WINDOW_SIZE=100 fallback. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/app/api/feishu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/app/api/feishu.py b/backend/app/api/feishu.py index aff83664a..e06fb3974 100644 --- a/backend/app/api/feishu.py +++ b/backend/app/api/feishu.py @@ -1497,11 +1497,11 @@ async def _call_agent_llm( return f"⚠️ {agent.name} 未配置 LLM 模型,请在管理后台设置。" # Build conversation messages (without system prompt — call_llm adds it) + # NOTE: history is already truncated to ctx_size by the SQL .limit() in + # each caller, so no further slicing is needed here. messages: list[dict] = [] - from app.models.agent import DEFAULT_CONTEXT_WINDOW_SIZE - ctx_size = agent.context_window_size or DEFAULT_CONTEXT_WINDOW_SIZE if history: - messages.extend(history[-ctx_size:]) + messages.extend(history) messages.append({"role": "user", "content": user_text}) # Use actual user_id so the system prompt knows who it's chatting with