deep_agent пре 1 месец
родитељ
комит
5e7bec710d
6 измењених фајлова са 9 додато и 20 уклоњено
  1. 1 2
      .env.example
  2. 4 13
      agents/model_factory.py
  3. 1 1
      api/usage_routes.py
  4. 2 2
      billing/pricing.py
  5. 0 1
      config.py
  6. 1 1
      scripts/selfcheck.py

+ 1 - 2
.env.example

@@ -13,11 +13,10 @@
 DEEP_AGENT_ENV_PRIORITY=dotenv
 
 # ============================================================
-# 模型(主 agent 与摘要模型)
+# 模型(主 agent)
 # ============================================================
 # provider:model 形式;deepseek* 前缀会走 langchain-deepseek(若已安装),否则走 ChatOpenAI
 DEEPAGENT_MODEL=deepseek-flash
-SUMMARY_MODEL=deepseek-v4-flash
 OPENAI_BASE_URL=https://api.deepseek.com
 OPENAI_API_KEY=sk-your-key-here
 OPENAI_TIMEOUT=180

+ 4 - 13
agents/model_factory.py

@@ -154,6 +154,10 @@ def _instantiate(name: str, common: dict[str, Any]) -> Any:
 # ============================================================
 # 进程级缓存
 # ============================================================
+# 没有「摘要模型」这一档:压缩用的 SummarizationMiddleware 由 deepagents 内部
+# 构造,拿到的就是传进 create_deep_agent 的那个实例,没有注入另一个模型的入口。
+# 所以思考级别同样作用于压缩调用;要单独给压缩配便宜模型,得先能替换掉那个
+# 中间件(同名冲突见 AGENTS.md 不变式 5)。
 
 @functools.lru_cache(maxsize=8)
 def _cached_main(model_name: str, thinking: str) -> Any:
@@ -167,21 +171,9 @@ def get_model(model_name: str | None = None, thinking: str | None = None) -> Any
     return _cached_main(name, level)
 
 
-@functools.lru_cache(maxsize=4)
-def _cached_summary(model_name: str, thinking: str) -> Any:
-    # 摘要不需要思考链:开启思考只会让压缩变慢变贵,且摘要本身是「提取」而非「推理」
-    return build_model(model_name, thinking)
-
-
-def get_summary_model() -> Any:
-    """取摘要模型实例(自动压缩用)。"""
-    return _cached_summary(config.SUMMARY_MODEL, "off")
-
-
 def clear_cache() -> None:
     """丢弃模型实例缓存(思考级别切换后调用)。"""
     _cached_main.cache_clear()
-    _cached_summary.cache_clear()
 
 
 def describe() -> dict[str, Any]:
@@ -189,7 +181,6 @@ def describe() -> dict[str, Any]:
     name = config.MODEL
     return {
         "model": name,
-        "summary_model": config.SUMMARY_MODEL,
         "thinking": normalize_thinking(None),
         "thinking_levels": list(VALID_THINKING_LEVELS),
         "context_window": context_window(name),

+ 1 - 1
api/usage_routes.py

@@ -61,7 +61,7 @@ async def billing_health():
     """计费子系统自检:单价表是否覆盖当前配置的模型。"""
     import config
 
-    models = {config.MODEL, config.SUMMARY_MODEL}
+    models = {config.MODEL}
     table = await asyncio.to_thread(pricing.pricing_table)
     priced = {row["model"] for row in table}
     missing = sorted(m for m in models if m and m not in priced)

+ 2 - 2
billing/pricing.py

@@ -36,8 +36,8 @@ def seed_default_pricing() -> int:
         if billing_store.get_pricing(model) is None:
             billing_store.set_pricing(model, input_price, output_price)
             created += 1
-    # 当前配置的主模型与摘要模型必须在表内,否则首轮就会 fail-closed
-    for model in {config.MODEL, config.SUMMARY_MODEL}:
+    # 当前配置的主模型必须在表内,否则首轮就会 fail-closed
+    for model in {config.MODEL}:
         if model and billing_store.get_pricing(model) is None:
             billing_store.set_pricing(model, 0.0, 0.0)
             created += 1

+ 0 - 1
config.py

@@ -156,7 +156,6 @@ LOG_FORMAT: str = get_str("LOG_FORMAT", "text")
 # 模型
 # ============================================================
 MODEL: str = get_str("DEEPAGENT_MODEL", "deepseek-flash")
-SUMMARY_MODEL: str = get_str("SUMMARY_MODEL", "") or MODEL
 OPENAI_BASE_URL: str = get_str("OPENAI_BASE_URL", "")
 OPENAI_API_KEY: str = get_str("OPENAI_API_KEY", "")
 OPENAI_TIMEOUT: int = get_int("OPENAI_TIMEOUT", 180)

+ 1 - 1
scripts/selfcheck.py

@@ -94,7 +94,7 @@ def check_pricing() -> str:
     created = pricing.seed_default_pricing()
     from db import billing_store
 
-    missing = [m for m in {pricing.config.MODEL, pricing.config.SUMMARY_MODEL}
+    missing = [m for m in {pricing.config.MODEL}
                if m and billing_store.get_pricing(m) is None]
     if missing:
         raise RuntimeError(f"模型未定价(会在请求开始时 fail-closed):{missing}")