fix(flows): 步数预算与图硬上限分离,预算耗尽时优雅收尾
max_steps 以前同时充当软预算和 recursion_limit,于是预算耗尽的那一刻 必然触发 GraphRecursionError:模型连一句收尾都来不及说,用户只收到 「处理消息时出错,请稍后再试」,已产出的内容也不会落库。 - 新增 StepBudgetMiddleware:按模型调用轮数计账(agent_rounds = max_steps // 2),剩余 <=4 轮时注入一次「立刻停止调用工具、给出结论」 的收尾提示,只提醒一次 - 新增 STEP_GRACE(20),recursion_limit = max_steps + STEP_GRACE,把余量 留给收尾动作 - GraphRecursionError 统一转成 StepBudgetExceeded,ainvoke 与流式两条 路径都覆盖 - AgentReply 把「步数用尽」渲染成可操作说明,接在已产出内容之后一并 下发并落库;用 _reported 标记让 on_error 不再补发通用错误文案,任务 状态仍如实记 failed - 同步 README / docs/architecture.md / db/schema.py 中 max_steps 的语义 测试:新增 tests/test_budget.py(7 个用例),全量 241 passed。
This commit is contained in:
1 parent
fbb01c4c83
commit
5da55f8d17
12 files changed
+531
-40
No files matched your search
@@ -8,7 +8,7 @@ from typing import Any
|
||||
|
||||
from bot042.channels.base import BaseChannel
|
||||
from bot042.channels.models import ChannelSubject, InboundMessage, TextContent
|
||||
from bot042.config import Settings
|
||||
from bot042.config import STEP_GRACE, Settings
|
||||
from bot042.flows.agent_task import last_message_text, run_task
|
||||
from bot042.flows.session import run_session
|
||||
|
||||
@@ -86,7 +86,8 @@ def test_run_task_uses_async_ainvoke(monkeypatch) -> None:
|
||||
assert last_message_text(result) == "done"
|
||||
state, config = fake.calls[0]
|
||||
assert state["messages"][-1] == {"role": "user", "content": "hi"}
|
||||
assert config == {"recursion_limit": 7}
|
||||
# 硬步数上限 = 软预算 + 收尾余量(见 Settings.recursion_limit)
|
||||
assert config == {"recursion_limit": 7 + STEP_GRACE}
|
||||
|
||||
|
||||
def test_last_message_text_multimodal_content() -> None:
|
||||
|
||||
Reference in new issue
Block a user